From 935da0827b0450d86305953c9f9f94ae4152f084 Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Fri, 24 Jul 2015 17:45:31 -0400 Subject: [PATCH 1/3] Add tests for Array.prototype.copyWithin --- .../prototype/copyWithin/coerced-values.js | 92 +++++++++++++++++++ .../Array/prototype/copyWithin/copyWithin.js | 21 +++++ .../Array/prototype/copyWithin/fill-holes.js | 15 +++ .../Array/prototype/copyWithin/length.js | 20 ++++ .../Array/prototype/copyWithin/name.js | 22 +++++ .../prototype/copyWithin/negative-end.js | 82 +++++++++++++++++ .../copyWithin/negative-out-of-bounds-end.js | 58 ++++++++++++ .../negative-out-of-bounds-start.js | 47 ++++++++++ .../negative-out-of-bounds-target.js | 31 +++++++ .../prototype/copyWithin/negative-start.js | 63 +++++++++++++ .../prototype/copyWithin/negative-target.js | 39 ++++++++ .../non-negative-out-of-bounds-end.js | 50 ++++++++++ ...negative-out-of-bounds-target-and-start.js | 56 +++++++++++ .../non-negative-target-and-start.js | 60 ++++++++++++ .../non-negative-target-start-and-end.js | 85 +++++++++++++++++ .../return-abrupt-from-delete-proxy-target.js | 38 ++++++++ .../return-abrupt-from-delete-target.js | 33 +++++++ .../return-abrupt-from-end-as-symbol.js | 20 ++++ .../copyWithin/return-abrupt-from-end.js | 25 +++++ .../return-abrupt-from-get-start-value.js | 39 ++++++++ .../return-abrupt-from-has-start.js | 38 ++++++++ .../return-abrupt-from-set-target-value.js | 40 ++++++++ .../return-abrupt-from-start-as-symbol.js | 19 ++++ .../copyWithin/return-abrupt-from-start.js | 24 +++++ .../return-abrupt-from-target-as-symbol.js | 20 ++++ .../copyWithin/return-abrupt-from-target.js | 23 +++++ ...eturn-abrupt-from-this-length-as-symbol.js | 24 +++++ .../return-abrupt-from-this-length.js | 37 ++++++++ .../copyWithin/return-abrupt-from-this.js | 20 ++++ .../Array/prototype/copyWithin/return-this.js | 22 +++++ .../prototype/copyWithin/undefined-end.js | 31 +++++++ 31 files changed, 1194 insertions(+) create mode 100644 test/built-ins/Array/prototype/copyWithin/coerced-values.js create mode 100644 test/built-ins/Array/prototype/copyWithin/copyWithin.js create mode 100644 test/built-ins/Array/prototype/copyWithin/fill-holes.js create mode 100644 test/built-ins/Array/prototype/copyWithin/length.js create mode 100644 test/built-ins/Array/prototype/copyWithin/name.js create mode 100644 test/built-ins/Array/prototype/copyWithin/negative-end.js create mode 100644 test/built-ins/Array/prototype/copyWithin/negative-out-of-bounds-end.js create mode 100644 test/built-ins/Array/prototype/copyWithin/negative-out-of-bounds-start.js create mode 100644 test/built-ins/Array/prototype/copyWithin/negative-out-of-bounds-target.js create mode 100644 test/built-ins/Array/prototype/copyWithin/negative-start.js create mode 100644 test/built-ins/Array/prototype/copyWithin/negative-target.js create mode 100644 test/built-ins/Array/prototype/copyWithin/non-negative-out-of-bounds-end.js create mode 100644 test/built-ins/Array/prototype/copyWithin/non-negative-out-of-bounds-target-and-start.js create mode 100644 test/built-ins/Array/prototype/copyWithin/non-negative-target-and-start.js create mode 100644 test/built-ins/Array/prototype/copyWithin/non-negative-target-start-and-end.js create mode 100644 test/built-ins/Array/prototype/copyWithin/return-abrupt-from-delete-proxy-target.js create mode 100644 test/built-ins/Array/prototype/copyWithin/return-abrupt-from-delete-target.js create mode 100644 test/built-ins/Array/prototype/copyWithin/return-abrupt-from-end-as-symbol.js create mode 100644 test/built-ins/Array/prototype/copyWithin/return-abrupt-from-end.js create mode 100644 test/built-ins/Array/prototype/copyWithin/return-abrupt-from-get-start-value.js create mode 100644 test/built-ins/Array/prototype/copyWithin/return-abrupt-from-has-start.js create mode 100644 test/built-ins/Array/prototype/copyWithin/return-abrupt-from-set-target-value.js create mode 100644 test/built-ins/Array/prototype/copyWithin/return-abrupt-from-start-as-symbol.js create mode 100644 test/built-ins/Array/prototype/copyWithin/return-abrupt-from-start.js create mode 100644 test/built-ins/Array/prototype/copyWithin/return-abrupt-from-target-as-symbol.js create mode 100644 test/built-ins/Array/prototype/copyWithin/return-abrupt-from-target.js create mode 100644 test/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length-as-symbol.js create mode 100644 test/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length.js create mode 100644 test/built-ins/Array/prototype/copyWithin/return-abrupt-from-this.js create mode 100644 test/built-ins/Array/prototype/copyWithin/return-this.js create mode 100644 test/built-ins/Array/prototype/copyWithin/undefined-end.js diff --git a/test/built-ins/Array/prototype/copyWithin/coerced-values.js b/test/built-ins/Array/prototype/copyWithin/coerced-values.js new file mode 100644 index 0000000000..4f5720bbad --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/coerced-values.js @@ -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' +); diff --git a/test/built-ins/Array/prototype/copyWithin/copyWithin.js b/test/built-ins/Array/prototype/copyWithin/copyWithin.js new file mode 100644 index 0000000000..7b22be6aa6 --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/copyWithin.js @@ -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'); diff --git a/test/built-ins/Array/prototype/copyWithin/fill-holes.js b/test/built-ins/Array/prototype/copyWithin/fill-holes.js new file mode 100644 index 0000000000..d1b25a2391 --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/fill-holes.js @@ -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] + ) +); diff --git a/test/built-ins/Array/prototype/copyWithin/length.js b/test/built-ins/Array/prototype/copyWithin/length.js new file mode 100644 index 0000000000..af9fe38286 --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/length.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. +/*--- +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'); diff --git a/test/built-ins/Array/prototype/copyWithin/name.js b/test/built-ins/Array/prototype/copyWithin/name.js new file mode 100644 index 0000000000..56fcc5a7be --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/name.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. +/*--- +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'); diff --git a/test/built-ins/Array/prototype/copyWithin/negative-end.js b/test/built-ins/Array/prototype/copyWithin/negative-end.js new file mode 100644 index 0000000000..54ee64830b --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/negative-end.js @@ -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]' +); diff --git a/test/built-ins/Array/prototype/copyWithin/negative-out-of-bounds-end.js b/test/built-ins/Array/prototype/copyWithin/negative-out-of-bounds-end.js new file mode 100644 index 0000000000..cc6d196bb9 --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/negative-out-of-bounds-end.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. +/*--- +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]' +); \ No newline at end of file diff --git a/test/built-ins/Array/prototype/copyWithin/negative-out-of-bounds-start.js b/test/built-ins/Array/prototype/copyWithin/negative-out-of-bounds-start.js new file mode 100644 index 0000000000..278f31df04 --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/negative-out-of-bounds-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. +/*--- +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]' +); diff --git a/test/built-ins/Array/prototype/copyWithin/negative-out-of-bounds-target.js b/test/built-ins/Array/prototype/copyWithin/negative-out-of-bounds-target.js new file mode 100644 index 0000000000..3ada753cde --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/negative-out-of-bounds-target.js @@ -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]' +); diff --git a/test/built-ins/Array/prototype/copyWithin/negative-start.js b/test/built-ins/Array/prototype/copyWithin/negative-start.js new file mode 100644 index 0000000000..f53dd25161 --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/negative-start.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. +/*--- +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]' +); diff --git a/test/built-ins/Array/prototype/copyWithin/negative-target.js b/test/built-ins/Array/prototype/copyWithin/negative-target.js new file mode 100644 index 0000000000..c999e72af5 --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/negative-target.js @@ -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]' +); diff --git a/test/built-ins/Array/prototype/copyWithin/non-negative-out-of-bounds-end.js b/test/built-ins/Array/prototype/copyWithin/non-negative-out-of-bounds-end.js new file mode 100644 index 0000000000..dc0fbb0bc6 --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/non-negative-out-of-bounds-end.js @@ -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 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]' +); \ No newline at end of file diff --git a/test/built-ins/Array/prototype/copyWithin/non-negative-out-of-bounds-target-and-start.js b/test/built-ins/Array/prototype/copyWithin/non-negative-out-of-bounds-target-and-start.js new file mode 100644 index 0000000000..1099bf013d --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/non-negative-out-of-bounds-target-and-start.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. +/*--- +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 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] + ) +); diff --git a/test/built-ins/Array/prototype/copyWithin/non-negative-target-and-start.js b/test/built-ins/Array/prototype/copyWithin/non-negative-target-and-start.js new file mode 100644 index 0000000000..f706d0a669 --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/non-negative-target-and-start.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. +/*--- +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 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] + ) +); diff --git a/test/built-ins/Array/prototype/copyWithin/non-negative-target-start-and-end.js b/test/built-ins/Array/prototype/copyWithin/non-negative-target-start-and-end.js new file mode 100644 index 0000000000..4643f2dbb6 --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/non-negative-target-start-and-end.js @@ -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 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 [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]' +); \ No newline at end of file diff --git a/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-delete-proxy-target.js b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-delete-proxy-target.js new file mode 100644 index 0000000000..67bf816af5 --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-delete-proxy-target.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. +/*--- +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); +}); diff --git a/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-delete-target.js b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-delete-target.js new file mode 100644 index 0000000000..f8182feb3b --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-delete-target.js @@ -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); +}); diff --git a/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-end-as-symbol.js b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-end-as-symbol.js new file mode 100644 index 0000000000..4b38b0aca6 --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-end-as-symbol.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. +/*--- +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); +}); diff --git a/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-end.js b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-end.js new file mode 100644 index 0000000000..b925cad9f5 --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-end.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. +/*--- +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); +}); + diff --git a/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-get-start-value.js b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-get-start-value.js new file mode 100644 index 0000000000..06f13e2f42 --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-get-start-value.js @@ -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); +}); diff --git a/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-has-start.js b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-has-start.js new file mode 100644 index 0000000000..4b012541b3 --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-has-start.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. +/*--- +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); +}); diff --git a/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-set-target-value.js b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-set-target-value.js new file mode 100644 index 0000000000..7f2b61fd7d --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-set-target-value.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. +/*--- +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); +}); diff --git a/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-start-as-symbol.js b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-start-as-symbol.js new file mode 100644 index 0000000000..4a56e2d55a --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-start-as-symbol.js @@ -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); +}); diff --git a/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-start.js b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-start.js new file mode 100644 index 0000000000..ce0dd8a7c8 --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-start.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. +/*--- +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); +}); + diff --git a/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-target-as-symbol.js b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-target-as-symbol.js new file mode 100644 index 0000000000..3c7629791d --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-target-as-symbol.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. +/*--- +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); +}); diff --git a/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-target.js b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-target.js new file mode 100644 index 0000000000..b9055e7f94 --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-target.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. +/*--- +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); +}); diff --git a/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length-as-symbol.js b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length-as-symbol.js new file mode 100644 index 0000000000..51e43b5e43 --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length-as-symbol.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. +/*--- +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); +}); diff --git a/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length.js b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length.js new file mode 100644 index 0000000000..20f5d7d446 --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length.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. +/*--- +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); +}); diff --git a/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-this.js b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-this.js new file mode 100644 index 0000000000..96696309b6 --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-this.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. +/*--- +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); +}); diff --git a/test/built-ins/Array/prototype/copyWithin/return-this.js b/test/built-ins/Array/prototype/copyWithin/return-this.js new file mode 100644 index 0000000000..4e0f91e8eb --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/return-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. +/*--- +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); diff --git a/test/built-ins/Array/prototype/copyWithin/undefined-end.js b/test/built-ins/Array/prototype/copyWithin/undefined-end.js new file mode 100644 index 0000000000..fb30ce5431 --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/undefined-end.js @@ -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]' +); From 2a32ff4a6667cc2d08881497e96073e00903f1ea Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Fri, 31 Jul 2015 16:44:28 -0400 Subject: [PATCH 2/3] fixup! Add tests for Array.prototype.copyWithin --- .../copyWithin/coerced-values-end.js | 63 +++++++++++++ .../copyWithin/coerced-values-start.js | 80 ++++++++++++++++ .../copyWithin/coerced-values-target.js | 80 ++++++++++++++++ .../prototype/copyWithin/coerced-values.js | 92 ------------------- .../Array/prototype/copyWithin/fill-holes.js | 17 ++-- .../return-abrupt-from-this-length.js | 3 +- 6 files changed, 234 insertions(+), 101 deletions(-) create mode 100644 test/built-ins/Array/prototype/copyWithin/coerced-values-end.js create mode 100644 test/built-ins/Array/prototype/copyWithin/coerced-values-start.js create mode 100644 test/built-ins/Array/prototype/copyWithin/coerced-values-target.js delete mode 100644 test/built-ins/Array/prototype/copyWithin/coerced-values.js diff --git a/test/built-ins/Array/prototype/copyWithin/coerced-values-end.js b/test/built-ins/Array/prototype/copyWithin/coerced-values-end.js new file mode 100644 index 0000000000..1580980b00 --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/coerced-values-end.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. +/*--- +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' +); diff --git a/test/built-ins/Array/prototype/copyWithin/coerced-values-start.js b/test/built-ins/Array/prototype/copyWithin/coerced-values-start.js new file mode 100644 index 0000000000..37d7644f2b --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/coerced-values-start.js @@ -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' +); \ No newline at end of file diff --git a/test/built-ins/Array/prototype/copyWithin/coerced-values-target.js b/test/built-ins/Array/prototype/copyWithin/coerced-values-target.js new file mode 100644 index 0000000000..3743bc1034 --- /dev/null +++ b/test/built-ins/Array/prototype/copyWithin/coerced-values-target.js @@ -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' +); \ No newline at end of file diff --git a/test/built-ins/Array/prototype/copyWithin/coerced-values.js b/test/built-ins/Array/prototype/copyWithin/coerced-values.js deleted file mode 100644 index 4f5720bbad..0000000000 --- a/test/built-ins/Array/prototype/copyWithin/coerced-values.js +++ /dev/null @@ -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' -); diff --git a/test/built-ins/Array/prototype/copyWithin/fill-holes.js b/test/built-ins/Array/prototype/copyWithin/fill-holes.js index d1b25a2391..a54e655f46 100644 --- a/test/built-ins/Array/prototype/copyWithin/fill-holes.js +++ b/test/built-ins/Array/prototype/copyWithin/fill-holes.js @@ -4,12 +4,15 @@ 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] - ) -); +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); diff --git a/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length.js b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length.js index 20f5d7d446..7c8da2671c 100644 --- a/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length.js +++ b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-this-length.js @@ -18,8 +18,7 @@ var o1 = {}; Object.defineProperty(o1, 'length', { get: function() { throw new Test262Error(); - }, - configurable: true + } }); assert.throws(Test262Error, function() { [].copyWithin.call(o1); From e72f4bcd62cf14ca007caa379d08276607b0dc43 Mon Sep 17 00:00:00 2001 From: Leonardo Balter Date: Fri, 31 Jul 2015 16:46:14 -0400 Subject: [PATCH 3/3] fixup! Add tests for Array.prototype.copyWithin --- .../prototype/copyWithin/return-abrupt-from-end-as-symbol.js | 1 + .../prototype/copyWithin/return-abrupt-from-start-as-symbol.js | 1 + 2 files changed, 2 insertions(+) diff --git a/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-end-as-symbol.js b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-end-as-symbol.js index 4b38b0aca6..89276666a9 100644 --- a/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-end-as-symbol.js +++ b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-end-as-symbol.js @@ -12,6 +12,7 @@ info: > ToInteger(end). 12. ReturnIfAbrupt(relativeEnd). ... +features: [Symbol] ---*/ var s = Symbol(1); diff --git a/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-start-as-symbol.js b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-start-as-symbol.js index 4a56e2d55a..276a7625d9 100644 --- a/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-start-as-symbol.js +++ b/test/built-ins/Array/prototype/copyWithin/return-abrupt-from-start-as-symbol.js @@ -11,6 +11,7 @@ info: > 8. Let relativeStart be ToInteger(start). 9. ReturnIfAbrupt(relativeStart). ... +features: [Symbol] ---*/ var s = Symbol(1);