diff options
Diffstat (limited to 'js/src/tests/test262/built-ins/Array/prototype/shift')
22 files changed, 905 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A1.1_T1.js b/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A1.1_T1.js new file mode 100644 index 0000000000..1f70e9b735 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A1.1_T1.js @@ -0,0 +1,33 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If length equal zero, call the [[Put]] method of this object + with arguments "length" and 0 and return undefined +esid: sec-array.prototype.shift +description: Checking this algorithm +---*/ + +var x = new Array(); +var shift = x.shift(); +if (shift !== undefined) { + throw new Test262Error('#1: var x = new Array(); x.shift() === undefined. Actual: ' + (shift)); +} + +if (x.length !== 0) { + throw new Test262Error('#2: var x = new Array(); x.shift(); x.length === 0. Actual: ' + (x.length)); +} + +var x = Array(1, 2, 3); +x.length = 0; +var shift = x.shift(); +if (shift !== undefined) { + throw new Test262Error('#2: var x = Array(1,2,3); x.length = 0; x.shift() === undefined. Actual: ' + (shift)); +} + +if (x.length !== 0) { + throw new Test262Error('#4: var x = new Array(1,2,3); x.length = 0; x.shift(); x.length === 0. Actual: ' + (x.length)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A1.2_T1.js b/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A1.2_T1.js new file mode 100644 index 0000000000..a0e9c13392 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A1.2_T1.js @@ -0,0 +1,60 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The first element of the array is removed from the array and + returned +esid: sec-array.prototype.shift +description: Checking this use new Array() and [] +---*/ + +var x = new Array(0, 1, 2, 3); +var shift = x.shift(); +if (shift !== 0) { + throw new Test262Error('#1: x = new Array(0,1,2,3); x.shift() === 0. Actual: ' + (shift)); +} + +if (x.length !== 3) { + throw new Test262Error('#2: x = new Array(0,1,2,3); x.shift(); x.length == 3'); +} + +if (x[0] !== 1) { + throw new Test262Error('#3: x = new Array(0,1,2,3); x.shift(); x[0] == 1'); +} + +if (x[1] !== 2) { + throw new Test262Error('#4: x = new Array(0,1,2,3); x.shift(); x[1] == 2'); +} + +x = []; +x[0] = 0; +x[3] = 3; +var shift = x.shift(); +if (shift !== 0) { + throw new Test262Error('#5: x = []; x[0] = 0; x[3] = 3; x.shift() === 0. Actual: ' + (shift)); +} + +if (x.length !== 3) { + throw new Test262Error('#6: x = []; x[0] = 0; x[3] = 3; x.shift(); x.length == 3'); +} + +if (x[0] !== undefined) { + throw new Test262Error('#7: x = []; x[0] = 0; x[3] = 3; x.shift(); x[0] == undefined'); +} + +if (x[12] !== undefined) { + throw new Test262Error('#8: x = []; x[0] = 0; x[3] = 3; x.shift(); x[1] == undefined'); +} + +x.length = 1; +var shift = x.shift(); +if (shift !== undefined) { + throw new Test262Error('#9: x = []; x[0] = 0; x[3] = 3; x.shift(); x.length = 1; x.shift() === undefined. Actual: ' + (shift)); +} + +if (x.length !== 0) { + throw new Test262Error('#10: x = []; x[0] = 0; x[3] = 3; x.shift(); x.length = 1; x.shift(); x.length === 0. Actual: ' + (x.length)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A2_T1.js b/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A2_T1.js new file mode 100644 index 0000000000..29f2f4f311 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A2_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 shift function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.shift +description: > + If ToUint32(length) equal zero, call the [[Put]] method of this + object with arguments "length" and 0 and return undefined +---*/ + +var obj = {}; +obj.shift = Array.prototype.shift; + +if (obj.length !== undefined) { + throw new Test262Error('#0: var obj = {}; obj.length === undefined. Actual: ' + (obj.length)); +} else { + var shift = obj.shift(); + if (shift !== undefined) { + throw new Test262Error('#1: var obj = {}; obj.shift = Array.prototype.shift; obj.shift() === undefined. Actual: ' + (shift)); + } + if (obj.length !== 0) { + throw new Test262Error('#2: var obj = {}; obj.shift = Array.prototype.shift; obj.shift(); obj.length === 0. Actual: ' + (obj.length)); + } +} + +obj.length = undefined; +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#3: var obj = {}; obj.length = undefined; obj.shift = Array.prototype.shift; obj.shift() === undefined. Actual: ' + (shift)); +} + +if (obj.length !== 0) { + throw new Test262Error('#4: var obj = {}; obj.length = undefined; obj.shift = Array.prototype.shift; obj.shift(); obj.length === 0. Actual: ' + (obj.length)); +} + +obj.length = null +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#5: var obj = {}; obj.length = null; obj.shift = Array.prototype.shift; obj.shift() === undefined. Actual: ' + (shift)); +} + +if (obj.length !== 0) { + throw new Test262Error('#6: var obj = {}; obj.length = null; obj.shift = Array.prototype.shift; obj.shift(); obj.length === 0. Actual: ' + (obj.length)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A2_T2.js b/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A2_T2.js new file mode 100644 index 0000000000..cbe2c18644 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A2_T2.js @@ -0,0 +1,71 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The shift function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.shift +description: > + If ToUint32(length) equal zero, call the [[Put]] method of this + object with arguments "length" and 0 and return undefined +---*/ + +var obj = {}; +obj.shift = Array.prototype.shift; + +obj.length = NaN; +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#1: var obj = {}; obj.length = NaN; obj.shift = Array.prototype.shift; obj.shift() === undefined. Actual: ' + (shift)); +} + +if (obj.length !== 0) { + throw new Test262Error('#2: var obj = {}; obj.length = NaN; obj.shift = Array.prototype.shift; obj.shift(); obj.length === 0. Actual: ' + (obj.length)); +} + +obj.length = Number.NEGATIVE_INFINITY; +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#5: var obj = {}; obj.length = Number.NEGATIVE_INFINITY; obj.shift = Array.prototype.shift; obj.shift() === undefined. Actual: ' + (shift)); +} + +if (obj.length !== 0) { + throw new Test262Error('#6: var obj = {}; obj.length = Number.NEGATIVE_INFINITY; obj.shift = Array.prototype.shift; obj.shift(); obj.length === 0. Actual: ' + (obj.length)); +} + +obj.length = -0; +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#7: var obj = {}; obj.length = -0; obj.shift = Array.prototype.shift; obj.shift() === undefined. Actual: ' + (shift)); +} + +if (obj.length !== 0) { + throw new Test262Error('#8: var obj = {}; obj.length = -0; obj.shift = Array.prototype.shift; obj.shift(); obj.length === 0. Actual: ' + (obj.length)); +} else { + if (1 / obj.length !== Number.POSITIVE_INFINITY) { + throw new Test262Error('#8: var obj = {}; obj.length = -0; obj.shift = Array.prototype.shift; obj.shift(); obj.length === +0. Actual: ' + (obj.length)); + } +} + +obj.length = 0.5; +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#9: var obj = {}; obj.length = 0.5; obj.shift = Array.prototype.shift; obj.shift() === undefined. Actual: ' + (shift)); +} + +if (obj.length !== 0) { + throw new Test262Error('#10: var obj = {}; obj.length = 0.5; obj.shift = Array.prototype.shift; obj.shift(); obj.length === 0. Actual: ' + (obj.length)); +} + +obj.length = new Number(0); +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#11: var obj = {}; obj.length = new Number(0); obj.shift = Array.prototype.shift; obj.shift() === undefined. Actual: ' + (shift)); +} + +if (obj.length !== 0) { + throw new Test262Error('#12: var obj = {}; obj.length = new Number(0); obj.shift = Array.prototype.shift; obj.shift(); obj.length === 0. Actual: ' + (obj.length)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A2_T3.js b/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A2_T3.js new file mode 100644 index 0000000000..13d371b6ee --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A2_T3.js @@ -0,0 +1,37 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The shift function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.shift +description: > + The first element of the array is removed from the array and + returned +---*/ + +var obj = {}; +obj.shift = Array.prototype.shift; + +obj.length = 2.5; +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#1: var obj = {}; obj.length = 2.5; obj.shift = Array.prototype.shift; obj.shift() === undefined. Actual: ' + (shift)); +} + +if (obj.length !== 1) { + throw new Test262Error('#2: var obj = {}; obj.length = 2.5; obj.shift = Array.prototype.shift; obj.shift(); obj.length === 1. Actual: ' + (obj.length)); +} + +obj.length = new Number(2); +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#11: var obj = {}; obj.length = new Number(2); obj.shift = Array.prototype.shift; obj.shift() === undefined. Actual: ' + (shift)); +} + +if (obj.length !== 1) { + throw new Test262Error('#12: var obj = {}; obj.length = new Number(2); obj.shift = Array.prototype.shift; obj.shift(); obj.length === 1. Actual: ' + (obj.length)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A2_T4.js b/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A2_T4.js new file mode 100644 index 0000000000..1f315396cd --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A2_T4.js @@ -0,0 +1,48 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The shift function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.shift +description: > + The first element of the array is removed from the array and + returned +---*/ + +var obj = {}; +obj["0"] = 0; +obj["3"] = 3; +obj.shift = Array.prototype.shift; + +obj.length = 4; +var shift = obj.shift(); +if (shift !== 0) { + throw new Test262Error('#1: var obj = {}; obj["0"] = 0; obj["3"] = 3; obj.length = 4; obj.shift = Array.prototype.shift; obj.shift() === 0. Actual: ' + (shift)); +} + +if (obj.length !== 3) { + throw new Test262Error('#2: var obj = {}; obj["0"] = 0; obj["3"] = 3; obj.length = 4; obj.shift = Array.prototype.shift; obj.shift(); obj.length === 3. Actual: ' + (obj.length)); +} + +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#3: var obj = {}; obj["0"] = 0; obj["3"] = 3; obj.length = 4; obj.shift = Array.prototype.shift; obj.shift(); obj.shift() === undefined. Actual: ' + (shift)); +} + +if (obj.length !== 2) { + throw new Test262Error('#4: var obj = {}; obj["0"] = 0; obj["3"] = 3; obj.length = 4; obj.shift = Array.prototype.shift; obj.shift(); obj.shift(); obj.length === 2. Actual: ' + (obj.length)); +} + +obj.length = 1; +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#5: var obj = {}; obj["0"] = 0; obj["3"] = 3; obj.length = 4; obj.shift = Array.prototype.shift; obj.shift(); obj.shift(); obj.length = 1; obj.shift() === undefined. Actual: ' + (shift)); +} + +if (obj.length !== 0) { + throw new Test262Error('#6: var obj = {}; obj["0"] = 0; obj["3"] = 3; obj.length = 4; obj.shift = Array.prototype.shift; obj.shift(); obj.shift(); obj.length = 1; obj.shift(); obj.length === 0. Actual: ' + (obj.length)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A2_T5.js b/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A2_T5.js new file mode 100644 index 0000000000..76b01bbe57 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A2_T5.js @@ -0,0 +1,126 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The shift function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.shift +description: > + Operator use ToNumber from length. If Type(value) is Object, + evaluate ToPrimitive(value, Number) +---*/ + +var obj = {}; +obj.shift = Array.prototype.shift; + +obj[0] = -1; +obj.length = { + valueOf() { + return 1 + } +}; +var shift = obj.shift(); +assert.sameValue(shift, -1, 'The value of shift is expected to be -1'); + +obj[0] = -1; +obj.length = { + valueOf() { + return 1 + }, + toString() { + return 0 + } +}; +var shift = obj.shift(); +assert.sameValue(shift, -1, 'The value of shift is expected to be -1'); + +obj[0] = -1; +obj.length = { + valueOf() { + return 1 + }, + toString() { + return {} + } +}; +var shift = obj.shift(); +assert.sameValue(shift, -1, 'The value of shift is expected to be -1'); + +try { + obj[0] = -1; + obj.length = { + valueOf() { + return 1 + }, + toString() { + throw "error" + } + }; + var shift = obj.shift(); + assert.sameValue(shift, -1, 'The value of shift is expected to be -1'); +} +catch (e) { + assert.notSameValue(e, "error", 'The value of e is not "error"'); +} + +obj[0] = -1; +obj.length = { + toString() { + return 0 + } +}; +var shift = obj.shift(); +assert.sameValue(shift, undefined, 'The value of shift is expected to equal undefined'); + +obj[0] = -1; +obj.length = { + valueOf() { + return {} + }, + toString() { + return 0 + } +} +var shift = obj.shift(); +assert.sameValue(shift, undefined, 'The value of shift is expected to equal undefined'); + +try { + obj[0] = -1; + obj.length = { + valueOf() { + throw "error" + }, + toString() { + return 0 + } + }; + var shift = obj.shift(); + throw new Test262Error('#7.1: obj[0] = -1; obj.length = {valueOf() {throw "error"}, toString() {return 0}}; obj.shift() throw "error". Actual: ' + (shift)); +} +catch (e) { + assert.sameValue(e, "error", 'The value of e is expected to be "error"'); +} + +try { + obj[0] = -1; + obj.length = { + valueOf() { + return {} + }, + toString() { + return {} + } + }; + var shift = obj.shift(); + throw new Test262Error('#8.1: obj[0] = -1; obj.length = {valueOf() {return {}}, toString() {return {}}} obj.shift() throw TypeError. Actual: ' + (shift)); +} +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/shift/S15.4.4.9_A3_T3.js b/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A3_T3.js new file mode 100644 index 0000000000..70d9a86cd0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A3_T3.js @@ -0,0 +1,33 @@ +// 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.shift +description: length is arbitrarily +---*/ + +var obj = {}; +obj.shift = Array.prototype.shift; +obj[0] = "x"; +obj[1] = "y"; +obj.length = -4294967294; + +var shift = obj.shift(); +if (shift !== undefined) { + throw new Test262Error('#1: var obj = {}; obj.shift = Array.prototype.shift; obj[0] = "x"; obj[1] = "y"; obj.length = -4294967294; obj.shift() === undefined. Actual: ' + (shift)); +} + +if (obj.length !== 0) { + throw new Test262Error('#2: var obj = {}; obj.shift = Array.prototype.shift; obj[0] = "x"; obj[1] = "y"; obj.length = -4294967294; obj.shift(); obj.length === 0. Actual: ' + (obj.length)); +} + +if (obj[0] !== "x") { + throw new Test262Error('#3: var obj = {}; obj.shift = Array.prototype.shift; obj[0] = "x"; obj[1] = "y"; obj.length = -4294967294; obj.shift(); obj[0] === "x". Actual: ' + (obj[0])); +} + +if (obj[1] !== "y") { + throw new Test262Error('#4: var obj = {}; obj.shift = Array.prototype.shift; obj[0] = "x" obj[1] = "y"; obj.length = -4294967294; obj.shift(); obj[1] === "y". Actual: ' + (obj[1])); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A4_T1.js b/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A4_T1.js new file mode 100644 index 0000000000..8865e88e73 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A4_T1.js @@ -0,0 +1,58 @@ +// 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.shift +description: > + [[Prototype]] of Array instance is Array.prototype, [[Prototype] + of Array.prototype is Object.prototype +---*/ + +Array.prototype[1] = 1; +var x = [0]; +x.length = 2; + +var shift = x.shift(); +if (shift !== 0) { + throw new Test262Error('#1: Array.prototype[1] = 1; x = [0]; x.length = 2; x.shift() === 0. Actual: ' + (shift)); +} + +if (x[0] !== 1) { + throw new Test262Error('#2: Array.prototype[1] = 1; x = [0]; x.length = 2; x.shift(); x[0] === 1. Actual: ' + (x[0])); +} + +if (x[1] !== 1) { + throw new Test262Error('#3: Array.prototype[1] = 1; x = [0]; x.length = 2; x.shift(); x[1] === 1. Actual: ' + (x[1])); +} + +Object.prototype[1] = 1; +Object.prototype.length = 2; +Object.prototype.shift = Array.prototype.shift; +x = { + 0: 0 +}; + +var shift = x.shift(); +if (shift !== 0) { + throw new Test262Error('#4: Object.prototype[1] = 1; Object.prototype.length = 2; Object.prototype.shift = Array.prototype.shift; x = {0:0}; x.shift() === 0. Actual: ' + (shift)); +} + +if (x[0] !== 1) { + throw new Test262Error('#5: Object.prototype[1] = 1; Object.prototype.length = 2; Object.prototype.shift = Array.prototype.shift; x = {0:0}; x.shift(); x[0] === 1. Actual: ' + (x[0])); +} + +if (x[1] !== 1) { + throw new Test262Error('#6: Object.prototype[1] = 1; Object.prototype.length = 2; Object.prototype.shift = Array.prototype.shift; x = {0:0}; x.shift(); x[1] === 1. Actual: ' + (x[1])); +} + +if (x.length !== 1) { + throw new Test262Error('#7: Object.prototype[1] = 1; Object.prototype.length = 2; Object.prototype.shift = Array.prototype.shift; x = {0:0}; x.shift(); x.length === 1. Actual: ' + (x.length)); +} + +delete x.length; +if (x.length !== 2) { + throw new Test262Error('#8: Object.prototype[1] = 1; Object.prototype.length = 2; Object.prototype.shift = Array.prototype.shift; x = {0:0}; x.shift(); delete x; x.length === 2. Actual: ' + (x.length)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A4_T2.js b/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A4_T2.js new file mode 100644 index 0000000000..def860e177 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/shift/S15.4.4.9_A4_T2.js @@ -0,0 +1,59 @@ +// 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.shift +description: > + [[Prototype]] of Array instance is Array.prototype, [[Prototype] + of Array.prototype is Object.prototype +---*/ + +Array.prototype[1] = -1; +var x = [0, 1]; +x.length = 2; + +var shift = x.shift(); +if (shift !== 0) { + throw new Test262Error('#1: Array.prototype[1] = -1; x = [0,1]; x.length = 2; x.shift() === 0. Actual: ' + (shift)); +} + +if (x[0] !== 1) { + throw new Test262Error('#2: Array.prototype[1] = -1; x = [0,1]; x.length = 2; x.shift(); x[0] === 1. Actual: ' + (x[0])); +} + +if (x[1] !== -1) { + throw new Test262Error('#3: Array.prototype[1] = -1; x = [0,1]; x.length = 2; x.shift(); x[1] === -1. Actual: ' + (x[1])); +} + +Object.prototype[1] = -1; +Object.prototype.length = 2; +Object.prototype.shift = Array.prototype.shift; +x = { + 0: 0, + 1: 1 +}; + +var shift = x.shift(); +if (shift !== 0) { + throw new Test262Error('#4: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.shift = Array.prototype.shift; x = {0:0,1:1}; x.shift() === 0. Actual: ' + (shift)); +} + +if (x[0] !== 1) { + throw new Test262Error('#5: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.shift = Array.prototype.shift; x = {0:0,1:1}; x.shift(); x[0] === 1. Actual: ' + (x[0])); +} + +if (x[1] !== -1) { + throw new Test262Error('#6: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.shift = Array.prototype.shift; x = {0:0,1:1}; x.shift(); x[1] === -1. Actual: ' + (x[1])); +} + +if (x.length !== 1) { + throw new Test262Error('#7: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.shift = Array.prototype.shift; x = {0:0,1:1}; x.shift(); x.length === 1. Actual: ' + (x.length)); +} + +delete x.length; +if (x.length !== 2) { + throw new Test262Error('#8: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.shift = Array.prototype.shift; x = {0:0,1:1}; x.shift(); delete x; x.length === 2. Actual: ' + (x.length)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/shift/browser.js b/js/src/tests/test262/built-ins/Array/prototype/shift/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/shift/browser.js diff --git a/js/src/tests/test262/built-ins/Array/prototype/shift/call-with-boolean.js b/js/src/tests/test262/built-ins/Array/prototype/shift/call-with-boolean.js new file mode 100644 index 0000000000..142fa3a6d0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/shift/call-with-boolean.js @@ -0,0 +1,20 @@ +// Copyright (c) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-array.prototype.shift +description: Array.prototype.shift applied to boolean primitive +---*/ + +assert.sameValue( + Array.prototype.shift.call(true), + undefined, + 'Array.prototype.shift.call(true) must return undefined' +); +assert.sameValue( + Array.prototype.shift.call(false), + undefined, + 'Array.prototype.shift.call(false) must return undefined' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/shift/length.js b/js/src/tests/test262/built-ins/Array/prototype/shift/length.js new file mode 100644 index 0000000000..08932c056d --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/shift/length.js @@ -0,0 +1,30 @@ +// 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.shift +description: > + The "length" property of Array.prototype.shift +info: | + 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.shift.length, 0); + +verifyNotEnumerable(Array.prototype.shift, 'length'); +verifyNotWritable(Array.prototype.shift, 'length'); +verifyConfigurable(Array.prototype.shift, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/shift/name.js b/js/src/tests/test262/built-ins/Array/prototype/shift/name.js new file mode 100644 index 0000000000..a64cdab03f --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/shift/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.shift +description: > + Array.prototype.shift.name is "shift". +info: | + Array.prototype.shift ( ) + + 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.shift.name, "shift"); + +verifyNotEnumerable(Array.prototype.shift, "name"); +verifyNotWritable(Array.prototype.shift, "name"); +verifyConfigurable(Array.prototype.shift, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/shift/not-a-constructor.js b/js/src/tests/test262/built-ins/Array/prototype/shift/not-a-constructor.js new file mode 100644 index 0000000000..b58cbbb0fa --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/shift/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.shift 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.shift), + false, + 'isConstructor(Array.prototype.shift) must return false' +); + +assert.throws(TypeError, () => { + new Array.prototype.shift(); +}, '`new Array.prototype.shift()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/shift/prop-desc.js b/js/src/tests/test262/built-ins/Array/prototype/shift/prop-desc.js new file mode 100644 index 0000000000..851e87947e --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/shift/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.shift +description: > + "shift" 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.shift, 'function', 'typeof'); + +verifyNotEnumerable(Array.prototype, "shift"); +verifyWritable(Array.prototype, "shift"); +verifyConfigurable(Array.prototype, "shift"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/shift/set-length-array-is-frozen.js b/js/src/tests/test262/built-ins/Array/prototype/shift/set-length-array-is-frozen.js new file mode 100644 index 0000000000..30064e098d --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/shift/set-length-array-is-frozen.js @@ -0,0 +1,45 @@ +// 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.shift +description: > + A TypeError is thrown when "length" is [[Set]] on a frozen array. +info: | + Array.prototype.shift ( ) + + [...] + 4. Let first be ? Get(O, "0"). + [...] + 8. Perform ? Set(O, "length", 𝔽(len - 1), 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 = new Array(1); +var arrayPrototypeGet0Calls = 0; + +Object.defineProperty(Array.prototype, "0", { + get() { + Object.freeze(array); + arrayPrototypeGet0Calls++; + }, +}); + +assert.throws(TypeError, function() { + array.shift(); +}); + +assert.sameValue(array.length, 1); +assert.sameValue(arrayPrototypeGet0Calls, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/shift/set-length-array-length-is-non-writable.js b/js/src/tests/test262/built-ins/Array/prototype/shift/set-length-array-length-is-non-writable.js new file mode 100644 index 0000000000..2094475bd9 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/shift/set-length-array-length-is-non-writable.js @@ -0,0 +1,45 @@ +// 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.shift +description: > + A TypeError is thrown when "length" is [[Set]] on an array with non-writable "length". +info: | + Array.prototype.shift ( ) + + [...] + 4. Let first be ? Get(O, "0"). + [...] + 8. Perform ? Set(O, "length", 𝔽(len - 1), 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 = new Array(1); +var arrayPrototypeGet0Calls = 0; + +Object.defineProperty(Array.prototype, "0", { + get() { + Object.defineProperty(array, "length", { writable: false }); + arrayPrototypeGet0Calls++; + }, +}); + +assert.throws(TypeError, function() { + array.shift(); +}); + +assert.sameValue(array.length, 1); +assert.sameValue(arrayPrototypeGet0Calls, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/shift/set-length-zero-array-is-frozen.js b/js/src/tests/test262/built-ins/Array/prototype/shift/set-length-zero-array-is-frozen.js new file mode 100644 index 0000000000..6e5a16be2d --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/shift/set-length-zero-array-is-frozen.js @@ -0,0 +1,34 @@ +// 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.shift +description: > + A TypeError is thrown when "length" is [[Set]] on an empty frozen array. +info: | + Array.prototype.shift ( ) + + [...] + 3. If len = 0, then + a. Perform ? Set(O, "length", +0𝔽, 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.shift(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/shift/set-length-zero-array-length-is-non-writable.js b/js/src/tests/test262/built-ins/Array/prototype/shift/set-length-zero-array-length-is-non-writable.js new file mode 100644 index 0000000000..d7ee7f8f6e --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/shift/set-length-zero-array-length-is-non-writable.js @@ -0,0 +1,34 @@ +// 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.shift +description: > + A TypeError is thrown when "length" is [[Set]] on an empty array with non-writable "length". +info: | + Array.prototype.shift ( ) + + [...] + 3. If len = 0, then + a. Perform ? Set(O, "length", +0𝔽, 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.shift(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/shift/shell.js b/js/src/tests/test262/built-ins/Array/prototype/shift/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/shift/shell.js diff --git a/js/src/tests/test262/built-ins/Array/prototype/shift/throws-when-this-value-length-is-writable-false.js b/js/src/tests/test262/built-ins/Array/prototype/shift/throws-when-this-value-length-is-writable-false.js new file mode 100644 index 0000000000..1c03b29e68 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/shift/throws-when-this-value-length-is-writable-false.js @@ -0,0 +1,37 @@ +// 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.shift +description: > + Array#shift throws TypeError if this value's "length" property was defined with [[Writable]]: false. +info: | + Array.prototype.shift ( ) + ... + 3. If len is zero, then + a. Perform ? Set(O, "length", 0, true). + ... + 8. Perform ? Set(O, "length", len - 1, 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.shift.call(''); +}, "Array.prototype.shift.call('')"); + +assert.throws(TypeError, () => { + Array.prototype.shift.call('abc'); +}, "Array.prototype.shift.call('abc')"); + +assert.throws(TypeError, () => { + Array.prototype.shift.call(function() {}); +}, "Array.prototype.shift.call(function() {})"); + +assert.throws(TypeError, () => { + Array.prototype.shift.call(Object.defineProperty({}, 'length', {writable: false})); +}, "Array.prototype.shift.call(Object.defineProperty({}, 'length', {writable: false}))"); + +reportCompare(0, 0); |