mirror of https://github.com/tc39/test262.git
Merge pull request #390 from bocoup/Array.prototype.copyWithin
Add tests for Array.prototype.copyWithin
This commit is contained in:
commit
574c87b167
|
@ -0,0 +1,63 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
end argument is coerced to an integer values.
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
11. If end is undefined, let relativeEnd be len; else let relativeEnd be
|
||||
ToInteger(end).
|
||||
...
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(1, 0, null),
|
||||
[0, 1, 2, 3]
|
||||
),
|
||||
'null value coerced to 0'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(1, 0, NaN),
|
||||
[0, 1, 2, 3]
|
||||
),
|
||||
'NaN value coerced to 0'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(1, 0, false),
|
||||
[0, 1, 2, 3]
|
||||
),
|
||||
'false value coerced to 0'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(1, 0, true),
|
||||
[0, 0, 2, 3]
|
||||
),
|
||||
'true value coerced to 1'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(1, 0, '-2'),
|
||||
[0, 0, 1, 3]
|
||||
),
|
||||
'string "-2" value coerced to integer -2'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(1, 0, -2.5),
|
||||
[0, 0, 1, 3]
|
||||
),
|
||||
'float -2.5 value coerced to integer -2'
|
||||
);
|
|
@ -0,0 +1,80 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
start argument is coerced to an integer value.
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
8. Let relativeStart be ToInteger(start).
|
||||
...
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(1, undefined),
|
||||
[0, 0, 1, 2]
|
||||
),
|
||||
'undefined value coerced to 0'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(1, false),
|
||||
[0, 0, 1, 2]
|
||||
),
|
||||
'false value coerced to 0'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(1, NaN),
|
||||
[0, 0, 1, 2]
|
||||
),
|
||||
'NaN value coerced to 0'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(1, null),
|
||||
[0, 0, 1, 2]
|
||||
),
|
||||
'null value coerced to 0'
|
||||
);
|
||||
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(0, true),
|
||||
[1, 2, 3, 3]
|
||||
),
|
||||
'true value coerced to 1'
|
||||
);
|
||||
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(0, '1'),
|
||||
[1, 2, 3, 3]
|
||||
),
|
||||
'string "1" value coerced to 1'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(1, 0.5),
|
||||
[0, 0, 1, 2]
|
||||
),
|
||||
'0.5 float value coerced to integer 0'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(0, 1.5),
|
||||
[1, 2, 3, 3]
|
||||
),
|
||||
'1.5 float value coerced to integer 1'
|
||||
);
|
|
@ -0,0 +1,80 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
target argument is coerced to an integer value.
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
5. Let relativeTarget be ToInteger(target).
|
||||
...
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(undefined, 1),
|
||||
[1, 2, 3, 3]
|
||||
),
|
||||
'undefined value coerced to 0'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(false, 1),
|
||||
[1, 2, 3, 3]
|
||||
),
|
||||
'false value coerced to 0'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(NaN, 1),
|
||||
[1, 2, 3, 3]
|
||||
),
|
||||
'NaN value coerced to 0'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(null, 1),
|
||||
[1, 2, 3, 3]
|
||||
),
|
||||
'null value coerced to 0'
|
||||
);
|
||||
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(true, 0),
|
||||
[0, 0, 1, 2]
|
||||
),
|
||||
'true value coerced to 1'
|
||||
);
|
||||
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin('1', 0),
|
||||
[0, 0, 1, 2]
|
||||
),
|
||||
'string "1" value coerced to 1'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(0.5, 1),
|
||||
[1, 2, 3, 3]
|
||||
),
|
||||
'0.5 float value coerced to integer 0'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(1.5, 0),
|
||||
[0, 0, 1, 2]
|
||||
),
|
||||
'1.5 float value coerced to integer 1'
|
||||
);
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: Property type and descriptor.
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
typeof Array.prototype.copyWithin,
|
||||
'function',
|
||||
'`typeof Array.prototype.copyWithin` is `function`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(Array.prototype, 'copyWithin');
|
||||
verifyWritable(Array.prototype, 'copyWithin');
|
||||
verifyConfigurable(Array.prototype, 'copyWithin');
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Loop from each property, even empty holes.
|
||||
---*/
|
||||
|
||||
var arr = [0, 1, , , 1];
|
||||
|
||||
arr.copyWithin(0, 1, 4);
|
||||
|
||||
assert.sameValue(arr.length, 5);
|
||||
assert.sameValue(arr[0], 1);
|
||||
assert.sameValue(arr[4], 1);
|
||||
assert.sameValue(arr.hasOwnProperty(1), false);
|
||||
assert.sameValue(arr.hasOwnProperty(2), false);
|
||||
assert.sameValue(arr.hasOwnProperty(3), false);
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: Array.prototype.copyWithin.length value and descriptor.
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
The length property of the copyWithin method is 2.
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
Array.prototype.copyWithin.length, 2,
|
||||
'The value of `Array.prototype.copyWithin.length` is `2`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(Array.prototype.copyWithin, 'length');
|
||||
verifyNotWritable(Array.prototype.copyWithin, 'length');
|
||||
verifyConfigurable(Array.prototype.copyWithin, 'length');
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Array.prototype.copyWithin.name value and descriptor.
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
17 ECMAScript Standard Built-in Objects
|
||||
|
||||
includes: [propertyHelper.js]
|
||||
---*/
|
||||
|
||||
assert.sameValue(
|
||||
Array.prototype.copyWithin.name, 'copyWithin',
|
||||
'The value of `Array.prototype.copyWithin.name` is `"copyWithin"`'
|
||||
);
|
||||
|
||||
verifyNotEnumerable(Array.prototype.copyWithin, 'name');
|
||||
verifyNotWritable(Array.prototype.copyWithin, 'name');
|
||||
verifyConfigurable(Array.prototype.copyWithin, 'name');
|
|
@ -0,0 +1,82 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Set values with negative end argument.
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
11. If end is undefined, let relativeEnd be len; else let relativeEnd be
|
||||
ToInteger(end).
|
||||
12. ReturnIfAbrupt(relativeEnd).
|
||||
13. If relativeEnd < 0, let final be max((len + relativeEnd),0); else let
|
||||
final be min(relativeEnd, len).
|
||||
...
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(0, 1, -1),
|
||||
[1, 2, 2, 3]
|
||||
),
|
||||
'[0, 1, 2, 3].copyWithin(0, 1, -1) -> [1, 2, 2, 3]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3, 4].copyWithin(2, 0, -1),
|
||||
[0, 1, 0, 1, 2]
|
||||
),
|
||||
'[0, 1, 2, 3, 4].copyWithin(2, 0, -1) -> [0, 1, 0, 1, 2]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3, 4].copyWithin(1, 2, -2),
|
||||
[0, 2, 2, 3, 4]
|
||||
),
|
||||
'[0, 1, 2, 3, 4].copyWithin(1, 2, -2) -> [0, 2, 2, 3, 4]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(0, -2, -1),
|
||||
[2, 1, 2, 3]
|
||||
),
|
||||
'[0, 1, 2, 3].copyWithin(0, -2, -1) -> [2, 1, 2, 3]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3, 4].copyWithin(2, -2, -1),
|
||||
[0, 1, 3, 3, 4]
|
||||
),
|
||||
'[0, 1, 2, 3, 4].copyWithin(2, -2, 1) -> [0, 1, 3, 3, 4]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(-3, -2, -1),
|
||||
[0, 2, 2, 3]
|
||||
),
|
||||
'[0, 1, 2, 3].copyWithin(-3, -2, -1) -> [0, 2, 2, 3]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3, 4].copyWithin(-2, -3, -1),
|
||||
[0, 1, 2, 2, 3]
|
||||
),
|
||||
'[0, 1, 2, 3, 4].copyWithin(-2, -3, -1) -> [0, 1, 2, 2, 3]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3, 4].copyWithin(-5, -2, -1),
|
||||
[3, 1, 2, 3, 4]
|
||||
),
|
||||
'[0, 1, 2, 3, 4].copyWithin(-5, -2, -1) -> [3, 1, 2, 3, 4]'
|
||||
);
|
|
@ -0,0 +1,58 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Set values with negative out of bounds end argument.
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
11. If end is undefined, let relativeEnd be len; else let relativeEnd be
|
||||
ToInteger(end).
|
||||
12. ReturnIfAbrupt(relativeEnd).
|
||||
13. If relativeEnd < 0, let final be max((len + relativeEnd),0); else let
|
||||
final be min(relativeEnd, len).
|
||||
...
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(0, 1, -10),
|
||||
[0, 1, 2, 3]
|
||||
),
|
||||
'[0, 1, 2, 3].copyWithin(0, 1, -10) -> [0, 1, 2, 3]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(0, -2, -10),
|
||||
[0, 1, 2, 3]
|
||||
),
|
||||
'[0, 1, 2, 3].copyWithin(0, -2, -10) -> [0, 1, 2, 3]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(0, -9, -10),
|
||||
[0, 1, 2, 3]
|
||||
),
|
||||
'[0, 1, 2, 3].copyWithin(0, -9, -10) -> [0, 1, 2, 3]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(-3, -2, -10),
|
||||
[0, 1, 2, 3]
|
||||
),
|
||||
'[0, 1, 2, 3].copyWithin(-3, -2, -10) -> [0, 1, 2, 3]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(-7, -8, -9),
|
||||
[0, 1, 2, 3]
|
||||
),
|
||||
'[0, 1, 2, 3].copyWithin(-7, -8, -9) -> [0, 1, 2, 3]'
|
||||
);
|
|
@ -0,0 +1,47 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Set values with out of bounds negative start argument.
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
10. If relativeStart < 0, let from be max((len + relativeStart),0); else let
|
||||
from be min(relativeStart, len).
|
||||
...
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(0, -10),
|
||||
[0, 1, 2, 3]
|
||||
),
|
||||
'[0, 1, 2, 3].copyWithin(0, -10) -> [0, 1, 2, 3]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3, 4].copyWithin(2, -10),
|
||||
[0, 1, 0, 1, 2]
|
||||
),
|
||||
'[0, 1, 2, 3, 4].copyWithin(2, -2) -> [0, 1, 0, 1, 2]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3, 4].copyWithin(10, -10),
|
||||
[0, 1, 2, 3, 4]
|
||||
),
|
||||
'[0, 1, 2, 3, 4].copyWithin(10, -10) -> [0, 1, 2, 3, 4]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(-9, -10),
|
||||
[0, 1, 2, 3]
|
||||
),
|
||||
'[0, 1, 2, 3].copyWithin(-9, -10) -> [0, 1, 2, 3]'
|
||||
);
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Set values with out of bounds negative target argument.
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
7. If relativeTarget < 0, let to be max((len + relativeTarget),0); else let to
|
||||
be min(relativeTarget, len).
|
||||
...
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(-10, 0),
|
||||
[0, 1, 2, 3]
|
||||
),
|
||||
'[0, 1, 2, 3].copyWithin(-10, 0) -> [0, 1, 2, 3]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3, 4].copyWithin(-10, 2),
|
||||
[2, 3, 4, 3, 4]
|
||||
),
|
||||
'[0, 1, 2, 3, 4].copyWithin(-10, 2) -> [2, 3, 4, 3, 4]'
|
||||
);
|
|
@ -0,0 +1,63 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Set values with negative start argument.
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
10. If relativeStart < 0, let from be max((len + relativeStart),0); else let
|
||||
from be min(relativeStart, len).
|
||||
...
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(0, -1),
|
||||
[3, 1, 2, 3]
|
||||
),
|
||||
'[0, 1, 2, 3].copyWithin(0, -1) -> [3, 1, 2, 3]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3, 4].copyWithin(2, -2),
|
||||
[0, 1, 3, 4, 4]
|
||||
),
|
||||
'[0, 1, 2, 3, 4].copyWithin(2, -2) -> [0, 1, 3, 4, 4]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3, 4].copyWithin(1, -2),
|
||||
[0, 3, 4, 3, 4]
|
||||
),
|
||||
'[0, 1, 2, 3, 4].copyWithin(1, -2) -> [0, 3, 4, 3, 4]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(-1, -2),
|
||||
[0, 1, 2, 2]
|
||||
),
|
||||
'[0, 1, 2, 3].copyWithin(-1, -2) -> [ 0, 1, 2, 2 ]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3, 4].copyWithin(-2, -3),
|
||||
[0, 1, 2, 2, 3]
|
||||
),
|
||||
'[0, 1, 2, 3, 4].copyWithin(-2, -3) -> [0, 1, 2, 2, 3]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3, 4].copyWithin(-5, -2),
|
||||
[3, 4, 2, 3, 4]
|
||||
),
|
||||
'[0, 1, 2, 3, 4].copyWithin(-5, -2) -> [3, 4, 2, 3, 4]'
|
||||
);
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Set values with negative target argument.
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
7. If relativeTarget < 0, let to be max((len + relativeTarget),0); else let to
|
||||
be min(relativeTarget, len).
|
||||
...
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(-1, 0),
|
||||
[0, 1, 2, 0]
|
||||
),
|
||||
'[0, 1, 2, 3].copyWithin(-1, 0) -> [0, 1, 2, 0]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3, 4].copyWithin(-2, 2),
|
||||
[0, 1, 2, 2, 3]
|
||||
),
|
||||
'[0, 1, 2, 3, 4].copyWithin(-2, 2) -> [0, 1, 2, 2, 3]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(-1, 2),
|
||||
[0, 1, 2, 2]
|
||||
),
|
||||
'[0, 1, 2, 3].copyWithin(-1, 2) -> [0, 1, 2, 2]'
|
||||
);
|
|
@ -0,0 +1,50 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Max value of end position is the this.length.
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
7. If relativeTarget < 0, let to be max((len + relativeTarget),0); else let to
|
||||
be min(relativeTarget, len).
|
||||
...
|
||||
10. If relativeStart < 0, let from be max((len + relativeStart),0); else let
|
||||
from be min(relativeStart, len).
|
||||
11. If end is undefined, let relativeEnd be len; else let relativeEnd be
|
||||
ToInteger(end).
|
||||
...
|
||||
14. Let count be min(final-from, len-to).
|
||||
15. If from<to and to<from+count
|
||||
a. Let direction be -1.
|
||||
b. Let from be from + count -1.
|
||||
c. Let to be to + count -1.
|
||||
16. Else,
|
||||
a. Let direction = 1.
|
||||
17. Repeat, while count > 0
|
||||
...
|
||||
a. If fromPresent is true, then
|
||||
i. Let fromVal be Get(O, fromKey).
|
||||
...
|
||||
iii. Let setStatus be Set(O, toKey, fromVal, true).
|
||||
...
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(0, 1, 6),
|
||||
[1, 2, 3, 3]
|
||||
),
|
||||
'[0, 1, 2, 3].copyWithin(0, 1, 6) -> [1, 2, 3, 3]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3, 4, 5].copyWithin(1, 3, 6),
|
||||
[0, 3, 4, 5, 4, 5]
|
||||
),
|
||||
'[0, 1, 2, 3, 4, 5].copyWithin(1, 3, 6) -> [0, 3, 4, 5, 4, 5]'
|
||||
);
|
56
test/built-ins/Array/prototype/copyWithin/non-negative-out-of-bounds-target-and-start.js
vendored
Normal file
56
test/built-ins/Array/prototype/copyWithin/non-negative-out-of-bounds-target-and-start.js
vendored
Normal file
|
@ -0,0 +1,56 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Max values of target and start positions are this.length.
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
7. If relativeTarget < 0, let to be max((len + relativeTarget),0); else let to
|
||||
be min(relativeTarget, len).
|
||||
...
|
||||
10. If relativeStart < 0, let from be max((len + relativeStart),0); else let
|
||||
from be min(relativeStart, len).
|
||||
11. If end is undefined, let relativeEnd be len; else let relativeEnd be
|
||||
ToInteger(end).
|
||||
...
|
||||
14. Let count be min(final-from, len-to).
|
||||
15. If from<to and to<from+count
|
||||
...
|
||||
16. Else,
|
||||
a. Let direction = 1.
|
||||
17. Repeat, while count > 0
|
||||
...
|
||||
...
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3, 4, 5].copyWithin(6, 0),
|
||||
[0, 1, 2, 3, 4, 5]
|
||||
)
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3, 4, 5].copyWithin(0, 6),
|
||||
[0, 1, 2, 3, 4, 5]
|
||||
)
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3, 4, 5].copyWithin(6, 6),
|
||||
[0, 1, 2, 3, 4, 5]
|
||||
)
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3, 4, 5].copyWithin(10, 10),
|
||||
[0, 1, 2, 3, 4, 5]
|
||||
)
|
||||
);
|
|
@ -0,0 +1,60 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Copy values with non-negative target and start positions.
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
7. If relativeTarget < 0, let to be max((len + relativeTarget),0); else let to
|
||||
be min(relativeTarget, len).
|
||||
...
|
||||
10. If relativeStart < 0, let from be max((len + relativeStart),0); else let
|
||||
from be min(relativeStart, len).
|
||||
11. If end is undefined, let relativeEnd be len; else let relativeEnd be
|
||||
ToInteger(end).
|
||||
...
|
||||
14. Let count be min(final-from, len-to).
|
||||
15. If from<to and to<from+count
|
||||
...
|
||||
16. Else,
|
||||
a. Let direction = 1.
|
||||
17. Repeat, while count > 0
|
||||
...
|
||||
a. If fromPresent is true, then
|
||||
i. Let fromVal be Get(O, fromKey).
|
||||
...
|
||||
iii. Let setStatus be Set(O, toKey, fromVal, true).
|
||||
...
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
['a', 'b', 'c', 'd', 'e', 'f'].copyWithin(0, 0),
|
||||
['a', 'b', 'c', 'd', 'e', 'f']
|
||||
)
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
['a', 'b', 'c', 'd', 'e', 'f'].copyWithin(0, 2),
|
||||
['c', 'd', 'e', 'f', 'e', 'f']
|
||||
)
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
['a', 'b', 'c', 'd', 'e', 'f'].copyWithin(3, 0),
|
||||
['a', 'b', 'c', 'a', 'b', 'c']
|
||||
)
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3, 4, 5].copyWithin(1, 4),
|
||||
[0, 4, 5, 3, 4, 5]
|
||||
)
|
||||
);
|
85
test/built-ins/Array/prototype/copyWithin/non-negative-target-start-and-end.js
vendored
Normal file
85
test/built-ins/Array/prototype/copyWithin/non-negative-target-start-and-end.js
vendored
Normal file
|
@ -0,0 +1,85 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Copy values with non-negative target, start and end positions.
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
7. If relativeTarget < 0, let to be max((len + relativeTarget),0); else let to
|
||||
be min(relativeTarget, len).
|
||||
...
|
||||
10. If relativeStart < 0, let from be max((len + relativeStart),0); else let
|
||||
from be min(relativeStart, len).
|
||||
11. If end is undefined, let relativeEnd be len; else let relativeEnd be
|
||||
ToInteger(end).
|
||||
...
|
||||
14. Let count be min(final-from, len-to).
|
||||
15. If from<to and to<from+count
|
||||
a. Let direction be -1.
|
||||
b. Let from be from + count -1.
|
||||
c. Let to be to + count -1.
|
||||
16. Else,
|
||||
a. Let direction = 1.
|
||||
17. Repeat, while count > 0
|
||||
...
|
||||
a. If fromPresent is true, then
|
||||
i. Let fromVal be Get(O, fromKey).
|
||||
...
|
||||
iii. Let setStatus be Set(O, toKey, fromVal, true).
|
||||
...
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(0, 0, 0),
|
||||
[0, 1, 2, 3]
|
||||
),
|
||||
'[0, 1, 2, 3].copyWithin(0, 0, 0) -> [0, 1, 2, 3]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(0, 0, 2),
|
||||
[0, 1, 2, 3]
|
||||
),
|
||||
'[0, 1, 2, 3].copyWithin(0, 0, 2) -> [0, 1, 2, 3]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(0, 1, 2),
|
||||
[1, 1, 2, 3]
|
||||
),
|
||||
'[0, 1, 2, 3].copyWithin(0, 1, 2) -> [1, 1, 2, 3]'
|
||||
);
|
||||
|
||||
/*
|
||||
* 15. If from<to and to<from+count
|
||||
* a. Let direction be -1.
|
||||
* b. Let from be from + count -1.
|
||||
* c. Let to be to + count -1.
|
||||
*
|
||||
* 0 < 1, 1 < 0 + 2
|
||||
* direction = -1
|
||||
* from = 0 + 2 - 1
|
||||
* to = 1 + 2 - 1
|
||||
*/
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(1, 0, 2),
|
||||
[0, 0, 1, 3]
|
||||
),
|
||||
'[0, 1, 2, 3].copyWithin(1, 0, 2) -> [0, 0, 1, 3]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3, 4, 5].copyWithin(1, 3, 5),
|
||||
[0, 3, 4, 3, 4, 5]
|
||||
),
|
||||
'[0, 1, 2, 3, 4, 5].copyWithin(1, 3, 5) -> [0, 3, 4, 3, 4, 5]'
|
||||
);
|
38
test/built-ins/Array/prototype/copyWithin/return-abrupt-from-delete-proxy-target.js
vendored
Normal file
38
test/built-ins/Array/prototype/copyWithin/return-abrupt-from-delete-proxy-target.js
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Return abrupt from deleting property value - using Proxy
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
17. Repeat, while count > 0
|
||||
a. Let fromKey be ToString(from).
|
||||
b. Let toKey be ToString(to).
|
||||
c. Let fromPresent be HasProperty(O, fromKey).
|
||||
...
|
||||
f. Else fromPresent is false,
|
||||
i. Let deleteStatus be DeletePropertyOrThrow(O, toKey).
|
||||
ii. ReturnIfAbrupt(deleteStatus).
|
||||
...
|
||||
features: [Proxy]
|
||||
---*/
|
||||
|
||||
var o = {
|
||||
'42': true,
|
||||
length: 43
|
||||
};
|
||||
|
||||
var p = new Proxy(o, {
|
||||
deleteProperty: function(t, prop) {
|
||||
if (prop === '42') {
|
||||
throw new Test262Error();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
Array.prototype.copyWithin.call(p, 42, 0);
|
||||
});
|
33
test/built-ins/Array/prototype/copyWithin/return-abrupt-from-delete-target.js
vendored
Normal file
33
test/built-ins/Array/prototype/copyWithin/return-abrupt-from-delete-target.js
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Return abrupt from deleting property value on DeletePropertyOrThrow(O, toKey).
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
17. Repeat, while count > 0
|
||||
a. Let fromKey be ToString(from).
|
||||
b. Let toKey be ToString(to).
|
||||
c. Let fromPresent be HasProperty(O, fromKey).
|
||||
...
|
||||
f. Else fromPresent is false,
|
||||
i. Let deleteStatus be DeletePropertyOrThrow(O, toKey).
|
||||
ii. ReturnIfAbrupt(deleteStatus).
|
||||
...
|
||||
---*/
|
||||
|
||||
var o = {
|
||||
length: 43
|
||||
};
|
||||
|
||||
Object.defineProperty(o, '42', {
|
||||
configurable: false,
|
||||
writable: true
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Array.prototype.copyWithin.call(o, 42, 0);
|
||||
});
|
21
test/built-ins/Array/prototype/copyWithin/return-abrupt-from-end-as-symbol.js
vendored
Normal file
21
test/built-ins/Array/prototype/copyWithin/return-abrupt-from-end-as-symbol.js
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Return abrupt from end as a Symbol.
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
11. If end is undefined, let relativeEnd be len; else let relativeEnd be
|
||||
ToInteger(end).
|
||||
12. ReturnIfAbrupt(relativeEnd).
|
||||
...
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var s = Symbol(1);
|
||||
assert.throws(TypeError, function() {
|
||||
[].copyWithin(0, 0, s);
|
||||
});
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Return abrupt from ToInteger(end).
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
11. If end is undefined, let relativeEnd be len; else let relativeEnd be
|
||||
ToInteger(end).
|
||||
12. ReturnIfAbrupt(relativeEnd).
|
||||
...
|
||||
---*/
|
||||
|
||||
var o1 = {
|
||||
valueOf: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
assert.throws(Test262Error, function() {
|
||||
[].copyWithin(0, 0, o1);
|
||||
});
|
||||
|
39
test/built-ins/Array/prototype/copyWithin/return-abrupt-from-get-start-value.js
vendored
Normal file
39
test/built-ins/Array/prototype/copyWithin/return-abrupt-from-get-start-value.js
vendored
Normal file
|
@ -0,0 +1,39 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Return abrupt from getting property value - Get(O, fromKey).
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
8. Let relativeStart be ToInteger(start).
|
||||
9. ReturnIfAbrupt(relativeStart).
|
||||
10. If relativeStart < 0, let from be max((len + relativeStart),0); else let
|
||||
from be min(relativeStart, len).
|
||||
...
|
||||
17. Repeat, while count > 0
|
||||
a. Let fromKey be ToString(from).
|
||||
b. Let toKey be ToString(to).
|
||||
c. Let fromPresent be HasProperty(O, fromKey).
|
||||
d. ReturnIfAbrupt(fromPresent).
|
||||
e. If fromPresent is true, then
|
||||
i. Let fromVal be Get(O, fromKey).
|
||||
ii. ReturnIfAbrupt(fromVal).
|
||||
...
|
||||
---*/
|
||||
|
||||
var o = {
|
||||
length: 1
|
||||
};
|
||||
|
||||
Object.defineProperty(o, '0', {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
Array.prototype.copyWithin.call(o, 0, 0);
|
||||
});
|
|
@ -0,0 +1,38 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Return abrupt from HasProperty(O, fromKey).
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
8. Let relativeStart be ToInteger(start).
|
||||
9. ReturnIfAbrupt(relativeStart).
|
||||
10. If relativeStart < 0, let from be max((len + relativeStart),0); else let
|
||||
from be min(relativeStart, len).
|
||||
...
|
||||
17. Repeat, while count > 0
|
||||
a. Let fromKey be ToString(from).
|
||||
b. Let toKey be ToString(to).
|
||||
c. Let fromPresent be HasProperty(O, fromKey).
|
||||
d. ReturnIfAbrupt(fromPresent).
|
||||
...
|
||||
features: [Proxy]
|
||||
---*/
|
||||
|
||||
var o = {
|
||||
'0': 42,
|
||||
length: 1
|
||||
};
|
||||
|
||||
var p = new Proxy(o, {
|
||||
has: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
Array.prototype.copyWithin.call(p, 0, 0);
|
||||
});
|
40
test/built-ins/Array/prototype/copyWithin/return-abrupt-from-set-target-value.js
vendored
Normal file
40
test/built-ins/Array/prototype/copyWithin/return-abrupt-from-set-target-value.js
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Return abrupt from setting property value - Set(O, toKey, fromVal, true).
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
5. Let relativeTarget be ToInteger(target).
|
||||
6. ReturnIfAbrupt(relativeTarget).
|
||||
7. If relativeTarget < 0, let to be max((len + relativeTarget),0); else let to
|
||||
be min(relativeTarget, len).
|
||||
...
|
||||
17. Repeat, while count > 0
|
||||
a. Let fromKey be ToString(from).
|
||||
b. Let toKey be ToString(to).
|
||||
...
|
||||
e. If fromPresent is true, then
|
||||
...
|
||||
iii. Let setStatus be Set(O, toKey, fromVal, true).
|
||||
iv. ReturnIfAbrupt(setStatus).
|
||||
...
|
||||
---*/
|
||||
|
||||
var o = {
|
||||
'0': true,
|
||||
length: 43
|
||||
};
|
||||
|
||||
Object.defineProperty(o, '42', {
|
||||
set: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
|
||||
assert.throws(Test262Error, function() {
|
||||
Array.prototype.copyWithin.call(o, 42, 0);
|
||||
});
|
20
test/built-ins/Array/prototype/copyWithin/return-abrupt-from-start-as-symbol.js
vendored
Normal file
20
test/built-ins/Array/prototype/copyWithin/return-abrupt-from-start-as-symbol.js
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Return abrupt from start as a Symbol.
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
8. Let relativeStart be ToInteger(start).
|
||||
9. ReturnIfAbrupt(relativeStart).
|
||||
...
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var s = Symbol(1);
|
||||
assert.throws(TypeError, function() {
|
||||
[].copyWithin(0, s);
|
||||
});
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Return abrupt from ToInteger(start).
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
8. Let relativeStart be ToInteger(start).
|
||||
9. ReturnIfAbrupt(relativeStart).
|
||||
...
|
||||
---*/
|
||||
|
||||
var o1 = {
|
||||
valueOf: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
assert.throws(Test262Error, function() {
|
||||
[].copyWithin(0, o1);
|
||||
});
|
||||
|
20
test/built-ins/Array/prototype/copyWithin/return-abrupt-from-target-as-symbol.js
vendored
Normal file
20
test/built-ins/Array/prototype/copyWithin/return-abrupt-from-target-as-symbol.js
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Return abrupt from target as a Symbol.
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
5. Let relativeTarget be ToInteger(target).
|
||||
6. ReturnIfAbrupt(relativeTarget).
|
||||
...
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var s = Symbol(1);
|
||||
assert.throws(TypeError, function() {
|
||||
[].copyWithin(s, 0);
|
||||
});
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Return abrupt from ToInteger(target).
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
5. Let relativeTarget be ToInteger(target).
|
||||
6. ReturnIfAbrupt(relativeTarget).
|
||||
...
|
||||
---*/
|
||||
|
||||
var o1 = {
|
||||
valueOf: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
};
|
||||
assert.throws(Test262Error, function() {
|
||||
[].copyWithin(o1);
|
||||
});
|
24
test/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length-as-symbol.js
vendored
Normal file
24
test/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length-as-symbol.js
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Return abrupt from ToLength(Get(O, "length")) where length is a Symbol.
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
1. Let O be ToObject(this value).
|
||||
2. ReturnIfAbrupt(O).
|
||||
3. Let len be ToLength(Get(O, "length")).
|
||||
4. ReturnIfAbrupt(len).
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var o = {};
|
||||
|
||||
o.length = Symbol(1);
|
||||
|
||||
// value argument is given to avoid false positives
|
||||
assert.throws(TypeError, function() {
|
||||
[].copyWithin.call(o, 0, 0);
|
||||
});
|
|
@ -0,0 +1,36 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Return abrupt from ToLength(Get(O, "length")).
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
1. Let O be ToObject(this value).
|
||||
2. ReturnIfAbrupt(O).
|
||||
3. Let len be ToLength(Get(O, "length")).
|
||||
4. ReturnIfAbrupt(len).
|
||||
---*/
|
||||
|
||||
var o1 = {};
|
||||
|
||||
Object.defineProperty(o1, 'length', {
|
||||
get: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
});
|
||||
assert.throws(Test262Error, function() {
|
||||
[].copyWithin.call(o1);
|
||||
});
|
||||
|
||||
var o2 = {
|
||||
length: {
|
||||
valueOf: function() {
|
||||
throw new Test262Error();
|
||||
}
|
||||
}
|
||||
};
|
||||
assert.throws(Test262Error, function() {
|
||||
[].copyWithin.call(o2);
|
||||
});
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Return abrupt from ToObject(this value).
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
1. Let O be ToObject(this value).
|
||||
2. ReturnIfAbrupt(O).
|
||||
---*/
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Array.prototype.copyWithin.call(undefined, 0, 0);
|
||||
});
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Array.prototype.copyWithin.call(null, 0, 0);
|
||||
});
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
Returns `this`.
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
18. Return O.
|
||||
---*/
|
||||
|
||||
var arr = [];
|
||||
var result = arr.copyWithin(0, 0);
|
||||
|
||||
assert.sameValue(result, arr);
|
||||
|
||||
var o = {
|
||||
length: 0
|
||||
};
|
||||
result = Array.prototype.copyWithin.call(o, 0, 0);
|
||||
assert.sameValue(result, o);
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright (C) 2015 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
es6id: 22.1.3.3
|
||||
description: >
|
||||
If `end` is undefined, set final position to `this.length`.
|
||||
info: >
|
||||
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
|
||||
|
||||
...
|
||||
11. If end is undefined, let relativeEnd be len; else let relativeEnd be
|
||||
ToInteger(end).
|
||||
...
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(0, 1, undefined),
|
||||
[1, 2, 3, 3]
|
||||
),
|
||||
'[0, 1, 2, 3].copyWithin(0, 1, undefined) -> [1, 2, 3]'
|
||||
);
|
||||
|
||||
assert(
|
||||
compareArray(
|
||||
[0, 1, 2, 3].copyWithin(0, 1),
|
||||
[1, 2, 3, 3]
|
||||
),
|
||||
'[0, 1, 2, 3].copyWithin(0, 1) -> [1, 2, 3, 3]'
|
||||
);
|
Loading…
Reference in New Issue