diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/Array/prototype/copyWithin | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Array/prototype/copyWithin')
40 files changed, 1532 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/browser.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/browser.js diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/call-with-boolean.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/call-with-boolean.js new file mode 100644 index 0000000000..27d06cec41 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/call-with-boolean.js @@ -0,0 +1,20 @@ +// Copyright (c) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.copyWithin +description: Array.prototype.copyWithin applied to boolean primitive +---*/ + +assert.sameValue( + Array.prototype.copyWithin.call(true) instanceof Boolean, + true, + 'The result of evaluating (Array.prototype.copyWithin.call(true) instanceof Boolean) is expected to be true' +); +assert.sameValue( + Array.prototype.copyWithin.call(false) instanceof Boolean, + true, + 'The result of evaluating (Array.prototype.copyWithin.call(false) instanceof Boolean) is expected to be true' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/coerced-values-end.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/coerced-values-end.js new file mode 100644 index 0000000000..7759eea41d --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/coerced-values-end.js @@ -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. +/*--- +esid: sec-array.prototype.copywithin +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], + '[0, 1, 2, 3].copyWithin(1, 0, null) must return [0, 1, 2, 3]' +); + +assert.compareArray( + [0, 1, 2, 3].copyWithin(1, 0, NaN), [0, 1, 2, 3], + '[0, 1, 2, 3].copyWithin(1, 0, NaN) must return [0, 1, 2, 3]' +); + +assert.compareArray( + [0, 1, 2, 3].copyWithin(1, 0, false), [0, 1, 2, 3], + '[0, 1, 2, 3].copyWithin(1, 0, false) must return [0, 1, 2, 3]' +); + +assert.compareArray( + [0, 1, 2, 3].copyWithin(1, 0, true), [0, 0, 2, 3], + '[0, 1, 2, 3].copyWithin(1, 0, true) must return [0, 0, 2, 3]' +); + +assert.compareArray( + [0, 1, 2, 3].copyWithin(1, 0, '-2'), [0, 0, 1, 3], + '[0, 1, 2, 3].copyWithin(1, 0, "-2") must return [0, 0, 1, 3]' +); + +assert.compareArray( + [0, 1, 2, 3].copyWithin(1, 0, -2.5), [0, 0, 1, 3], + '[0, 1, 2, 3].copyWithin(1, 0, -2.5) must return [0, 0, 1, 3]' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/coerced-values-start-change-start.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/coerced-values-start-change-start.js new file mode 100644 index 0000000000..0692e72247 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/coerced-values-start-change-start.js @@ -0,0 +1,57 @@ +// Copyright (C) 2019 Google. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.copywithin +description: > + SECURITY: start argument is coerced to an integer value + and side effects change the length of the array so that + the start is out of bounds +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 8. Let relativeStart be ToInteger(start). + ... +includes: [compareArray.js] +---*/ + + +// make a long integer Array +function longDenseArray(){ + var a = [0]; + for(var i = 0; i < 1024; i++){ + a[i] = i; + } + return a; +} + +function shorten(){ + currArray.length = 20; + return 1000; +} + +var array = []; +array.length = 20; + +var currArray = longDenseArray(); + +assert.compareArray( + currArray.copyWithin(0, {valueOf: shorten}), array, + 'currArray.copyWithin(0, {valueOf: shorten}) returns array' +); + +currArray = longDenseArray(); +Object.setPrototypeOf(currArray, longDenseArray()); + +var array2 = longDenseArray(); +array2.length = 20; +for(var i = 0; i < 24; i++){ + array2[i] = Object.getPrototypeOf(currArray)[i+1000]; +} + +assert.compareArray( + currArray.copyWithin(0, {valueOf: shorten}), array2, + 'currArray.copyWithin(0, {valueOf: shorten}) returns array2' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/coerced-values-start-change-target.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/coerced-values-start-change-target.js new file mode 100644 index 0000000000..cefe3e64a4 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/coerced-values-start-change-target.js @@ -0,0 +1,46 @@ +// Copyright (C) 2019 Google. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.copywithin +description: > + SECURITY: start argument is coerced to an integer value + and side effects change the length of the array so that + the target is out of bounds +info: | + 22.1.3.3 Array.prototype.copyWithin (target, start [ , end ] ) + + ... + 8. Let relativeStart be ToInteger(start). + ... +includes: [compareArray.js] +---*/ + + +// make a long integer Array +function longDenseArray(){ + var a = [0]; + for(var i = 0; i < 1024; i++){ + a[i] = i; + } + return a; +} + +function shorten(){ + currArray.length = 20; + return 1; +} + +var array = longDenseArray(); +array.length = 20; +for(var i = 0; i < 19; i++){ + array[i+1000] = array[i+1]; +} + +var currArray = longDenseArray(); + +assert.compareArray( + currArray.copyWithin(1000, {valueOf: shorten}), array, + 'currArray.copyWithin(1000, {valueOf: shorten}) returns array' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/coerced-values-start.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/coerced-values-start.js new file mode 100644 index 0000000000..804e795b56 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/coerced-values-start.js @@ -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. +/*--- +esid: sec-array.prototype.copywithin +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], + '[0, 1, 2, 3].copyWithin(1, undefined) must return [0, 0, 1, 2]' +); + +assert.compareArray( + [0, 1, 2, 3].copyWithin(1, false), [0, 0, 1, 2], + '[0, 1, 2, 3].copyWithin(1, false) must return [0, 0, 1, 2]' +); + +assert.compareArray( + [0, 1, 2, 3].copyWithin(1, NaN), [0, 0, 1, 2], + '[0, 1, 2, 3].copyWithin(1, NaN) must return [0, 0, 1, 2]' +); + +assert.compareArray( + [0, 1, 2, 3].copyWithin(1, null), [0, 0, 1, 2], + '[0, 1, 2, 3].copyWithin(1, null) must return [0, 0, 1, 2]' +); + + +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, true), [1, 2, 3, 3], + '[0, 1, 2, 3].copyWithin(0, true) must return [1, 2, 3, 3]' +); + + +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, '1'), [1, 2, 3, 3], + '[0, 1, 2, 3].copyWithin(0, "1") must return [1, 2, 3, 3]' +); + +assert.compareArray( + [0, 1, 2, 3].copyWithin(1, 0.5), [0, 0, 1, 2], + '[0, 1, 2, 3].copyWithin(1, 0.5) must return [0, 0, 1, 2]' +); + +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, 1.5), [1, 2, 3, 3], + '[0, 1, 2, 3].copyWithin(0, 1.5) must return [1, 2, 3, 3]' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/coerced-values-target.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/coerced-values-target.js new file mode 100644 index 0000000000..dac3cfd53b --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/coerced-values-target.js @@ -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. +/*--- +esid: sec-array.prototype.copywithin +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], + '[0, 1, 2, 3].copyWithin(undefined, 1) must return [1, 2, 3, 3]' +); + +assert.compareArray( + [0, 1, 2, 3].copyWithin(false, 1), [1, 2, 3, 3], + '[0, 1, 2, 3].copyWithin(false, 1) must return [1, 2, 3, 3]' +); + +assert.compareArray( + [0, 1, 2, 3].copyWithin(NaN, 1), [1, 2, 3, 3], + '[0, 1, 2, 3].copyWithin(NaN, 1) must return [1, 2, 3, 3]' +); + +assert.compareArray( + [0, 1, 2, 3].copyWithin(null, 1), [1, 2, 3, 3], + '[0, 1, 2, 3].copyWithin(null, 1) must return [1, 2, 3, 3]' +); + + +assert.compareArray( + [0, 1, 2, 3].copyWithin(true, 0), [0, 0, 1, 2], + '[0, 1, 2, 3].copyWithin(true, 0) must return [0, 0, 1, 2]' +); + + +assert.compareArray( + [0, 1, 2, 3].copyWithin('1', 0), [0, 0, 1, 2], + '[0, 1, 2, 3].copyWithin("1", 0) must return [0, 0, 1, 2]' +); + +assert.compareArray( + [0, 1, 2, 3].copyWithin(0.5, 1), [1, 2, 3, 3], + '[0, 1, 2, 3].copyWithin(0.5, 1) must return [1, 2, 3, 3]' +); + +assert.compareArray( + [0, 1, 2, 3].copyWithin(1.5, 0), [0, 0, 1, 2], + '[0, 1, 2, 3].copyWithin(1.5, 0) must return [0, 0, 1, 2]' +); + +assert.compareArray( + [0, 1, 2, 3].copyWithin({}, 1), [1, 2, 3, 3], + '[0, 1, 2, 3].copyWithin({}, 1) must return [1, 2, 3, 3]' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/fill-holes.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/fill-holes.js new file mode 100644 index 0000000000..972c5d82a7 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/fill-holes.js @@ -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. +/*--- +esid: sec-array.prototype.copywithin +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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/length-near-integer-limit.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/length-near-integer-limit.js new file mode 100644 index 0000000000..ba7b59991a --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/length-near-integer-limit.js @@ -0,0 +1,45 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.copywithin +description: > + Elements are copied and deleted in an array-like object + whose "length" property is near the integer limit. +info: | + Array.prototype.copyWithin ( target, start [ , end ] ) + + 1. Let O be ? ToObject(this value). + 2. Let len be ? LengthOfArrayLike(O). + [...] + 9. Let count be min(final - from, len - to). + [...] + 12. Repeat, while count > 0 + [...] + d. If fromPresent is true, then + i. Let fromVal be ? Get(O, fromKey). + ii. Perform ? Set(O, toKey, fromVal, true). + e. Else, + i. Assert: fromPresent is false. + ii. Perform ? DeletePropertyOrThrow(O, toKey). + [...] +---*/ + +var startIndex = Number.MAX_SAFE_INTEGER - 3; +var arrayLike = { + 0: 0, + 1: 1, + 2: 2, + length: Number.MAX_SAFE_INTEGER, +}; + +arrayLike[startIndex] = -3; +arrayLike[startIndex + 2] = -1; + +Array.prototype.copyWithin.call(arrayLike, 0, startIndex, startIndex + 3); + +assert.sameValue(arrayLike[0], -3); +assert.sameValue(1 in arrayLike, false); +assert.sameValue(arrayLike[2], -1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/length.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/length.js new file mode 100644 index 0000000000..e846f74754 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/length.js @@ -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. +/*--- +esid: sec-array.prototype.copywithin +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/name.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/name.js new file mode 100644 index 0000000000..c8c6c0b5b9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/name.js @@ -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. +/*--- +esid: sec-array.prototype.copywithin +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/negative-end.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/negative-end.js new file mode 100644 index 0000000000..3bea4299b5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/negative-end.js @@ -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. +/*--- +esid: sec-array.prototype.copywithin +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) must return [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) must return [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) must return [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) must return [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) must return [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) must return [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) must return [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) must return [3, 1, 2, 3, 4]' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/negative-out-of-bounds-end.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/negative-out-of-bounds-end.js new file mode 100644 index 0000000000..acd8f91c95 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/negative-out-of-bounds-end.js @@ -0,0 +1,70 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.copywithin +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) must return [0, 1, 2, 3]' +); + +assert.compareArray( + [1, 2, 3, 4, 5].copyWithin(0, 1, -Infinity), [1, 2, 3, 4, 5], + '[1, 2, 3, 4, 5].copyWithin(0, 1, -Infinity) must return [1, 2, 3, 4, 5]' +); + +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, -2, -10), [0, 1, 2, 3], + '[0, 1, 2, 3].copyWithin(0, -2, -10) must return [0, 1, 2, 3]' +); + +assert.compareArray( + [1, 2, 3, 4, 5].copyWithin(0, -2, -Infinity), [1, 2, 3, 4, 5], + '[1, 2, 3, 4, 5].copyWithin(0, -2, -Infinity) must return [1, 2, 3, 4, 5]' +); + +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, -9, -10), [0, 1, 2, 3], + '[0, 1, 2, 3].copyWithin(0, -9, -10) must return [0, 1, 2, 3]' +); + +assert.compareArray( + [1, 2, 3, 4, 5].copyWithin(0, -9, -Infinity), [1, 2, 3, 4, 5], + '[1, 2, 3, 4, 5].copyWithin(0, -9, -Infinity) must return [1, 2, 3, 4, 5]' +); + +assert.compareArray( + [0, 1, 2, 3].copyWithin(-3, -2, -10), [0, 1, 2, 3], + '[0, 1, 2, 3].copyWithin(-3, -2, -10) must return [0, 1, 2, 3]' +); + +assert.compareArray( + [1, 2, 3, 4, 5].copyWithin(-3, -2, -Infinity), [1, 2, 3, 4, 5], + '[1, 2, 3, 4, 5].copyWithin(-3, -2, -Infinity) must return [1, 2, 3, 4, 5]' +); + +assert.compareArray( + [0, 1, 2, 3].copyWithin(-7, -8, -9), [0, 1, 2, 3], + '[0, 1, 2, 3].copyWithin(-7, -8, -9) must return [0, 1, 2, 3]' +); + +assert.compareArray( + [1, 2, 3, 4, 5].copyWithin(-7, -8, -Infinity), [1, 2, 3, 4, 5], + '[1, 2, 3, 4, 5].copyWithin(-7, -8, -Infinity) must return [1, 2, 3, 4, 5]' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/negative-out-of-bounds-start.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/negative-out-of-bounds-start.js new file mode 100644 index 0000000000..7faf5378eb --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/negative-out-of-bounds-start.js @@ -0,0 +1,59 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.copywithin +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) must return [0, 1, 2, 3]' +); + +assert.compareArray( + [1, 2, 3, 4, 5].copyWithin(0, -Infinity), [1, 2, 3, 4, 5], + '[1, 2, 3, 4, 5].copyWithin(0, -Infinity) must return [1, 2, 3, 4, 5]' +); + +assert.compareArray( + [0, 1, 2, 3, 4].copyWithin(2, -10), [0, 1, 0, 1, 2], + '[0, 1, 2, 3, 4].copyWithin(2, -10) must return [0, 1, 0, 1, 2]' +); + +assert.compareArray( + [1, 2, 3, 4, 5].copyWithin(2, -Infinity), [1, 2, 1, 2, 3], + '[1, 2, 3, 4, 5].copyWithin(2, -Infinity) must return [1, 2, 1, 2, 3]' +); + + +assert.compareArray( + [0, 1, 2, 3, 4].copyWithin(10, -10), [0, 1, 2, 3, 4], + '[0, 1, 2, 3, 4].copyWithin(10, -10) must return [0, 1, 2, 3, 4]' +); + +assert.compareArray( + [1, 2, 3, 4, 5].copyWithin(10, -Infinity), [1, 2, 3, 4, 5], + '[1, 2, 3, 4, 5].copyWithin(10, -Infinity) must return [1, 2, 3, 4, 5]' +); + + +assert.compareArray( + [0, 1, 2, 3].copyWithin(-9, -10), [0, 1, 2, 3], + '[0, 1, 2, 3].copyWithin(-9, -10) must return [0, 1, 2, 3]' +); + +assert.compareArray( + [1, 2, 3, 4, 5].copyWithin(-9, -Infinity), [1, 2, 3, 4, 5], + '[1, 2, 3, 4, 5].copyWithin(-9, -Infinity) must return [1, 2, 3, 4, 5]' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/negative-out-of-bounds-target.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/negative-out-of-bounds-target.js new file mode 100644 index 0000000000..6bc927c1fc --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/negative-out-of-bounds-target.js @@ -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. +/*--- +esid: sec-array.prototype.copywithin +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) must return [0, 1, 2, 3]' +); + +assert.compareArray( + [1, 2, 3, 4, 5].copyWithin(-Infinity, 0), [1, 2, 3, 4, 5], + '[1, 2, 3, 4, 5].copyWithin(-Infinity, 0) must return [1, 2, 3, 4, 5]' +); + +assert.compareArray( + [0, 1, 2, 3, 4].copyWithin(-10, 2), [2, 3, 4, 3, 4], + '[0, 1, 2, 3, 4].copyWithin(-10, 2) must return [2, 3, 4, 3, 4]' +); + +assert.compareArray( + [1, 2, 3, 4, 5].copyWithin(-Infinity, 2), [3, 4, 5, 4, 5], + '[1, 2, 3, 4, 5].copyWithin(-Infinity, 2) must return [3, 4, 5, 4, 5]' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/negative-start.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/negative-start.js new file mode 100644 index 0000000000..9bed566c60 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/negative-start.js @@ -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. +/*--- +esid: sec-array.prototype.copywithin +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) must return [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) must return [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) must return [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) must return [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) must return [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) must return [3, 4, 2, 3, 4]' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/negative-target.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/negative-target.js new file mode 100644 index 0000000000..232ddf0d2d --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/negative-target.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.copywithin +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) must return [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) must return [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) must return [0, 1, 2, 2]' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/non-negative-out-of-bounds-end.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/non-negative-out-of-bounds-end.js new file mode 100644 index 0000000000..079beae545 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/non-negative-out-of-bounds-end.js @@ -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. +/*--- +esid: sec-array.prototype.copywithin +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) must return [1, 2, 3, 3]' +); + +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, 1, Infinity), [1, 2, 3, 3], + '[0, 1, 2, 3].copyWithin(0, 1, Infinity) must return [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) must return [0, 3, 4, 5, 4, 5]' +); + +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(1, 3, Infinity), [0, 3, 4, 5, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(1, 3, Infinity) must return [0, 3, 4, 5, 4, 5]' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/non-negative-out-of-bounds-target-and-start.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/non-negative-out-of-bounds-target-and-start.js new file mode 100644 index 0000000000..13f3ff3388 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/non-negative-out-of-bounds-target-and-start.js @@ -0,0 +1,107 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.copywithin +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], + '[0, 1, 2, 3, 4, 5].copyWithin(6, 0) must return [0, 1, 2, 3, 4, 5]' +); + +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(7, 0), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(7, 0) must return [0, 1, 2, 3, 4, 5]' +); + +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(Infinity, 0), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(Infinity, 0) must return [0, 1, 2, 3, 4, 5]' +); + +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(6, 2), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(6, 2) must return [0, 1, 2, 3, 4, 5]' +); + +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(7, 2), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(7, 2) must return [0, 1, 2, 3, 4, 5]' +); + +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(Infinity, 2), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(Infinity, 2) must return [0, 1, 2, 3, 4, 5]' +); + +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(0, 6), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(0, 6) must return [0, 1, 2, 3, 4, 5]' +); + +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(0, 7), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(0, 7) must return [0, 1, 2, 3, 4, 5]' +); + + +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(0, Infinity), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(0, Infinity) must return [0, 1, 2, 3, 4, 5]' +); + +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(2, 6), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(2, 6) must return [0, 1, 2, 3, 4, 5]' +); + +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(1, 7), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(1, 7) must return [0, 1, 2, 3, 4, 5]' +); + + +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(3, Infinity), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(3, Infinity) must return [0, 1, 2, 3, 4, 5]' +); + +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(6, 6), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(6, 6) must return [0, 1, 2, 3, 4, 5]' +); + +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(10, 10), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(10, 10) must return [0, 1, 2, 3, 4, 5]' +); + +assert.compareArray( + [0, 1, 2, 3, 4, 5].copyWithin(Infinity, Infinity), [0, 1, 2, 3, 4, 5], + '[0, 1, 2, 3, 4, 5].copyWithin(Infinity, Infinity) must return [0, 1, 2, 3, 4, 5]' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/non-negative-target-and-start.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/non-negative-target-and-start.js new file mode 100644 index 0000000000..da1d411abc --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/non-negative-target-and-start.js @@ -0,0 +1,54 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.copywithin +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] +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/non-negative-target-start-and-end.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/non-negative-target-start-and-end.js new file mode 100644 index 0000000000..ffbda9c208 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/non-negative-target-start-and-end.js @@ -0,0 +1,72 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.copywithin +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) must return [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) must return [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) must return [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) must return [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) must return [0, 3, 4, 3, 4, 5]' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/not-a-constructor.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/not-a-constructor.js new file mode 100644 index 0000000000..f16770a6c5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/not-a-constructor.js @@ -0,0 +1,35 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Array.prototype.copyWithin does not implement [[Construct]], is not new-able +info: | + ECMAScript Function Objects + + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified in + the description of a particular function. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, arrow-function] +---*/ + +assert.sameValue( + isConstructor(Array.prototype.copyWithin), + false, + 'isConstructor(Array.prototype.copyWithin) must return false' +); + +assert.throws(TypeError, () => { + new Array.prototype.copyWithin(); +}, '`new Array.prototype.copyWithin()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/prop-desc.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/prop-desc.js new file mode 100644 index 0000000000..0142ba32ed --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/prop-desc.js @@ -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. +/*--- +esid: sec-array.prototype.copywithin +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'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-delete-proxy-target.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-delete-proxy-target.js new file mode 100644 index 0000000000..efbb992e30 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-delete-proxy-target.js @@ -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. +/*--- +esid: sec-array.prototype.copywithin +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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-delete-target.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-delete-target.js new file mode 100644 index 0000000000..14c970ecb5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-delete-target.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.copywithin +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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-end-as-symbol.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-end-as-symbol.js new file mode 100644 index 0000000000..345ad8d3c6 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-end-as-symbol.js @@ -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. +/*--- +esid: sec-array.prototype.copywithin +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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-end.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-end.js new file mode 100644 index 0000000000..cfe2a7353f --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-end.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.copywithin +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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-get-start-value.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-get-start-value.js new file mode 100644 index 0000000000..559520b1c0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-get-start-value.js @@ -0,0 +1,41 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.copywithin +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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-has-start.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-has-start.js new file mode 100644 index 0000000000..8a7d16735c --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-has-start.js @@ -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. +/*--- +esid: sec-array.prototype.copywithin +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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-set-target-value.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-set-target-value.js new file mode 100644 index 0000000000..fa66f8a706 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-set-target-value.js @@ -0,0 +1,42 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.copywithin +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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-start-as-symbol.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-start-as-symbol.js new file mode 100644 index 0000000000..a766cafaeb --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-start-as-symbol.js @@ -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. +/*--- +esid: sec-array.prototype.copywithin +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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-start.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-start.js new file mode 100644 index 0000000000..93eb3cf5d2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-start.js @@ -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. +/*--- +esid: sec-array.prototype.copywithin +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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-target-as-symbol.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-target-as-symbol.js new file mode 100644 index 0000000000..2c318faa5e --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-target-as-symbol.js @@ -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. +/*--- +esid: sec-array.prototype.copywithin +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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-target.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-target.js new file mode 100644 index 0000000000..4eb0d794b0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-target.js @@ -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. +/*--- +esid: sec-array.prototype.copywithin +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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length-as-symbol.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length-as-symbol.js new file mode 100644 index 0000000000..51de5bcc74 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length-as-symbol.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.copywithin +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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length.js new file mode 100644 index 0000000000..99f789d9e4 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length.js @@ -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. +/*--- +esid: sec-array.prototype.copywithin +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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-this.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-this.js new file mode 100644 index 0000000000..52b27cc214 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-abrupt-from-this.js @@ -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. +/*--- +esid: sec-array.prototype.copywithin +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); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-this.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-this.js new file mode 100644 index 0000000000..6a60d8479f --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/return-this.js @@ -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. +/*--- +esid: sec-array.prototype.copywithin +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); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/shell.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/shell.js diff --git a/js/src/tests/test262/built-ins/Array/prototype/copyWithin/undefined-end.js b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/undefined-end.js new file mode 100644 index 0000000000..ae2f4e3256 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/copyWithin/undefined-end.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.copywithin +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) must return [1, 2, 3, 3]' +); + +assert.compareArray( + [0, 1, 2, 3].copyWithin(0, 1), [1, 2, 3, 3], + '[0, 1, 2, 3].copyWithin(0, 1) must return [1, 2, 3, 3]' +); + +reportCompare(0, 0); |