Add tests for Array.prototype.copyWithin

This commit is contained in:
Leonardo Balter 2015-07-24 17:45:31 -04:00
parent d54ff00df2
commit 935da0827b
31 changed files with 1194 additions and 0 deletions

View File

@ -0,0 +1,92 @@
// 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: >
Arguments are coerced to integer values.
info: >
22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] )
...
5. Let relativeTarget be ToInteger(target).
...
8. Let relativeStart be ToInteger(start).
...
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(undefined, undefined),
[0, 1, 2, 3]
),
'undefined `target` and `start` values coerced to 0'
);
assert(
compareArray(
[0, 1, 2, 3].copyWithin(false, false),
[0, 1, 2, 3]
),
'false `target` and `start` values coerced to 0'
);
assert(
compareArray(
[0, 1, 2, 3].copyWithin(NaN, NaN),
[0, 1, 2, 3]
),
'NaN `target` and `start` values coerced to 0'
);
assert(
compareArray(
[0, 1, 2, 3].copyWithin(null, null),
[0, 1, 2, 3]
),
'null `target` and `start` values coerced to 0'
);
assert(
compareArray(
[0, 1, 2, 3].copyWithin(true, 0),
[0, 0, 1, 2]
),
'true `target` value coerced to 1'
);
assert(
compareArray(
[0, 1, 2, 3].copyWithin(0, true),
[1, 2, 3, 3]
),
'true `start` value coerced to 1'
);
assert(
compareArray(
[0, 1, 2, 3].copyWithin(1, 0, true),
[0, 0, 2, 3]
),
'true `end` value coerced to 1'
);
assert(
compareArray(
[0, 1, 2, 3].copyWithin('1', '', '-2'),
[0, 0, 1, 3]
),
'string values coerced to integer'
);
assert(
compareArray(
[0, 1, 2, 3].copyWithin(1.3, 0.4, -2.5),
[0, 0, 1, 3]
),
'float values coerced to integer'
);

View 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: 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');

View File

@ -0,0 +1,15 @@
// 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.
includes: [compareArray.js]
---*/
assert(
compareArray(
[0, 1, , , 1].copyWithin(0, 1, 4),
[1, , , , 1]
)
);

View 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: 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');

View File

@ -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');

View File

@ -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]'
);

View File

@ -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]'
);

View File

@ -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]'
);

View File

@ -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]'
);

View File

@ -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]'
);

View 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: >
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]'
);

View File

@ -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]'
);

View 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]
)
);

View File

@ -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]
)
);

View 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]'
);

View 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);
});

View 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);
});

View 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 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).
...
---*/
var s = Symbol(1);
assert.throws(TypeError, function() {
[].copyWithin(0, 0, s);
});

View File

@ -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);
});

View 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);
});

View 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 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);
});

View 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);
});

View File

@ -0,0 +1,19 @@
// 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).
...
---*/
var s = Symbol(1);
assert.throws(TypeError, function() {
[].copyWithin(0, s);
});

View 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 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);
});

View 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);
});

View File

@ -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);
});

View 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);
});

View File

@ -0,0 +1,37 @@
// 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();
},
configurable: true
});
assert.throws(Test262Error, function() {
[].copyWithin.call(o1);
});
var o2 = {
length: {
valueOf: function() {
throw new Test262Error();
}
}
};
assert.throws(Test262Error, function() {
[].copyWithin.call(o2);
});

View 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 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);
});

View File

@ -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);

View File

@ -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]'
);