diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/Array/prototype/pop | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Array/prototype/pop')
25 files changed, 986 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A1.1_T1.js b/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A1.1_T1.js new file mode 100644 index 0000000000..6463da32cc --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_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.pop +description: Checking this algorithm +---*/ + +var x = new Array(); +var pop = x.pop(); +if (pop !== undefined) { + throw new Test262Error('#1: var x = new Array(); x.pop() === undefined. Actual: ' + (pop)); +} + +if (x.length !== 0) { + throw new Test262Error('#2: var x = new Array(); x.pop(); x.length === 0. Actual: ' + (x.length)); +} + +var x = Array(1, 2, 3); +x.length = 0; +var pop = x.pop(); +if (pop !== undefined) { + throw new Test262Error('#2: var x = Array(1,2,3); x.length = 0; x.pop() === undefined. Actual: ' + (pop)); +} + +if (x.length !== 0) { + throw new Test262Error('#4: var x = new Array(1,2,3); x.length = 0; x.pop(); x.length === 0. Actual: ' + (x.length)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A1.2_T1.js b/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A1.2_T1.js new file mode 100644 index 0000000000..97cab3dc1e --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_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 last element of the array is removed from the array + and returned +esid: sec-array.prototype.pop +description: Checking this use new Array() and [] +---*/ + +var x = new Array(0, 1, 2, 3); +var pop = x.pop(); +if (pop !== 3) { + throw new Test262Error('#1: x = new Array(0,1,2,3); x.pop() === 3. Actual: ' + (pop)); +} + +if (x.length !== 3) { + throw new Test262Error('#2: x = new Array(0,1,2,3); x.pop(); x.length == 3'); +} + +if (x[3] !== undefined) { + throw new Test262Error('#3: x = new Array(0,1,2,3); x.pop(); x[3] == undefined'); +} + +if (x[2] !== 2) { + throw new Test262Error('#4: x = new Array(0,1,2,3); x.pop(); x[2] == 2'); +} + +x = []; +x[0] = 0; +x[3] = 3; +var pop = x.pop(); +if (pop !== 3) { + throw new Test262Error('#5: x = []; x[0] = 0; x[3] = 3; x.pop() === 3. Actual: ' + (pop)); +} + +if (x.length !== 3) { + throw new Test262Error('#6: x = []; x[0] = 0; x[3] = 3; x.pop(); x.length == 3'); +} + +if (x[3] !== undefined) { + throw new Test262Error('#7: x = []; x[0] = 0; x[3] = 3; x.pop(); x[3] == undefined'); +} + +if (x[2] !== undefined) { + throw new Test262Error('#8: x = []; x[0] = 0; x[3] = 3; x.pop(); x[2] == undefined'); +} + +x.length = 1; +var pop = x.pop(); +if (pop !== 0) { + throw new Test262Error('#9: x = []; x[0] = 0; x[3] = 3; x.pop(); x.length = 1; x.pop() === 0. Actual: ' + (pop)); +} + +if (x.length !== 0) { + throw new Test262Error('#10: x = []; x[0] = 0; x[3] = 3; x.pop(); x.length = 1; x.pop(); x.length === 0. Actual: ' + (x.length)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A2_T1.js b/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A2_T1.js new file mode 100644 index 0000000000..9961c4733a --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_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 pop function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.pop +description: > + If ToUint32(length) equal zero, call the [[Put]] method of this + object with arguments "length" and 0 and return undefined +---*/ + +var obj = {}; +obj.pop = Array.prototype.pop; + +if (obj.length !== undefined) { + throw new Test262Error('#0: var obj = {}; obj.length === undefined. Actual: ' + (obj.length)); +} else { + var pop = obj.pop(); + if (pop !== undefined) { + throw new Test262Error('#1: var obj = {}; obj.pop = Array.prototype.pop; obj.pop() === undefined. Actual: ' + (pop)); + } + if (obj.length !== 0) { + throw new Test262Error('#2: var obj = {}; obj.pop = Array.prototype.pop; obj.pop(); obj.length === 0. Actual: ' + (obj.length)); + } +} + +obj.length = undefined; +var pop = obj.pop(); +if (pop !== undefined) { + throw new Test262Error('#3: var obj = {}; obj.length = undefined; obj.pop = Array.prototype.pop; obj.pop() === undefined. Actual: ' + (pop)); +} + +if (obj.length !== 0) { + throw new Test262Error('#4: var obj = {}; obj.length = undefined; obj.pop = Array.prototype.pop; obj.pop(); obj.length === 0. Actual: ' + (obj.length)); +} + +obj.length = null +var pop = obj.pop(); +if (pop !== undefined) { + throw new Test262Error('#5: var obj = {}; obj.length = null; obj.pop = Array.prototype.pop; obj.pop() === undefined. Actual: ' + (pop)); +} + +if (obj.length !== 0) { + throw new Test262Error('#6: var obj = {}; obj.length = null; obj.pop = Array.prototype.pop; obj.pop(); obj.length === 0. Actual: ' + (obj.length)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A2_T2.js b/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A2_T2.js new file mode 100644 index 0000000000..f414f4d00a --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A2_T2.js @@ -0,0 +1,81 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + The pop function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.pop +description: > + If ToUint32(length) equal zero, call the [[Put]] method of this + object with arguments "length" and 0 and return undefined +---*/ + +var obj = {}; +obj.pop = Array.prototype.pop; + +obj.length = NaN; +var pop = obj.pop(); +if (pop !== undefined) { + throw new Test262Error('#1: var obj = {}; obj.length = NaN; obj.pop = Array.prototype.pop; obj.pop() === undefined. Actual: ' + (pop)); +} + +if (obj.length !== 0) { + throw new Test262Error('#2: var obj = {}; obj.length = NaN; obj.pop = Array.prototype.pop; obj.pop(); obj.length === 0. Actual: ' + (obj.length)); +} + +obj.length = Number.POSITIVE_INFINITY; +var pop = obj.pop(); +if (pop !== undefined) { + throw new Test262Error('#3: var obj = {}; obj.length = Number.POSITIVE_INFINITY; obj.pop = Array.prototype.pop; obj.pop() === undefined. Actual: ' + (pop)); +} + +if (obj.length !== 9007199254740990) { + throw new Test262Error('#4: var obj = {}; obj.length = Number.POSITIVE_INFINITY; obj.pop = Array.prototype.pop; obj.pop(); obj.length === 9007199254740990. Actual: ' + (obj.length)); +} + +obj.length = Number.NEGATIVE_INFINITY; +var pop = obj.pop(); +if (pop !== undefined) { + throw new Test262Error('#5: var obj = {}; obj.length = Number.NEGATIVE_INFINITY; obj.pop = Array.prototype.pop; obj.pop() === undefined. Actual: ' + (pop)); +} + +if (obj.length !== 0) { + throw new Test262Error('#6: var obj = {}; obj.length = Number.NEGATIVE_INFINITY; obj.pop = Array.prototype.pop; obj.pop(); obj.length === 0. Actual: ' + (obj.length)); +} + +obj.length = -0; +var pop = obj.pop(); +if (pop !== undefined) { + throw new Test262Error('#7: var obj = {}; obj.length = -0; obj.pop = Array.prototype.pop; obj.pop() === undefined. Actual: ' + (pop)); +} + +if (obj.length !== 0) { + throw new Test262Error('#8: var obj = {}; obj.length = -0; obj.pop = Array.prototype.pop; obj.pop(); obj.length === 0. Actual: ' + (obj.length)); +} else { + if (1 / obj.length !== Number.POSITIVE_INFINITY) { + throw new Test262Error('#8: var obj = {}; obj.length = -0; obj.pop = Array.prototype.pop; obj.pop(); obj.length === +0. Actual: ' + (obj.length)); + } +} + +obj.length = 0.5; +var pop = obj.pop(); +if (pop !== undefined) { + throw new Test262Error('#9: var obj = {}; obj.length = 0.5; obj.pop = Array.prototype.pop; obj.pop() === undefined. Actual: ' + (pop)); +} + +if (obj.length !== 0) { + throw new Test262Error('#10: var obj = {}; obj.length = 0.5; obj.pop = Array.prototype.pop; obj.pop(); obj.length === 0. Actual: ' + (obj.length)); +} + +obj.length = new Number(0); +var pop = obj.pop(); +if (pop !== undefined) { + throw new Test262Error('#11: var obj = {}; obj.length = new Number(0); obj.pop = Array.prototype.pop; obj.pop() === undefined. Actual: ' + (pop)); +} + +if (obj.length !== 0) { + throw new Test262Error('#12: var obj = {}; obj.length = new Number(0); obj.pop = Array.prototype.pop; obj.pop(); obj.length === 0. Actual: ' + (obj.length)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A2_T3.js b/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A2_T3.js new file mode 100644 index 0000000000..74df6b3500 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_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 pop function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.pop +description: > + The last element ToUint32(length) - 1 of the array is removed from + the array and returned +---*/ + +var obj = {}; +obj.pop = Array.prototype.pop; + +obj.length = 2.5; +var pop = obj.pop(); +if (pop !== undefined) { + throw new Test262Error('#1: var obj = {}; obj.length = 2.5; obj.pop = Array.prototype.pop; obj.pop() === undefined. Actual: ' + (pop)); +} + +if (obj.length !== 1) { + throw new Test262Error('#2: var obj = {}; obj.length = 2.5; obj.pop = Array.prototype.pop; obj.pop(); obj.length === 1. Actual: ' + (obj.length)); +} + +obj.length = new Number(2); +var pop = obj.pop(); +if (pop !== undefined) { + throw new Test262Error('#11: var obj = {}; obj.length = new Number(2); obj.pop = Array.prototype.pop; obj.pop() === undefined. Actual: ' + (pop)); +} + +if (obj.length !== 1) { + throw new Test262Error('#12: var obj = {}; obj.length = new Number(2); obj.pop = Array.prototype.pop; obj.pop(); obj.length === 1. Actual: ' + (obj.length)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A2_T4.js b/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A2_T4.js new file mode 100644 index 0000000000..d37f8024d5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A2_T4.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 pop function is intentionally generic. + It does not require that its this value be an Array object +esid: sec-array.prototype.pop +description: > + Operator use ToNumber from length. If Type(value) is Object, + evaluate ToPrimitive(value, Number) +---*/ + +var obj = {}; +obj.pop = Array.prototype.pop; + +obj[0] = -1; +obj.length = { + valueOf() { + return 1 + } +}; +var pop = obj.pop(); +assert.sameValue(pop, -1, 'The value of pop is expected to be -1'); + +obj[0] = -1; +obj.length = { + valueOf() { + return 1 + }, + toString() { + return 0 + } +}; +var pop = obj.pop(); +assert.sameValue(pop, -1, 'The value of pop is expected to be -1'); + +obj[0] = -1; +obj.length = { + valueOf() { + return 1 + }, + toString() { + return {} + } +}; +var pop = obj.pop(); +assert.sameValue(pop, -1, 'The value of pop is expected to be -1'); + +try { + obj[0] = -1; + obj.length = { + valueOf() { + return 1 + }, + toString() { + throw "error" + } + }; + var pop = obj.pop(); + assert.sameValue(pop, -1, 'The value of pop 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 pop = obj.pop(); +assert.sameValue(pop, undefined, 'The value of pop is expected to equal undefined'); + +obj[0] = -1; +obj.length = { + valueOf() { + return {} + }, + toString() { + return 0 + } +} +var pop = obj.pop(); +assert.sameValue(pop, undefined, 'The value of pop is expected to equal undefined'); + +try { + obj[0] = -1; + obj.length = { + valueOf() { + throw "error" + }, + toString() { + return 0 + } + }; + var pop = obj.pop(); + throw new Test262Error('#7.1: obj[0] = -1; obj.length = {valueOf() {throw "error"}, toString() {return 0}}; obj.pop() throw "error". Actual: ' + (pop)); +} +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 pop = obj.pop(); + throw new Test262Error('#8.1: obj[0] = -1; obj.length = {valueOf() {return {}}, toString() {return {}}} obj.pop() throw TypeError. Actual: ' + (pop)); +} +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/pop/S15.4.4.6_A3_T1.js b/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A3_T1.js new file mode 100644 index 0000000000..7c0ce497dc --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A3_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: Check ToLength(length) for non Array objects +esid: sec-array.prototype.pop +description: length = 4294967296 +---*/ + +var obj = {}; +obj.pop = Array.prototype.pop; +obj[0] = "x"; +obj[4294967295] = "y"; +obj.length = 4294967296; + +var pop = obj.pop(); +if (pop !== "y") { + throw new Test262Error('#1: var obj = {}; obj.pop = Array.prototype.pop; obj[0] = "x"; obj[4294967295] = "y"; obj.length = 4294967296; obj.pop() === "y". Actual: ' + (pop)); +} + +if (obj.length !== 4294967295) { + throw new Test262Error('#2: var obj = {}; obj.pop = Array.prototype.pop; obj[0] = "x"; obj[4294967295] = "y"; obj.length = 4294967296; obj.pop(); obj.length === 4294967295. Actual: ' + (obj.length)); +} + +if (obj[0] !== "x") { + throw new Test262Error('#3: var obj = {}; obj.pop = Array.prototype.pop; obj[0] = "x"; obj[4294967295] = "y"; obj.length = 4294967296; obj.pop(); obj[0] === "x". Actual: ' + (obj[0])); +} + +if (obj[4294967295] !== undefined) { + throw new Test262Error('#4: var obj = {}; obj.pop = Array.prototype.pop; obj[0] = "x"; obj[4294967295] = "y"; obj.length = 4294967296; obj.pop(); obj[4294967295] === undefined. Actual: ' + (obj[4294967295])); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A3_T2.js b/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A3_T2.js new file mode 100644 index 0000000000..b6de632743 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A3_T2.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.pop +description: length = 4294967297 +---*/ + +var obj = {}; +obj.pop = Array.prototype.pop; +obj[0] = "x"; +obj[4294967296] = "y"; +obj.length = 4294967297; + +var pop = obj.pop(); +if (pop !== "y") { + throw new Test262Error('#1: var obj = {}; obj.pop = Array.prototype.pop; obj[0] = "x"; obj[4294967296] = "y"; obj.length = 4294967297; obj.pop() === "y". Actual: ' + (pop)); +} + +if (obj.length !== 4294967296) { + throw new Test262Error('#2: var obj = {}; obj.pop = Array.prototype.pop; obj[0] = "x"; obj[4294967296] = "y"; obj.length = 4294967297; obj.pop(); obj.length === 4294967296. Actual: ' + (obj.length)); +} + +if (obj[0] !== "x") { + throw new Test262Error('#3: var obj = {}; obj.pop = Array.prototype.pop; obj[0] = "x"; obj[4294967296] = "y"; obj.length = 4294967297; obj.pop(); obj[0] === "x". Actual: ' + (obj[0])); +} + +if (obj[4294967296] !== undefined) { + throw new Test262Error('#4: var obj = {}; obj.pop = Array.prototype.pop; obj[0] = "x"; obj[4294967296] = "y"; obj.length = 4294967297; obj.pop(); obj[4294967296] === undefined. Actual: ' + (obj[4294967296])); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A3_T3.js b/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A3_T3.js new file mode 100644 index 0000000000..7086832284 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A3_T3.js @@ -0,0 +1,28 @@ +// 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.pop +description: length = -1 +---*/ + +var obj = {}; +obj.pop = Array.prototype.pop; +obj[4294967294] = "x"; +obj.length = -1; + +var pop = obj.pop(); +if (pop !== undefined) { + throw new Test262Error('#1: var obj = {}; obj.pop = Array.prototype.pop; obj[4294967294] = "x"; obj.length = -1; obj.pop() === undefined. Actual: ' + (pop)); +} + +if (obj.length !== 0) { + throw new Test262Error('#2: var obj = {}; obj.pop = Array.prototype.pop; obj[4294967294] = "x"; obj.length = -1; obj.pop(); obj.length === 0. Actual: ' + (obj.length)); +} + +if (obj[4294967294] !== "x") { + throw new Test262Error('#3: var obj = {}; obj.pop = Array.prototype.pop; obj[4294967294] = "x"; obj.length = -1; obj.pop(); obj[4294967294] === "x". Actual: ' + (obj[4294967294])); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A4_T1.js b/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A4_T1.js new file mode 100644 index 0000000000..454bd58b98 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A4_T1.js @@ -0,0 +1,50 @@ +// 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.pop +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 pop = x.pop(); +if (pop !== 1) { + throw new Test262Error('#1: Array.prototype[1] = 1; x = [0]; x.length = 2; x.pop() === 1. Actual: ' + (pop)); +} + +if (x[1] !== 1) { + throw new Test262Error('#2: Array.prototype[1] = 1; x = [0]; x.length = 2; x.pop(); x[1] === 1. Actual: ' + (x[1])); +} + +Object.prototype[1] = 1; +Object.prototype.length = 2; +Object.prototype.pop = Array.prototype.pop; +x = { + 0: 0 +}; + +var pop = x.pop(); +if (pop !== 1) { + throw new Test262Error('#3: Object.prototype[1] = 1; Object.prototype.length = 2; Object.prototype.pop = Array.prototype.pop; x = {0:0}; x.pop() === 1. Actual: ' + (pop)); +} + +if (x[1] !== 1) { + throw new Test262Error('#4: Object.prototype[1] = 1; Object.prototype.length = 2; Object.prototype.pop = Array.prototype.pop; x = {0:0}; x.pop(); x[1] === 1. Actual: ' + (x[1])); +} + +if (x.length !== 1) { + throw new Test262Error('#6: Object.prototype[1] = 1; Object.prototype.length = 2; Object.prototype.pop = Array.prototype.pop; x = {0:0}; x.pop(); x.length === 1. Actual: ' + (x.length)); +} + +delete x.length; +if (x.length !== 2) { + throw new Test262Error('#7: Object.prototype[1] = 1; Object.prototype.length = 2; Object.prototype.pop = Array.prototype.pop; x = {0:0}; x.pop(); delete x; x.length === 2. Actual: ' + (x.length)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A4_T2.js b/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A4_T2.js new file mode 100644 index 0000000000..51ed4692cf --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/S15.4.4.6_A4_T2.js @@ -0,0 +1,51 @@ +// 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.pop +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 pop = x.pop(); +if (pop !== 1) { + throw new Test262Error('#1: Array.prototype[1] = -1; x = [0,1]; x.length = 2; x.pop() === 1. Actual: ' + (pop)); +} + +if (x[1] !== -1) { + throw new Test262Error('#2: Array.prototype[1] = -1; x = [0,1]; x.length = 2; x.pop(); x[1] === -1. Actual: ' + (x[1])); +} + +Object.prototype[1] = -1; +Object.prototype.length = 2; +Object.prototype.pop = Array.prototype.pop; +x = { + 0: 0, + 1: 1 +}; + +var pop = x.pop(); +if (pop !== 1) { + throw new Test262Error('#3: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.pop = Array.prototype.pop; x = {0:0,1:1}; x.pop() === 1. Actual: ' + (pop)); +} + +if (x[1] !== -1) { + throw new Test262Error('#4: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.pop = Array.prototype.pop; x = {0:0,1:1}; x.pop(); x[1] === -1. Actual: ' + (x[1])); +} + +if (x.length !== 1) { + throw new Test262Error('#6: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.pop = Array.prototype.pop; x = {0:0,1:1}; x.pop(); x.length === 1. Actual: ' + (x.length)); +} + +delete x.length; +if (x.length !== 2) { + throw new Test262Error('#7: Object.prototype[1] = -1; Object.prototype.length = 2; Object.prototype.pop = Array.prototype.pop; x = {0:0,1:1}; x.pop(); delete x; x.length === 2. Actual: ' + (x.length)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/browser.js b/js/src/tests/test262/built-ins/Array/prototype/pop/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/browser.js diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/call-with-boolean.js b/js/src/tests/test262/built-ins/Array/prototype/pop/call-with-boolean.js new file mode 100644 index 0000000000..024b63e892 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/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.pop +description: Array.prototype.pop applied to boolean primitive +---*/ + +assert.sameValue(Array.prototype.pop.call(true), undefined, 'Array.prototype.pop.call(true) must return undefined'); +assert.sameValue(Array.prototype.pop.call(false), undefined, 'Array.prototype.pop.call(false) must return undefined'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/clamps-to-integer-limit.js b/js/src/tests/test262/built-ins/Array/prototype/pop/clamps-to-integer-limit.js new file mode 100644 index 0000000000..4f0b10b147 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/clamps-to-integer-limit.js @@ -0,0 +1,38 @@ +// 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.pop +description: > + Length values exceeding 2^53-1 are clamped to 2^53-1. +info: | + 1. ... + 2. Let len be ? ToLength(? Get(O, "length")). + ... + 4. Else len > 0, + a. Let newLen be len-1. + ... + e. Perform ? Set(O, "length", newLen, true). + ... +features: [exponentiation] +---*/ + +var arrayLike = {}; + +arrayLike.length = 2 ** 53 - 1; +Array.prototype.pop.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 2, "Length is 2**53 - 1"); + +arrayLike.length = 2 ** 53; +Array.prototype.pop.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 2, "Length is 2**53"); + +arrayLike.length = 2 ** 53 + 2; +Array.prototype.pop.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 2, "Length is 2**53 + 2"); + +arrayLike.length = Infinity; +Array.prototype.pop.call(arrayLike); +assert.sameValue(arrayLike.length, 2 ** 53 - 2, "Length is Infinity"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/length-near-integer-limit.js b/js/src/tests/test262/built-ins/Array/prototype/pop/length-near-integer-limit.js new file mode 100644 index 0000000000..65cb4b0132 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/length-near-integer-limit.js @@ -0,0 +1,46 @@ +// 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.pop +description: > + A value is removed from an array-like object whose length property is near the integer limit. +info: | + ... + 2. Let len be ? ToLength(? Get(O, "length")). + ... + 4. Else len > 0, + a. Let newLen be len-1. + b. Let index be ! ToString(newLen). + c. Let element be ? Get(O, index). + d. Perform ? DeletePropertyOrThrow(O, index). + e. Perform ? Set(O, "length", newLen, true). + f. Return element. +features: [exponentiation] +---*/ + +var arrayLike = { + "9007199254740989": "9007199254740989", + "9007199254740990": "9007199254740990", + "9007199254740991": "9007199254740991", + length: 2 ** 53 - 1 +}; + +var value = Array.prototype.pop.call(arrayLike); + +assert.sameValue(value, "9007199254740990", + "arrayLike['9007199254740990'] is returned from pop()"); + +assert.sameValue(arrayLike.length, 2 ** 53 - 2, + "New arrayLike.length is 2**53 - 2"); + +assert.sameValue(arrayLike["9007199254740989"], "9007199254740989", + "arrayLike['9007199254740989'] is unchanged"); + +assert.sameValue("9007199254740990" in arrayLike, false, + "arrayLike['9007199254740990'] is removed"); + +assert.sameValue(arrayLike["9007199254740991"], "9007199254740991", + "arrayLike['9007199254740991'] is unchanged"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/length.js b/js/src/tests/test262/built-ins/Array/prototype/pop/length.js new file mode 100644 index 0000000000..6285c752f0 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/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.pop +description: > + The "length" property of Array.prototype.pop +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.pop.length, 0); + +verifyNotEnumerable(Array.prototype.pop, 'length'); +verifyNotWritable(Array.prototype.pop, 'length'); +verifyConfigurable(Array.prototype.pop, 'length'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/name.js b/js/src/tests/test262/built-ins/Array/prototype/pop/name.js new file mode 100644 index 0000000000..891fb91858 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/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.pop +description: > + Array.prototype.pop.name is "pop". +info: | + Array.prototype.pop ( ) + + 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.pop.name, "pop"); + +verifyNotEnumerable(Array.prototype.pop, "name"); +verifyNotWritable(Array.prototype.pop, "name"); +verifyConfigurable(Array.prototype.pop, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/not-a-constructor.js b/js/src/tests/test262/built-ins/Array/prototype/pop/not-a-constructor.js new file mode 100644 index 0000000000..849c2b3305 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/not-a-constructor.js @@ -0,0 +1,31 @@ +// 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.pop 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.pop), false, 'isConstructor(Array.prototype.pop) must return false'); + +assert.throws(TypeError, () => { + new Array.prototype.pop(); +}, '`new Array.prototype.pop()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/prop-desc.js b/js/src/tests/test262/built-ins/Array/prototype/pop/prop-desc.js new file mode 100644 index 0000000000..c39724bd1d --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/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.pop +description: > + "pop" 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.pop, 'function', 'typeof'); + +verifyNotEnumerable(Array.prototype, "pop"); +verifyWritable(Array.prototype, "pop"); +verifyConfigurable(Array.prototype, "pop"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/set-length-array-is-frozen.js b/js/src/tests/test262/built-ins/Array/prototype/pop/set-length-array-is-frozen.js new file mode 100644 index 0000000000..d083e0eb19 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/set-length-array-is-frozen.js @@ -0,0 +1,49 @@ +// 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.pop +description: > + A TypeError is thrown when "length" is [[Set]] on a frozen array. +info: | + Array.prototype.pop ( ) + + [...] + 4. Else, + a. Assert: len > 0. + b. Let newLen be 𝔽(len - 1). + c. Let index be ! ToString(newLen). + d. Let element be ? Get(O, index). + e. Perform ? DeletePropertyOrThrow(O, index). + f. Perform ? Set(O, "length", newLen, 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.pop(); +}); + +assert.sameValue(array.length, 1); +assert.sameValue(arrayPrototypeGet0Calls, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/set-length-array-length-is-non-writable.js b/js/src/tests/test262/built-ins/Array/prototype/pop/set-length-array-length-is-non-writable.js new file mode 100644 index 0000000000..b53a73d867 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/set-length-array-length-is-non-writable.js @@ -0,0 +1,49 @@ +// 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.pop +description: > + A TypeError is thrown when "length" is [[Set]] on an array with non-writable "length". +info: | + Array.prototype.pop ( ) + + [...] + 4. Else, + a. Assert: len > 0. + b. Let newLen be 𝔽(len - 1). + c. Let index be ! ToString(newLen). + d. Let element be ? Get(O, index). + e. Perform ? DeletePropertyOrThrow(O, index). + f. Perform ? Set(O, "length", newLen, 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.pop(); +}); + +assert.sameValue(array.length, 1); +assert.sameValue(arrayPrototypeGet0Calls, 1); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/set-length-zero-array-is-frozen.js b/js/src/tests/test262/built-ins/Array/prototype/pop/set-length-zero-array-is-frozen.js new file mode 100644 index 0000000000..a4fc043959 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/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.pop +description: > + A TypeError is thrown when "length" is [[Set]] on an empty frozen array. +info: | + Array.prototype.pop ( ) + + [...] + 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.pop(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/set-length-zero-array-length-is-non-writable.js b/js/src/tests/test262/built-ins/Array/prototype/pop/set-length-zero-array-length-is-non-writable.js new file mode 100644 index 0000000000..36664bc495 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/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.pop +description: > + A TypeError is thrown when "length" is [[Set]] on an empty array with non-writable "length". +info: | + Array.prototype.pop ( ) + + [...] + 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.pop(); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/shell.js b/js/src/tests/test262/built-ins/Array/prototype/pop/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/shell.js diff --git a/js/src/tests/test262/built-ins/Array/prototype/pop/throws-with-string-receiver.js b/js/src/tests/test262/built-ins/Array/prototype/pop/throws-with-string-receiver.js new file mode 100644 index 0000000000..4c2bfa1bff --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/prototype/pop/throws-with-string-receiver.js @@ -0,0 +1,31 @@ +// 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.pop +description: > + Array#pop throws TypeError upon attempting to modify a string +info: | + Array.prototype.pop ( ) + ... + 3. If len is zero, then + a. Perform ? Set(O, "length", 0, true). + ... + 4. Else, + ... + f. Perform ? Set(O, "length", newLen, 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.pop.call(''); +}, "Array.prototype.pop.call('')"); + +assert.throws(TypeError, () => { + Array.prototype.pop.call('abc'); +}, "Array.prototype.pop.call('abc')"); + +reportCompare(0, 0); |