mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-14 15:31:31 +00:00
Implement Array.isArray and Array#copyWithin (#331)
This commit is contained in:
@ -471,7 +471,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 136
|
||||
i32.const 37
|
||||
i32.const 45
|
||||
i32.const 39
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
@ -545,7 +545,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 136
|
||||
i32.const 37
|
||||
i32.const 45
|
||||
i32.const 39
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
@ -619,7 +619,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 136
|
||||
i32.const 37
|
||||
i32.const 45
|
||||
i32.const 39
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
@ -709,7 +709,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 136
|
||||
i32.const 37
|
||||
i32.const 45
|
||||
i32.const 39
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -28,6 +28,17 @@ function isArraysEqual<T>(a: Array<T>, b: Array<T>, len: i32 = 0): bool {
|
||||
|
||||
var arr = new Array<i32>();
|
||||
|
||||
// Array.isArray ///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class P {}
|
||||
var num = 1;
|
||||
var Null: i32[] | null = null;
|
||||
assert(Array.isArray(Null) == false);
|
||||
assert(Array.isArray(arr) == true);
|
||||
assert(Array.isArray(new P()) == false);
|
||||
// assert(Array.isArray(new Uint8Array(1)) == false); fail
|
||||
assert(Array.isArray(num) == false);
|
||||
|
||||
// Array#fill //////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var arr8: u8[] = [1, 2, 3, 4, 5];
|
||||
@ -145,6 +156,34 @@ out = source.concat(arr);
|
||||
assert(out.length == 3);
|
||||
assert(source.length == 0);
|
||||
|
||||
// Array#copyWithin ////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var cwArr: i32[];
|
||||
cwArr = [1, 2, 3, 4, 5];
|
||||
assert(isArraysEqual<i32>(cwArr.copyWithin(0, 3), <i32[]>[4, 5, 3, 4, 5]));
|
||||
cwArr = [1, 2, 3, 4, 5];
|
||||
assert(isArraysEqual<i32>(cwArr.copyWithin(1, 3), <i32[]>[1, 4, 5, 4, 5]));
|
||||
cwArr = [1, 2, 3, 4, 5];
|
||||
assert(isArraysEqual<i32>(cwArr.copyWithin(1, 2), <i32[]>[1, 3, 4, 5, 5]));
|
||||
cwArr = [1, 2, 3, 4, 5];
|
||||
assert(isArraysEqual<i32>(cwArr.copyWithin(2, 2), <i32[]>[1, 2, 3, 4, 5]));
|
||||
cwArr = [1, 2, 3, 4, 5];
|
||||
assert(isArraysEqual<i32>(cwArr.copyWithin(0, 3, 4), <i32[]>[4, 2, 3, 4, 5]));
|
||||
cwArr = [1, 2, 3, 4, 5];
|
||||
assert(isArraysEqual<i32>(cwArr.copyWithin(1, 3, 4), <i32[]>[1, 4, 3, 4, 5]));
|
||||
cwArr = [1, 2, 3, 4, 5];
|
||||
assert(isArraysEqual<i32>(cwArr.copyWithin(1, 2, 4), <i32[]>[1, 3, 4, 4, 5]));
|
||||
cwArr = [1, 2, 3, 4, 5];
|
||||
assert(isArraysEqual<i32>(cwArr.copyWithin(0, -2), <i32[]>[4, 5, 3, 4, 5]));
|
||||
cwArr = [1, 2, 3, 4, 5];
|
||||
assert(isArraysEqual<i32>(cwArr.copyWithin(0, -2, -1), <i32[]>[4, 2, 3, 4, 5]));
|
||||
cwArr = [1, 2, 3, 4, 5];
|
||||
assert(isArraysEqual<i32>(cwArr.copyWithin(-4, -3, -2), <i32[]>[1, 3, 3, 4, 5]));
|
||||
cwArr = [1, 2, 3, 4, 5];
|
||||
assert(isArraysEqual<i32>(cwArr.copyWithin(-4, -3, -1), <i32[]>[1, 3, 4, 4, 5]));
|
||||
cwArr = [1, 2, 3, 4, 5];
|
||||
assert(isArraysEqual<i32>(cwArr.copyWithin(-4, -3), <i32[]>[1, 3, 4, 5, 5]));
|
||||
|
||||
// Array#unshift ///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
arr.unshift(42);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1903,7 +1903,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 72
|
||||
i32.const 101
|
||||
i32.const 109
|
||||
i32.const 41
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
|
@ -2436,7 +2436,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 72
|
||||
i32.const 101
|
||||
i32.const 109
|
||||
i32.const 41
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
|
@ -2002,7 +2002,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 184
|
||||
i32.const 101
|
||||
i32.const 109
|
||||
i32.const 41
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
@ -2077,7 +2077,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 184
|
||||
i32.const 101
|
||||
i32.const 109
|
||||
i32.const 41
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
@ -2152,7 +2152,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 184
|
||||
i32.const 101
|
||||
i32.const 109
|
||||
i32.const 41
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
@ -2227,7 +2227,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 184
|
||||
i32.const 101
|
||||
i32.const 109
|
||||
i32.const 41
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
|
@ -3319,7 +3319,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 776
|
||||
i32.const 37
|
||||
i32.const 45
|
||||
i32.const 39
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
@ -3467,7 +3467,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 776
|
||||
i32.const 174
|
||||
i32.const 184
|
||||
i32.const 42
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
|
@ -4101,7 +4101,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 776
|
||||
i32.const 37
|
||||
i32.const 45
|
||||
i32.const 39
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
@ -4310,7 +4310,7 @@
|
||||
if
|
||||
i32.const 0
|
||||
i32.const 776
|
||||
i32.const 174
|
||||
i32.const 184
|
||||
i32.const 42
|
||||
call $~lib/env/abort
|
||||
unreachable
|
||||
|
Reference in New Issue
Block a user