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/language/expressions/unary-minus | |
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/language/expressions/unary-minus')
16 files changed, 460 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/expressions/unary-minus/11.4.7-4-1.js b/js/src/tests/test262/language/expressions/unary-minus/11.4.7-4-1.js new file mode 100644 index 0000000000..69d85bfd59 --- /dev/null +++ b/js/src/tests/test262/language/expressions/unary-minus/11.4.7-4-1.js @@ -0,0 +1,11 @@ +// Copyright (c) 2012 Ecma International. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 11.4.7-4-1 +description: -"" should be zero +---*/ + +assert.sameValue(-"", -0, '-""'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A1.js b/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A1.js new file mode 100644 index 0000000000..a7346c52fa --- /dev/null +++ b/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A1.js @@ -0,0 +1,62 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + White Space and Line Terminator between "-" and UnaryExpression are + allowed +es5id: 11.4.7_A1 +description: Checking by using eval +---*/ + +//CHECK#1 +if (eval("-\u00091") !== -1) { + throw new Test262Error('#1: -\\u00091 === -1'); +} + +//CHECK#2 +if (eval("-\u000B1") !== -1) { + throw new Test262Error('#2: -\\u000B1 === -1'); +} + +//CHECK#3 +if (eval("-\u000C1") !== -1) { + throw new Test262Error('#3: -\\u000C1 === -1'); +} + +//CHECK#4 +if (eval("-\u00201") !== -1) { + throw new Test262Error('#4: -\\u0020 === -1'); +} + +//CHECK#5 +if (eval("-\u00A01") !== -1) { + throw new Test262Error('#5: -\\u00A01 === -1'); +} + +//CHECK#6 +if (eval("-\u000A1") !== -1) { + throw new Test262Error('#6: -\\u000A1 === -1'); +} + +//CHECK#7 +if (eval("-\u000D1") !== -1) { + throw new Test262Error('#7: -\\u000D1 === -1'); +} + +//CHECK#8 +if (eval("-\u20281") !== -1) { + throw new Test262Error('#8: -\\u20281 === -1'); +} + +//CHECK#9 +if (eval("-\u20291") !== -1) { + throw new Test262Error('#9: -\\u20291 === -1'); +} + +//CHECK#10 +if (eval("-\u0009\u000B\u000C\u0020\u00A0\u000A\u000D\u2028\u20291") !== -1) { + throw new Test262Error('#10: -\\u0009\\u000B\\u000C\\u0020\\u00A0\\u000A\\u000D\\u2028\\u20291 === -1'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A2.1_T1.js b/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A2.1_T1.js new file mode 100644 index 0000000000..f927f0f48d --- /dev/null +++ b/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A2.1_T1.js @@ -0,0 +1,39 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator -x uses GetValue +es5id: 11.4.7_A2.1_T1 +description: Either Type(x) is not Reference or GetBase(x) is not null +---*/ + +//CHECK#1 +if (-1 !== -1) { + throw new Test262Error('#1: -1 === -1. Actual: ' + (-1)); +} + +//CHECK#2 +if (-(-1) !== 1) { + throw new Test262Error('#2: -(-1) === -1. Actual: ' + (-(-1))); +} + +//CHECK#3 +var x = -1; +if (-x !== 1) { + throw new Test262Error('#3: var x = -1; -x === 1. Actual: ' + (-x)); +} + +//CHECK#4 +var x = -1; +if (-(-x) !== -1) { + throw new Test262Error('#4: var x = -1; -(-x) === -1. Actual: ' + (-(-x))); +} + +//CHECK#5 +var object = new Object(); +object.prop = 1; +if (-object.prop !== -1) { + throw new Test262Error('#5: var object = new Object(); object.prop = -1; -object.prop === -1. Actual: ' + (-object.prop)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A2.1_T2.js b/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A2.1_T2.js new file mode 100644 index 0000000000..c9d49abfc4 --- /dev/null +++ b/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A2.1_T2.js @@ -0,0 +1,21 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator -x uses GetValue +es5id: 11.4.7_A2.1_T2 +description: If GetBase(x) is null, throw ReferenceError +---*/ + +//CHECK#1 +try { + -x; + throw new Test262Error('#1.1: -x throw ReferenceError. Actual: ' + (-x)); +} +catch (e) { + if ((e instanceof ReferenceError) !== true) { + throw new Test262Error('#1.2: -x throw ReferenceError. Actual: ' + (e)); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A2.2_T1.js b/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A2.2_T1.js new file mode 100644 index 0000000000..5eec8aaa18 --- /dev/null +++ b/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A2.2_T1.js @@ -0,0 +1,79 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator -x uses [[Default Value]] +es5id: 11.4.7_A2.2_T1 +description: If Type(value) is Object, evaluate ToPrimitive(value, Number) +---*/ + +//CHECK#1 +var object = {valueOf: function() {return -1}}; +if (-object !== 1) { + throw new Test262Error('#1: var object = {valueOf: function() {return -1}}; -object === 1. Actual: ' + (-object)); +} + +//CHECK#2 +var object = {valueOf: function() {return -1}, toString: function() {return 0}}; +if (-object !== 1) { + throw new Test262Error('#2: var object = {valueOf: function() {return -1}, toString: function() {return 0}}; -object === 1. Actual: ' + (-object)); +} + +//CHECK#3 +var object = {valueOf: function() {return -1}, toString: function() {return {}}}; +if (-object !== 1) { + throw new Test262Error('#3: var object = {valueOf: function() {return -1}, toString: function() {return {}}}; -object === 1. Actual: ' + (-object)); +} + +//CHECK#4 +try { + var object = {valueOf: function() {return -1}, toString: function() {throw "error"}}; + if (-object !== 1) { + throw new Test262Error('#4.1: var object = {valueOf: function() {return -1}, toString: function() {throw "error"}}; -object === 1. Actual: ' + (-object)); + } +} +catch (e) { + if (e === "error") { + throw new Test262Error('#4.2: var object = {valueOf: function() {return -1}, toString: function() {throw "error"}}; -object not throw "error"'); + } else { + throw new Test262Error('#4.3: var object = {valueOf: function() {return -1}, toString: function() {throw "error"}}; -object not throw Error. Actual: ' + (e)); + } +} + +//CHECK#5 +var object = {toString: function() {return -1}}; +if (-object !== 1) { + throw new Test262Error('#5.1: var object = {toString: function() {return -1}}; -object === 1. Actual: ' + (-object)); +} + +//CHECK#6 +var object = {valueOf: function() {return {}}, toString: function() {return -1}} +if (-object !== 1) { + throw new Test262Error('#6: var object = {valueOf: function() {return {}}, toString: function() {return -1}}; -object === 1. Actual: ' + (-object)); +} + +//CHECK#7 +try { + var object = {valueOf: function() {throw "error"}, toString: function() {return -1}}; + -object; + throw new Test262Error('#7.1: var object = {valueOf: function() {throw "error"}, toString: function() {return -1}}; -object throw "error". Actual: ' + (-object)); +} +catch (e) { + if (e !== "error") { + throw new Test262Error('#7.2: var object = {valueOf: function() {throw "error"}, toString: function() {return -1}}; -object throw "error". Actual: ' + (e)); + } +} + +//CHECK#8 +try { + var object = {valueOf: function() {return {}}, toString: function() {return {}}}; + -object; + throw new Test262Error('#8.1: var object = {valueOf: function() {return {}}, toString: function() {return {}}}; -object throw TypeError. Actual: ' + (-object)); +} +catch (e) { + if ((e instanceof TypeError) !== true) { + throw new Test262Error('#8.2: var object = {valueOf: function() {return {}}, toString: function() {return {}}}; -object throw TypeError. Actual: ' + (e)); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A3_T1.js b/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A3_T1.js new file mode 100644 index 0000000000..80e3f16129 --- /dev/null +++ b/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A3_T1.js @@ -0,0 +1,20 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator -x returns -ToNumber(x) +es5id: 11.4.7_A3_T1 +description: Type(x) is boolean primitive or Boolean object +---*/ + +//CHECK#1 +if (-false !== 0) { + throw new Test262Error('#1: -false === 0. Actual: ' + (-false)); +} + +//CHECK#2 +if (-new Boolean(true) !== -1) { + throw new Test262Error('#2: -new Boolean(true) === -1. Actual: ' + (-new Boolean(true))); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A3_T2.js b/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A3_T2.js new file mode 100644 index 0000000000..10e3a726c7 --- /dev/null +++ b/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A3_T2.js @@ -0,0 +1,20 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator -x returns -ToNumber(x) +es5id: 11.4.7_A3_T2 +description: Type(x) is number primitive or Number object +---*/ + +//CHECK#1 +if (-(1) !== -1) { + throw new Test262Error('#1: -(1) === -1. Actual: ' + (-(1))); +} + +//CHECK#2 +if (-new Number(-1) !== 1) { + throw new Test262Error('#2: -new Number(-1) === 1. Actual: ' + (-new Number(-1))); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A3_T3.js b/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A3_T3.js new file mode 100644 index 0000000000..09976f23f5 --- /dev/null +++ b/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A3_T3.js @@ -0,0 +1,25 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator -x returns -ToNumber(x) +es5id: 11.4.7_A3_T3 +description: Type(x) is string primitive or String object +---*/ + +//CHECK#1 +if (-"1" !== -1) { + throw new Test262Error('#1: -"1" === -1. Actual: ' + (-"1")); +} + +//CHECK#2 +if (isNaN(-"x") !== true) { + throw new Test262Error('#2: -"x" === Not-a-Number. Actual: ' + (-"x")); +} + +//CHECK#3 +if (-new String("-1") !== 1) { + throw new Test262Error('#3: -new String("-1") === 1. Actual: ' + (-new String("-1"))); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A3_T4.js b/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A3_T4.js new file mode 100644 index 0000000000..f5906dd2a0 --- /dev/null +++ b/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A3_T4.js @@ -0,0 +1,20 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator -x returns -ToNumber(x) +es5id: 11.4.7_A3_T4 +description: Type(x) is undefined or null +---*/ + +//CHECK#1 +if (isNaN(-void 0) !== true) { + throw new Test262Error('#1: +void 0 === Not-a-Number. Actual: ' + (+void 0)); +} + +//CHECK#2 +if (-null !== 0) { + throw new Test262Error('#2: +null === 0. Actual: ' + (+null)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A3_T5.js b/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A3_T5.js new file mode 100644 index 0000000000..c126479917 --- /dev/null +++ b/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A3_T5.js @@ -0,0 +1,20 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator -x returns -ToNumber(x) +es5id: 11.4.7_A3_T5 +description: Type(x) is Object object or Function object +---*/ + +//CHECK#1 +if (isNaN(-{}) !== true) { + throw new Test262Error('#1: -{} === Not-a-Number. Actual: ' + (-{})); +} + +//CHECK#2 +if (isNaN(-function(){return 1}) !== true) { + throw new Test262Error('#2: -function(){return 1} === Not-a-Number. Actual: ' + (-function(){return 1})); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A4.1.js b/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A4.1.js new file mode 100644 index 0000000000..7a40185964 --- /dev/null +++ b/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A4.1.js @@ -0,0 +1,21 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: If x is NaN, operator -x returns NaN +es5id: 11.4.7_A4.1 +description: Checking NaN +---*/ + +//CHECK#1 +if (isNaN(-NaN) !== true) { + throw new Test262Error('#1: -NaN === Not-a-Number. Actual: ' + (-NaN)); +} + +//CHECK#2 +var x = NaN; +if (isNaN(-x) != true) { + throw new Test262Error('#2: var x = NaN; -x === Not-a-Number. Actual: ' + (-x)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A4.2.js b/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A4.2.js new file mode 100644 index 0000000000..de82489eb5 --- /dev/null +++ b/js/src/tests/test262/language/expressions/unary-minus/S11.4.7_A4.2.js @@ -0,0 +1,32 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Negating +0 produces -0, negating -0 produces +0 +es5id: 11.4.7_A4.2 +description: Checking Infinity +---*/ + +//CHECK#1 +var x = 0; +x = -x; +if (x !== -0) { + throw new Test262Error('#1.1: var x = 0; x = -x; x === 0. Actual: ' + (x)); +} else { + if (1/x !== Number.NEGATIVE_INFINITY) { + throw new Test262Error('#1.2: var x = 0; x = -x; x === - 0. Actual: +0'); + } +} + +//CHECK#2 +var x = -0; +x = -x; +if (x !== 0) { + throw new Test262Error('#2.1: var x = -0; x = -x; x === 0. Actual: ' + (x)); +} else { + if (1/x !== Number.POSITIVE_INFINITY) { + throw new Test262Error('#2.2: var x = -0; x = -x; x === + 0. Actual: -0'); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/unary-minus/bigint-non-primitive.js b/js/src/tests/test262/language/expressions/unary-minus/bigint-non-primitive.js new file mode 100644 index 0000000000..31920ce3dc --- /dev/null +++ b/js/src/tests/test262/language/expressions/unary-minus/bigint-non-primitive.js @@ -0,0 +1,54 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Unary minus for BigInt object wrappers +esid: sec-unary-minus-operator-runtime-semantics-evaluation +info: | + Runtime Semantics: Evaluation + UnaryExpression : - UnaryExpression + + 1. Let expr be the result of evaluating UnaryExpression. + 2. Let oldValue be ? ToNumeric(? GetValue(expr)). + 3. Let T be Type(oldValue). + 4. Return ? T::unaryMinus(oldValue). + +features: [BigInt, Symbol.toPrimitive] +---*/ +assert.sameValue(-Object(1n), -1n, 'The value of -Object(1n) is -1n'); +assert.notSameValue(-Object(1n), 1n, 'The value of -Object(1n) is not 1n'); +assert.notSameValue(-Object(1n), Object(-1n), 'The value of -Object(1n) is not Object(-1n)'); +assert.sameValue(-Object(-1n), 1n, 'The value of -Object(-1n) is 1n'); +assert.notSameValue(-Object(-1n), -1n, 'The value of -Object(-1n) is not -1n'); +assert.notSameValue(-Object(-1n), Object(1n), 'The value of -Object(-1n) is not Object(1n)'); + +assert.sameValue(-{ + [Symbol.toPrimitive]: function() { + return 1n; + }, + + valueOf: function() { + throw new Test262Error(); + }, + + toString: function() { + throw new Test262Error(); + } +}, -1n, 'The value of -{[Symbol.toPrimitive]: function() {return 1n;}, valueOf: function() {throw new Test262Error();}, toString: function() {throw new Test262Error();}} is -1n'); + +assert.sameValue(-{ + valueOf: function() { + return 1n; + }, + + toString: function() { + throw new Test262Error(); + } +}, -1n, 'The value of -{valueOf: function() {return 1n;}, toString: function() {throw new Test262Error();}} is -1n'); + +assert.sameValue(-{ + toString: function() { + return 1n; + } +}, -1n, 'The value of -{toString: function() {return 1n;}} is -1n'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/unary-minus/bigint.js b/js/src/tests/test262/language/expressions/unary-minus/bigint.js new file mode 100644 index 0000000000..727f6d5ed1 --- /dev/null +++ b/js/src/tests/test262/language/expressions/unary-minus/bigint.js @@ -0,0 +1,36 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Unary minus for BigInt values +esid: sec-numeric-types-bigint-unaryMinus +info: | + BigInt::unaryMinus (x) + + The abstract operation BigInt::unaryMinus with an argument x of BigInt type returns the result of negating x. + + Note: There is only one 0n value; -0n is the same as 0n. + +features: [BigInt] +---*/ + +assert.sameValue(-0n, 0n, "-0n === 0n"); +assert.sameValue(-(0n), 0n, "-(0n) === 0n"); +assert.notSameValue(-1n, 1n, "-1n !== 1n"); +assert.sameValue(-(1n), -1n, "-(1n) === -1n"); +assert.notSameValue(-(1n), 1n, "-(1n) !== 1n"); +assert.sameValue(-(-1n), 1n, "-(-1n) === 1n"); +assert.notSameValue(-(-1n), -1n, "-(-1n) !== -1n"); +assert.sameValue(- - 1n, 1n, "- - 1n === 1n"); +assert.notSameValue(- - 1n, -1n, "- - 1n !== -1n"); +assert.sameValue( + -(0x1fffffffffffff01n), -0x1fffffffffffff01n, + "-(0x1fffffffffffff01n) === -0x1fffffffffffff01n"); +assert.notSameValue( + -(0x1fffffffffffff01n), 0x1fffffffffffff01n, + "-(0x1fffffffffffff01n) !== 0x1fffffffffffff01n"); +assert.notSameValue( + -(0x1fffffffffffff01n), -0x1fffffffffffff00n, + "-(0x1fffffffffffff01n) !== -0x1fffffffffffff00n"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/unary-minus/browser.js b/js/src/tests/test262/language/expressions/unary-minus/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/unary-minus/browser.js diff --git a/js/src/tests/test262/language/expressions/unary-minus/shell.js b/js/src/tests/test262/language/expressions/unary-minus/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/unary-minus/shell.js |