diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/Array/prototype/unshift')
23 files changed, 1041 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A1_T1.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A1_T1.js new file mode 100644 index 0000000000..121386346c --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A1_T1.js @@ -0,0 +1,49 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The arguments are prepended to the start of the array, such that + their order within the array is the same as the order in which they appear in + the argument list +esid: sec-array.prototype.unshift +description: Checking case when unsift is given no arguments or one argument +---*/ + +var x = new Array(); +var unshift = x.unshift(1); +if (unshift !== 1) { + throw new Test262Error('#1: x = new Array(); x.unshift(1) === 1. Actual: ' + (unshift)); +} + +if (x[0] !== 1) { + throw new Test262Error('#2: x = new Array(); x.unshift(1); x[0] === 1. Actual: ' + (x[0])); +} + +var unshift = x.unshift(); +if (unshift !== 1) { + throw new Test262Error('#3: x = new Array(); x.unshift(1); x.unshift() === 1. Actual: ' + (unshift)); +} + +if (x[1] !== undefined) { + throw new Test262Error('#4: x = new Array(); x.unshift(1); x.unshift(); x[1] === unedfined. Actual: ' + (x[1])); +} + +var unshift = x.unshift(-1); +if (unshift !== 2) { + throw new Test262Error('#5: x = new Array(); x.unshift(1); x.unshift(); x.unshift(-1) === 2. Actual: ' + (unshift)); +} + +if (x[0] !== -1) { + throw new Test262Error('#6: x = new Array(); x.unshift(1); x.unshift(-1); x[0] === -1. Actual: ' + (x[0])); +} + +if (x[1] !== 1) { + throw new Test262Error('#7: x = new Array(); x.unshift(1); x.unshift(-1); x[1] === 1. Actual: ' + (x[1])); +} + +if (x.length !== 2) { + throw new Test262Error('#8: x = new Array(); x.unshift(1); x.unshift(); x.unshift(-1); x.length === 2. Actual: ' + (x.length)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A1_T2.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A1_T2.js new file mode 100644 index 0000000000..be04543498 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A1_T2.js @@ -0,0 +1,52 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The arguments are prepended to the start of the array, such that + their order within the array is the same as the order in which they appear in + the argument list +esid: sec-array.prototype.unshift +description: Checking case when unsift is given many arguments +---*/ + +var x = []; +if (x.length !== 0) { + throw new Test262Error('#1: x = []; x.length === 0. Actual: ' + (x.length)); +} + +x[0] = 0; +var unshift = x.unshift(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); +if (unshift !== 6) { + throw new Test262Error('#2: x = []; x[0] = 0; x.unshift(true, Number.POSITIVE_INFINITY, "NaN", "1", -1) === 6. Actual: ' + (unshift)); +} + +if (x[5] !== 0) { + throw new Test262Error('#3: x = []; x[0] = 0; x.unshift(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); x[5] === 0. Actual: ' + (x[5])); +} + +if (x[0] !== true) { + throw new Test262Error('#4: x = []; x[0] = 0; x.unshift(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); x[0] === true. Actual: ' + (x[0])); +} + +if (x[1] !== Number.POSITIVE_INFINITY) { + throw new Test262Error('#5: x = []; x[0] = 0; x.unshift(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); x[1] === Number.POSITIVE_INFINITY. Actual: ' + (x[1])); +} + +if (x[2] !== "NaN") { + throw new Test262Error('#6: x = []; x[0] = 0; x.unshift(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); x[2] === "NaN". Actual: ' + (x[2])); +} + +if (x[3] !== "1") { + throw new Test262Error('#7: x = []; x[0] = 0; x.unshift(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); x[3] === "1". Actual: ' + (x[3])); +} + +if (x[4] !== -1) { + throw new Test262Error('#8: x = []; x[0] = 0; x.unshift(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); x[4] === -1. Actual: ' + (x[4])); +} + +if (x.length !== 6) { + throw new Test262Error('#9: x = []; x[0] = 0; x.unshift(true, Number.POSITIVE_INFINITY, "NaN", "1", -1); x.length === 6. Actual: ' + (x.length)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A2_T1.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A2_T1.js new file mode 100644 index 0000000000..272764f70d --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A2_T1.js @@ -0,0 +1,61 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The unshift function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.unshift +description: > + The arguments are prepended to the start of the array, such that + their order within the array is the same as the order in which + they appear in the argument list +---*/ + +var obj = {}; +obj.unshift = Array.prototype.unshift; + +if (obj.length !== undefined) { + throw new Test262Error('#0: var obj = {}; obj.length === undefined. Actual: ' + (obj.length)); +} else { + var unshift = obj.unshift(-1); + if (unshift !== 1) { + throw new Test262Error('#1: var obj = {}; obj.unshift = Array.prototype.unshift; obj.unshift(-1) === 1. Actual: ' + (unshift)); + } + if (obj.length !== 1) { + throw new Test262Error('#2: var obj = {}; obj.unshift = Array.prototype.unshift; obj.unshift(-1); obj.length === 1. Actual: ' + (obj.length)); + } + if (obj["0"] !== -1) { + throw new Test262Error('#3: var obj = {}; obj.unshift = Array.prototype.unshift; obj.unshift(-1); obj["0"] === -1. Actual: ' + (obj["0"])); + } +} + +obj.length = undefined; +var unshift = obj.unshift(-4); +if (unshift !== 1) { + throw new Test262Error('#4: var obj = {}; obj.length = undefined; obj.unshift = Array.prototype.unshift; obj.unshift(-4) === 1. Actual: ' + (unshift)); +} + +if (obj.length !== 1) { + throw new Test262Error('#5: var obj = {}; obj.length = undefined; obj.unshift = Array.prototype.unshift; obj.unshift(-4); obj.length === 1. Actual: ' + (obj.length)); +} + +if (obj["0"] !== -4) { + throw new Test262Error('#6: var obj = {}; obj.length = undefined; obj.unshift = Array.prototype.unshift; obj.unshift(-4); obj["0"] === -4. Actual: ' + (obj["0"])); +} + +obj.length = null +var unshift = obj.unshift(-7); +if (unshift !== 1) { + throw new Test262Error('#7: var obj = {}; obj.length = null; obj.unshift = Array.prototype.unshift; obj.unshift(-7) === 1. Actual: ' + (unshift)); +} + +if (obj.length !== 1) { + throw new Test262Error('#8: var obj = {}; obj.length = null; obj.unshift = Array.prototype.unshift; obj.unshift(-7); obj.length === 1. Actual: ' + (obj.length)); +} + +if (obj["0"] !== -7) { + throw new Test262Error('#9: var obj = {}; obj.length = null; obj.unshift = Array.prototype.unshift; obj.unshift(-7); obj["0"] === -7. Actual: ' + (obj["0"])); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A2_T2.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A2_T2.js new file mode 100644 index 0000000000..152ab6e247 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A2_T2.js @@ -0,0 +1,88 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The unshift function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.unshift +description: > + The arguments are prepended to the start of the array, such that + their order within the array is the same as the order in which + they appear in the argument list +---*/ + +var obj = {}; +obj.unshift = Array.prototype.unshift; + +obj.length = NaN; +var unshift = obj.unshift(-1); +if (unshift !== 1) { + throw new Test262Error('#1: var obj = {}; obj.length = NaN; obj.unshift = Array.prototype.unshift; obj.unshift(-1) === 1. Actual: ' + (unshift)); +} + +if (obj.length !== 1) { + throw new Test262Error('#2: var obj = {}; obj.length = NaN; obj.unshift = Array.prototype.unshift; obj.unshift(-1); obj.length === 1. Actual: ' + (obj.length)); +} + +if (obj["0"] !== -1) { + throw new Test262Error('#3: var obj = {}; obj.length = NaN; obj.unshift = Array.prototype.unshift; obj.unshift(-1); obj["0"] === -1. Actual: ' + (obj["0"])); +} + +obj.length = Number.NEGATIVE_INFINITY; +var unshift = obj.unshift(-7); +if (unshift !== 1) { + throw new Test262Error('#7: var obj = {}; obj.length = Number.NEGATIVE_INFINITY; obj.unshift = Array.prototype.unshift; obj.unshift(-7) === 1. Actual: ' + (unshift)); +} + +if (obj.length !== 1) { + throw new Test262Error('#8: var obj = {}; obj.length = Number.NEGATIVE_INFINITY; obj.unshift = Array.prototype.unshift; obj.unshift(-7); obj.length === 1. Actual: ' + (obj.length)); +} + +if (obj["0"] !== -7) { + throw new Test262Error('#9: var obj = {}; obj.length = Number.NEGATIVE_INFINITY; obj.unshift = Array.prototype.unshift; obj.unshift(-7); obj["0"] === -7. Actual: ' + (obj["0"])); +} + +obj.length = 0.5; +var unshift = obj.unshift(-10); +if (unshift !== 1) { + throw new Test262Error('#10: var obj = {}; obj.length = 0.5; obj.unshift = Array.prototype.unshift; obj.unshift(-10) === 1. Actual: ' + (unshift)); +} + +if (obj.length !== 1) { + throw new Test262Error('#11: var obj = {}; obj.length = 0.5; obj.unshift = Array.prototype.unshift; obj.unshift(-10); obj.length === 1. Actual: ' + (obj.length)); +} + +if (obj["0"] !== -10) { + throw new Test262Error('#12: var obj = {}; obj.length = 0.5; obj.unshift = Array.prototype.unshift; obj.unshift(-10); obj["0"] === -10. Actual: ' + (obj["0"])); +} + +obj.length = 1.5; +var unshift = obj.unshift(-13); +if (unshift !== 2) { + throw new Test262Error('#13: var obj = {}; obj.length = 1.5; obj.unshift = Array.prototype.unshift; obj.unshift(-13) === 2. Actual: ' + (unshift)); +} + +if (obj.length !== 2) { + throw new Test262Error('#14: var obj = {}; obj.length = 1.5; obj.unshift = Array.prototype.unshift; obj.unshift(-13); obj.length === 2. Actual: ' + (obj.length)); +} + +if (obj["0"] !== -13) { + throw new Test262Error('#15: var obj = {}; obj.length = 1.5; obj.unshift = Array.prototype.unshift; obj.unshift(-13); obj["0"] === -13. Actual: ' + (obj["0"])); +} + +obj.length = new Number(0); +var unshift = obj.unshift(-16); +if (unshift !== 1) { + throw new Test262Error('#16: var obj = {}; obj.length = new Number(0); obj.unshift = Array.prototype.unshift; obj.unshift(-16) === 1. Actual: ' + (unshift)); +} + +if (obj.length !== 1) { + throw new Test262Error('#17: var obj = {}; obj.length = new Number(0); obj.unshift = Array.prototype.unshift; obj.unshift(-16); obj.length === 1. Actual: ' + (obj.length)); +} + +if (obj["0"] !== -16) { + throw new Test262Error('#18: var obj = {}; obj.length = new Number(0); obj.unshift = Array.prototype.unshift; obj.unshift(-16); obj["0"] === -16. Actual: ' + (obj["0"])); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A2_T3.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A2_T3.js new file mode 100644 index 0000000000..8979724e9b --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A2_T3.js @@ -0,0 +1,120 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The unshift function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.unshift +description: > + Operator use ToNumber from length. If Type(value) is Object, + evaluate ToPrimitive(value, Number) +---*/ + +var obj = {}; +obj.unshift = Array.prototype.unshift; + +obj.length = { + valueOf() { + return 3 + } +}; +var unshift = obj.unshift(); +assert.sameValue(unshift, 3, 'The value of unshift is expected to be 3'); + +obj.length = { + valueOf() { + return 3 + }, + toString() { + return 1 + } +}; +var unshift = obj.unshift(); +assert.sameValue(unshift, 3, 'The value of unshift is expected to be 3'); + +obj.length = { + valueOf() { + return 3 + }, + toString() { + return {} + } +}; +var unshift = obj.unshift(); +assert.sameValue(unshift, 3, 'The value of unshift is expected to be 3'); + +try { + obj.length = { + valueOf() { + return 3 + }, + toString() { + throw "error" + } + }; + var unshift = obj.unshift(); + assert.sameValue(unshift, 3, 'The value of unshift is expected to be 3'); +} +catch (e) { + assert.notSameValue(e, "error", 'The value of e is not "error"'); +} + +obj.length = { + toString() { + return 1 + } +}; +var unshift = obj.unshift(); +assert.sameValue(unshift, 1, 'The value of unshift is expected to be 1'); + +obj.length = { + valueOf() { + return {} + }, + toString() { + return 1 + } +} +var unshift = obj.unshift(); +assert.sameValue(unshift, 1, 'The value of unshift is expected to be 1'); + +try { + + obj.length = { + valueOf() { + throw "error" + }, + toString() { + return 1 + } + }; + var unshift = obj.unshift(); + throw new Test262Error('#7.1: obj.length = {valueOf() {throw "error"}, toString() {return 1}}; obj.unshift() throw "error". Actual: ' + (unshift)); +} +catch (e) { + assert.sameValue(e, "error", 'The value of e is expected to be "error"'); +} + +try { + + obj.length = { + valueOf() { + return {} + }, + toString() { + return {} + } + }; + var unshift = obj.unshift(); + throw new Test262Error('#8.1: obj.length = {valueOf() {return {}}, toString() {return {}}} obj.unshift() throw TypeError. Actual: ' + (unshift)); +} +catch (e) { + assert.sameValue( + e instanceof TypeError, + true, + 'The result of evaluating (e instanceof TypeError) is expected to be true' + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A3_T2.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A3_T2.js new file mode 100644 index 0000000000..1634da4c16 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A3_T2.js @@ -0,0 +1,40 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Check ToLength(length) for non Array objects +esid: sec-array.prototype.unshift +description: length = -4294967295 +---*/ + +var obj = {}; +obj.unshift = Array.prototype.unshift; +obj[0] = ""; +obj.length = -4294967295; + +var unshift = obj.unshift("x", "y", "z"); +if (unshift !== 3) { + throw new Test262Error('#1: var obj = {}; obj.unshift = Array.prototype.unshift; obj[0] = ""; obj.length = -4294967295; obj.unshift("x", "y", "z") === 3. Actual: ' + (unshift)); +} + +if (obj.length !== 3) { + throw new Test262Error('#2: var obj = {}; obj.unshift = Array.prototype.unshift; obj[0] = ""; obj.length = -4294967295; obj.unshift("x", "y", "z"); obj.length === 3. Actual: ' + (obj.length)); +} + +if (obj[0] !== "x") { + throw new Test262Error('#3: var obj = {}; obj.unshift = Array.prototype.unshift; obj[0] = ""; obj.length = -4294967295; obj.unshift("x", "y", "z"); obj[0] === "x". Actual: ' + (obj[0])); +} + +if (obj[1] !== "y") { + throw new Test262Error('#4: var obj = {}; obj.unshift = Array.prototype.unshift; obj[0] = ""; obj.length = -4294967295; obj.unshift("x", "y", "z"); obj[1] === "y". Actual: ' + (obj[1])); +} + +if (obj[2] !== "z") { + throw new Test262Error('#5: var obj = {}; obj.unshift = Array.prototype.unshift; obj[0] = ""; obj.length = -4294967295; obj.unshift("x", "y", "z"); obj[2] === "z". Actual: ' + (obj[2])); +} + +if (obj[3] !== undefined) { + throw new Test262Error('#6: var obj = {}; obj.unshift = Array.prototype.unshift; obj[0] = ""; obj.length = -4294967295; obj.unshift("x", "y", "z"); obj[3] === undefined. Actual: ' + (obj[3])); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A4_T1.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A4_T1.js new file mode 100644 index 0000000000..fb0cdeb78e --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A4_T1.js @@ -0,0 +1,70 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: "[[Get]], [[Delete]] from not an inherited property" +esid: sec-array.prototype.unshift +description: > + [[Prototype]] of Array instance is Array.prototype, [[Prototype] + of Array.prototype is Object.prototype +---*/ + +Array.prototype[0] = -1; +var x = [1]; +x.length = 1; + +var unshift = x.unshift(0); +if (unshift !== 2) { + throw new Test262Error('#1: Array.prototype[0] = -1; x = [1]; x.length = 1; x.unshift(0) === 2. Actual: ' + (unshift)); +} + +if (x[0] !== 0) { + throw new Test262Error('#2: Array.prototype[0] = -1; x = [1]; x.length = 1; x.unshift(0); x[0] === 0. Actual: ' + (x[0])); +} + +if (x[1] !== 1) { + throw new Test262Error('#3: Array.prototype[0] = -1; x = [1]; x.length = 1; x.unshift(0); x[1] === 1. Actual: ' + (x[1])); +} + +delete x[0]; + +if (x[0] !== -1) { + throw new Test262Error('#4: Array.prototype[0] = -1; x = [1]; x.length = 1; x.unshift(0); delete x[0]; x[0] === -1. Actual: ' + (x[0])); +} + +Object.prototype[0] = -1; +Object.prototype.length = 1; +Object.prototype.unshift = Array.prototype.unshift; +x = { + 0: 1 +}; + +var unshift = x.unshift(0); +if (unshift !== 2) { + throw new Test262Error('#5: Object.prototype[0] = -1; Object.prototype.length = 1; Object.prototype.unshift = Array.prototype.unshift; x = {0:0}; x.unshift(0) === 2. Actual: ' + (unshift)); +} + +if (x[0] !== 0) { + throw new Test262Error('#6: Object.prototype[0] = -1; Object.prototype.length = 1; Object.prototype.unshift = Array.prototype.unshift; x = {0:0}; x.unshift(0); x[0] === 0. Actual: ' + (x[0])); +} + +if (x[1] !== 1) { + throw new Test262Error('#7: Object.prototype[0] = -1; Object.prototype.length = 1; Object.prototype.unshift = Array.prototype.unshift; x = {0:0}; x.unshift(0); x[1] === 1. Actual: ' + (x[1])); +} + +delete x[0]; + +if (x[0] !== -1) { + throw new Test262Error('#8: Object.prototype[0] = -1; Object.prototype.length = 1; Object.prototype.unshift = Array.prototype.unshift; x = {0:0}; x.unshift(0); delete x[0]; x[0] === -1. Actual: ' + (x[0])); +} + +if (x.length !== 2) { + throw new Test262Error('#9: Object.prototype[0] = -1; Object.prototype.length = 1; Object.prototype.unshift = Array.prototype.unshift; x = {0:0}; x.unshift(0); x.length === 1. Actual: ' + (x.length)); +} + +delete x.length; +if (x.length !== 1) { + throw new Test262Error('#10: Object.prototype[1] = -1; Object.prototype.length = 1; Object.prototype.unshift = Array.prototype.unshift; x = {0:0}; x.unshift(0); delete x; x.length === 1. Actual: ' + (x.length)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A4_T2.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A4_T2.js new file mode 100644 index 0000000000..bc63e8cf66 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/S15.4.4.13_A4_T2.js @@ -0,0 +1,68 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: "[[Get]], [[Delete]] from not an inherited property" +esid: sec-array.prototype.unshift +description: > + [[Prototype]] of Array instance is Array.prototype, [[Prototype] + of Array.prototype is Object.prototype +---*/ + +Array.prototype[0] = 1; +var x = []; +x.length = 1; + +var unshift = x.unshift(0); +if (unshift !== 2) { + throw new Test262Error('#1: Array.prototype[0] = 1; x = []; x.length = 1; x.unshift(0) === 2. Actual: ' + (unshift)); +} + +if (x[0] !== 0) { + throw new Test262Error('#2: Array.prototype[0] = 1; x = []; x.length = 1; x.unshift(0); x[0] === 0. Actual: ' + (x[0])); +} + +if (x[1] !== 1) { + throw new Test262Error('#3: Array.prototype[0] = 1; x = []; x.length = 1; x.unshift(0); x[1] === 1. Actual: ' + (x[1])); +} + +delete x[0]; + +if (x[0] !== 1) { + throw new Test262Error('#4: Array.prototype[0] = 1; x = [1]; x.length = 1; x.unshift(0); delete x[0]; x[0] === 1. Actual: ' + (x[0])); +} + +Object.prototype[0] = 1; +Object.prototype.length = 1; +Object.prototype.unshift = Array.prototype.unshift; +x = {}; + +var unshift = x.unshift(0); +if (unshift !== 2) { + throw new Test262Error('#5: Object.prototype[0] = 1; Object.prototype.length = 1; Object.prototype.unshift = Array.prototype.unshift; x = {}; x.unshift(0) === 2. Actual: ' + (unshift)); +} + +if (x[0] !== 0) { + throw new Test262Error('#6: Object.prototype[0] = 1; Object.prototype.length = 1; Object.prototype.unshift = Array.prototype.unshift; x = {}; x.unshift(0); x[0] === 0. Actual: ' + (x[0])); +} + +if (x[1] !== 1) { + throw new Test262Error('#7: Object.prototype[0] = 1; Object.prototype.length = 1; Object.prototype.unshift = Array.prototype.unshift; x = {}; x.unshift(0); x[1] === 1. Actual: ' + (x[1])); +} + +delete x[0]; + +if (x[0] !== 1) { + throw new Test262Error('#8: Object.prototype[0] = 1; Object.prototype.length = 1; Object.prototype.unshift = Array.prototype.unshift; x = {}; x.unshift(0); delete x[0]; x[0] === 1. Actual: ' + (x[0])); +} + +if (x.length !== 2) { + throw new Test262Error('#9: Object.prototype[0] = 1; Object.prototype.length = 1; Object.prototype.unshift = Array.prototype.unshift; x = {}; x.unshift(0); x.length === 1. Actual: ' + (x.length)); +} + +delete x.length; +if (x.length !== 1) { + throw new Test262Error('#10: Object.prototype[1] = 1; Object.prototype.length = 1; Object.prototype.unshift = Array.prototype.unshift; x = {}; x.unshift(0); delete x; x.length === 1. Actual: ' + (x.length)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/browser.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/browser.js diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/call-with-boolean.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/call-with-boolean.js new file mode 100644 index 0000000000..1d01b147ec --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/call-with-boolean.js @@ -0,0 +1,12 @@ +// 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.unshift +description: Array.prototype.unshift applied to boolean primitive +---*/ + +assert.sameValue(Array.prototype.unshift.call(true), 0, 'Array.prototype.unshift.call(true) must return 0'); +assert.sameValue(Array.prototype.unshift.call(false), 0, 'Array.prototype.unshift.call(false) must return 0'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/clamps-to-integer-limit.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/clamps-to-integer-limit.js new file mode 100644 index 0000000000..82c3056f5e --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/clamps-to-integer-limit.js @@ -0,0 +1,35 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.unshift +description: > + Length values exceeding 2^53-1 are clamped to 2^53-1. +info: | + 1. ... + 2. Let len be ? ToLength(? Get(O, "length")). + 3. Let argCount be the number of actual arguments. + 4. If argCount > 0, then ... + 5. Perform ? Set(O, "length", len+argCount, true). +features: [exponentiation] +---*/ + +var arrayLike = {}; + +arrayLike.length = 2 ** 53 - 1; +Array.prototype.unshift.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 1, "Length is 2**53 - 1"); + +arrayLike.length = 2 ** 53; +Array.prototype.unshift.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 1, "Length is 2**53"); + +arrayLike.length = 2 ** 53 + 2; +Array.prototype.unshift.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 1, "Length is 2**53 + 2"); + +arrayLike.length = Infinity; +Array.prototype.unshift.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 1, "Length is Infinity"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/length-near-integer-limit.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/length-near-integer-limit.js new file mode 100644 index 0000000000..f73b36e447 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/length-near-integer-limit.js @@ -0,0 +1,63 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.unshift +description: > + Test properties are correctly accessed when length property is near 2^53-1. +info: | + 2. Let len be ? ToLength(? Get(O, "length")). + 3. Let argCount be the number of actual arguments. + 4. If argCount > 0, then + ... + b. Let k be len. + c. Repeat, while k > 0, + i. Let from be ! ToString(k-1). + ii. Let to be ! ToString(k+argCount-1). + iii. Let fromPresent be ? HasProperty(O, from). + iv. If fromPresent is true, then + 1. Let fromValue be ? Get(O, from). + 2. Perform ? Set(O, to, fromValue, true). + v. Else fromPresent is false, + 1. Perform ? DeletePropertyOrThrow(O, to). + vi. Decrease k by 1. +features: [exponentiation] +---*/ + +function StopUnshift() {} + +var arrayLike = { + get "9007199254740986" () { + throw new StopUnshift(); + }, + "9007199254740987": "9007199254740987", + /* "9007199254740988": hole */ + "9007199254740989": "9007199254740989", + /* "9007199254740990": empty */ + "9007199254740991": "9007199254740991", + length: 2 ** 53 - 2 +}; + +assert.throws(StopUnshift, function() { + Array.prototype.unshift.call(arrayLike, null); +}); + +assert.sameValue(arrayLike.length, 2 ** 53 - 2, + "arrayLike.length is unchanged"); + +assert.sameValue(arrayLike["9007199254740987"], "9007199254740987", + "arrayLike['9007199254740987'] is unchanged"); + +assert.sameValue(arrayLike["9007199254740988"], "9007199254740987", + "arrayLike['9007199254740988'] is replaced with arrayLike['9007199254740987']"); + +assert.sameValue("9007199254740989" in arrayLike, false, + "arrayLike['9007199254740989'] is removed"); + +assert.sameValue(arrayLike["9007199254740990"], "9007199254740989", + "arrayLike['9007199254740990'] is replaced with arrayLike['9007199254740989']"); + +assert.sameValue(arrayLike["9007199254740991"], "9007199254740991", + "arrayLike['9007199254740991'] is unchanged"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/length.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/length.js new file mode 100644 index 0000000000..e99bffa6d8 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/length.js @@ -0,0 +1,34 @@ +// Copyright (C) 2017 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.unshift +description: > + The "length" property of Array.prototype.unshift +info: | + 22.1.3.29 Array.prototype.unshift ( ...items ) + + The length property of the unshift method is 1. + + 17 ECMAScript Standard Built-in Objects + + Every built-in function object, including constructors, has a length property + whose value is an integer. Unless otherwise specified, this value is equal to + the largest number of named arguments shown in the subclause headings for the + function description. Optional parameters (which are indicated with brackets: + [ ]) or rest parameters (which are shown using the form «...name») are not + included in the default argument count. + + Unless otherwise specified, the length property of a built-in function object + has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Array.prototype.unshift.length, 1); + +verifyNotEnumerable(Array.prototype.unshift, 'length'); +verifyNotWritable(Array.prototype.unshift, 'length'); +verifyConfigurable(Array.prototype.unshift, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/name.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/name.js new file mode 100644 index 0000000000..4caa8c29b4 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.unshift +description: > + Array.prototype.unshift.name is "unshift". +info: | + Array.prototype.unshift ( ...items ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Array.prototype.unshift.name, "unshift"); + +verifyNotEnumerable(Array.prototype.unshift, "name"); +verifyNotWritable(Array.prototype.unshift, "name"); +verifyConfigurable(Array.prototype.unshift, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/not-a-constructor.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/not-a-constructor.js new file mode 100644 index 0000000000..415a6e738d --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/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.unshift 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.unshift), + false, + 'isConstructor(Array.prototype.unshift) must return false' +); + +assert.throws(TypeError, () => { + new Array.prototype.unshift(); +}, '`new Array.prototype.unshift()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/prop-desc.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/prop-desc.js new file mode 100644 index 0000000000..6eee7edd19 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/prop-desc.js @@ -0,0 +1,23 @@ +// Copyright (C) 2017 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.unshift +description: > + "unshift" property of Array.prototype +info: | + 17 ECMAScript Standard Built-in Objects + + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(typeof Array.prototype.unshift, 'function', 'typeof'); + +verifyNotEnumerable(Array.prototype, "unshift"); +verifyWritable(Array.prototype, "unshift"); +verifyConfigurable(Array.prototype, "unshift"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/set-length-array-is-frozen.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/set-length-array-is-frozen.js new file mode 100644 index 0000000000..912e021aaa --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/set-length-array-is-frozen.js @@ -0,0 +1,50 @@ +// Copyright (C) 2022 Apple Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.unshift +description: > + A TypeError is thrown when "length" is [[Set]] on a frozen array. +info: | + Array.prototype.unshift ( ...items ) + + [...] + 4. If argCount > 0, then + [...] + d. Let j be +0𝔽. + e. For each element E of items, do + i. Perform ? Set(O, ! ToString(j), E, true). + ii. Set j to j + 1𝔽. + 5. Perform ? Set(O, "length", 𝔽(len + argCount), true). + + OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ) + + [...] + 2. If IsDataDescriptor(ownDesc) is true, then + a. If ownDesc.[[Writable]] is false, return false. + + Set ( O, P, V, Throw ) + + [...] + 1. Let success be ? O.[[Set]](P, V, O). + 2. If success is false and Throw is true, throw a TypeError exception. +---*/ + +var array = []; +var arrayPrototypeSet0Calls = 0; + +Object.defineProperty(Array.prototype, "0", { + set(_val) { + Object.freeze(array); + arrayPrototypeSet0Calls++; + }, +}); + +assert.throws(TypeError, function() { + array.unshift(1); +}); + +assert(!array.hasOwnProperty(0)); +assert.sameValue(array.length, 0); +assert.sameValue(arrayPrototypeSet0Calls, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/set-length-array-length-is-non-writable.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/set-length-array-length-is-non-writable.js new file mode 100644 index 0000000000..9ce38b5d93 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/set-length-array-length-is-non-writable.js @@ -0,0 +1,50 @@ +// Copyright (C) 2022 Apple Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.unshift +description: > + A TypeError is thrown when "length" is [[Set]] on an array with non-writable "length". +info: | + Array.prototype.unshift ( ...items ) + + [...] + 4. If argCount > 0, then + [...] + d. Let j be +0𝔽. + e. For each element E of items, do + i. Perform ? Set(O, ! ToString(j), E, true). + ii. Set j to j + 1𝔽. + 5. Perform ? Set(O, "length", 𝔽(len + argCount), true). + + OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ) + + [...] + 2. If IsDataDescriptor(ownDesc) is true, then + a. If ownDesc.[[Writable]] is false, return false. + + Set ( O, P, V, Throw ) + + [...] + 1. Let success be ? O.[[Set]](P, V, O). + 2. If success is false and Throw is true, throw a TypeError exception. +---*/ + +var array = []; +var arrayPrototypeSet0Calls = 0; + +Object.defineProperty(Array.prototype, "0", { + set(_val) { + Object.defineProperty(array, "length", { writable: false }); + arrayPrototypeSet0Calls++; + }, +}); + +assert.throws(TypeError, function() { + array.unshift(1); +}); + +assert(!array.hasOwnProperty(0)); +assert.sameValue(array.length, 0); +assert.sameValue(arrayPrototypeSet0Calls, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/set-length-zero-array-is-frozen.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/set-length-zero-array-is-frozen.js new file mode 100644 index 0000000000..0896cb8a25 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/set-length-zero-array-is-frozen.js @@ -0,0 +1,38 @@ +// Copyright (C) 2022 Apple Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.unshift +description: > + A TypeError is thrown when "length" is [[Set]] on an empty frozen array. +info: | + Array.prototype.unshift ( ...items ) + + [...] + 2. Let len be ? LengthOfArrayLike(O). + [...] + 5. Perform ? Set(O, "length", 𝔽(len + argCount), true). + + OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ) + + [...] + 2. If IsDataDescriptor(ownDesc) is true, then + a. If ownDesc.[[Writable]] is false, return false. + + Set ( O, P, V, Throw ) + + [...] + 1. Let success be ? O.[[Set]](P, V, O). + 2. If success is false and Throw is true, throw a TypeError exception. +---*/ + +var array = []; +Object.freeze(array); + +assert.throws(TypeError, function() { + array.unshift(); +}); + +assert(!array.hasOwnProperty(0)); +assert.sameValue(array.length, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/set-length-zero-array-length-is-non-writable.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/set-length-zero-array-length-is-non-writable.js new file mode 100644 index 0000000000..c6fa486c03 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/set-length-zero-array-length-is-non-writable.js @@ -0,0 +1,38 @@ +// Copyright (C) 2022 Apple Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.unshift +description: > + A TypeError is thrown when "length" is [[Set]] on an empty array with non-writable "length". +info: | + Array.prototype.unshift ( ...items ) + + [...] + 2. Let len be ? LengthOfArrayLike(O). + [...] + 5. Perform ? Set(O, "length", 𝔽(len + argCount), true). + + OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc ) + + [...] + 2. If IsDataDescriptor(ownDesc) is true, then + a. If ownDesc.[[Writable]] is false, return false. + + Set ( O, P, V, Throw ) + + [...] + 1. Let success be ? O.[[Set]](P, V, O). + 2. If success is false and Throw is true, throw a TypeError exception. +---*/ + +var array = []; +Object.defineProperty(array, "length", { writable: false }); + +assert.throws(TypeError, function() { + array.unshift(); +}); + +assert(!array.hasOwnProperty(0)); +assert.sameValue(array.length, 0); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/shell.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/shell.js diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/throws-if-integer-limit-exceeded.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/throws-if-integer-limit-exceeded.js new file mode 100644 index 0000000000..0e9ceada82 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/throws-if-integer-limit-exceeded.js @@ -0,0 +1,40 @@ +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.unshift +description: > + A TypeError is thrown if the new length exceeds 2^53-1. +info: | + 1. ... + 2. Let len be ? ToLength(? Get(O, "length")). + 3. Let argCount be the number of actual arguments. + 4. If argCount > 0, then + a. If len+argCount > 2^53-1, throw a TypeError exception. + b. ... +features: [exponentiation] +---*/ + +var arrayLike = {}; + +arrayLike.length = 2 ** 53 - 1; +assert.throws(TypeError, function() { + Array.prototype.unshift.call(arrayLike, null); +}, "Length is 2**53 - 1"); + +arrayLike.length = 2 ** 53; +assert.throws(TypeError, function() { + Array.prototype.unshift.call(arrayLike, null); +}, "Length is 2**53"); + +arrayLike.length = 2 ** 53 + 2; +assert.throws(TypeError, function() { + Array.prototype.unshift.call(arrayLike, null); +}, "Length is 2**53 + 2"); + +arrayLike.length = Infinity; +assert.throws(TypeError, function() { + Array.prototype.unshift.call(arrayLike, null); +}, "Length is Infinity"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/unshift/throws-with-string-receiver.js b/js/src/tests/test262/built-ins/Array/prototype/unshift/throws-with-string-receiver.js new file mode 100644 index 0000000000..7db1e088fd --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/unshift/throws-with-string-receiver.js @@ -0,0 +1,47 @@ +// Copyright (C) 2020 Sony Interactive Entertainment Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-array.prototype.unshift +description: > + Array#unshift throws TypeError upon attempting to modify a string +info: | + Array.prototype.unshift ( ...items ) + ... + 4. If argCount > 0, then + ... + c. Repeat, while k > 0, + ... + iv. If fromPresent is true, then + ... + 2. Perform ? Set(O, to, fromValue, true). + ... + ... + f. Repeat, while items is not empty + ... + Perform ? Set(O, ! ToString(j), E, true). + ... + 5. Perform ? Set(O, "length", len + argCount, true). + + Set ( O, P, V, Throw ) + ... + 4. Let success be ? O.[[Set]](P, V, O). + 5. If success is false and Throw is true, throw a TypeError exception. +---*/ + +assert.throws(TypeError, () => { + Array.prototype.unshift.call(''); +}, "Array.prototype.unshift.call('')"); + +assert.throws(TypeError, () => { + Array.prototype.unshift.call('', 1); +}, "Array.prototype.unshift.call('', 1)"); + +assert.throws(TypeError, () => { + Array.prototype.unshift.call('abc'); +}, "Array.prototype.unshift.call('abc')"); + +assert.throws(TypeError, () => { + Array.prototype.unshift.call('abc', 1); +}, "Array.prototype.unshift.call('abc', 1)"); + +reportCompare(0, 0); |