mirror of https://github.com/tc39/test262.git
fixup! Add tests for Array.prototype.copyWithin
This commit is contained in:
parent
935da0827b
commit
2a32ff4a66
|
@ -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'
|
||||||
|
);
|
|
@ -1,92 +0,0 @@
|
||||||
// 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'
|
|
||||||
);
|
|
|
@ -4,12 +4,15 @@
|
||||||
es6id: 22.1.3.3
|
es6id: 22.1.3.3
|
||||||
description: >
|
description: >
|
||||||
Loop from each property, even empty holes.
|
Loop from each property, even empty holes.
|
||||||
includes: [compareArray.js]
|
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
assert(
|
var arr = [0, 1, , , 1];
|
||||||
compareArray(
|
|
||||||
[0, 1, , , 1].copyWithin(0, 1, 4),
|
arr.copyWithin(0, 1, 4);
|
||||||
[1, , , , 1]
|
|
||||||
)
|
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);
|
||||||
|
|
|
@ -18,8 +18,7 @@ var o1 = {};
|
||||||
Object.defineProperty(o1, 'length', {
|
Object.defineProperty(o1, 'length', {
|
||||||
get: function() {
|
get: function() {
|
||||||
throw new Test262Error();
|
throw new Test262Error();
|
||||||
},
|
}
|
||||||
configurable: true
|
|
||||||
});
|
});
|
||||||
assert.throws(Test262Error, function() {
|
assert.throws(Test262Error, function() {
|
||||||
[].copyWithin.call(o1);
|
[].copyWithin.call(o1);
|
||||||
|
|
Loading…
Reference in New Issue