diff options
Diffstat (limited to 'js/src/tests/test262/language/expressions/equals')
49 files changed, 2022 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A1.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A1.js new file mode 100644 index 0000000000..1e8f33661d --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_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 EqualityExpression and "==" or + between "==" and RelationalExpression are allowed +es5id: 11.9.1_A1 +description: Checking by using eval +---*/ + +//CHECK#1 +if (eval("true\u0009==\u00091") !== true) { + throw new Test262Error('#1: (true\\u0009==\\u00091) === true'); +} + +//CHECK#2 +if (eval("true\u000B==\u000B1") !== true) { + throw new Test262Error('#2: (true\\u000B==\\u000B1) === true'); +} + +//CHECK#3 +if (eval("true\u000C==\u000C1") !== true) { + throw new Test262Error('#3: (true\\u000C==\\u000C1) === true'); +} + +//CHECK#4 +if (eval("true\u0020==\u00201") !== true) { + throw new Test262Error('#4: (true\\u0020==\\u00201) === true'); +} + +//CHECK#5 +if (eval("true\u00A0==\u00A01") !== true) { + throw new Test262Error('#5: (true\\u00A0==\\u00A01) === true'); +} + +//CHECK#6 +if (eval("true\u000A==\u000A1") !== true) { + throw new Test262Error('#6: (true\\u000A==\\u000A1) === true'); +} + +//CHECK#7 +if (eval("true\u000D==\u000D1") !== true) { + throw new Test262Error('#7: (true\\u000D==\\u000D1) === true'); +} + +//CHECK#8 +if (eval("true\u2028==\u20281") !== true) { + throw new Test262Error('#8: (true\\u2028==\\u20281) === true'); +} + +//CHECK#9 +if (eval("true\u2029==\u20291") !== true) { + throw new Test262Error('#9: (true\\u2029==\\u20291) === true'); +} + +//CHECK#10 +if (eval("true\u0009\u000B\u000C\u0020\u00A0\u000A\u000D\u2028\u2029==\u0009\u000B\u000C\u0020\u00A0\u000A\u000D\u2028\u20291") !== true) { + throw new Test262Error('#10: (true\\u0009\\u000B\\u000C\\u0020\\u00A0\\u000A\\u000D\\u2028\\u2029==\\u0009\\u000B\\u000C\\u0020\\u00A0\\u000A\\u000D\\u2028\\u20291) === true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A2.1_T1.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A2.1_T1.js new file mode 100644 index 0000000000..592b30d231 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A2.1_T1.js @@ -0,0 +1,43 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: Operator x == y uses GetValue +es5id: 11.9.1_A2.1_T1 +description: Either Type is not Reference or GetBase is not null +---*/ + +//CHECK#1 +if ((1 == 1) !== true) { + throw new Test262Error('#1: (1 == 1) === true'); +} + +//CHECK#2 +var x = 1; +if ((x == 1) !== true) { + throw new Test262Error('#2: var x = 1; (x == 1) === true'); +} + +//CHECK#3 +var y = 1; +if ((1 == y) !== true) { + throw new Test262Error('#3: var y = 1; (1 == y) === true'); +} + +//CHECK#4 +var x = 1; +var y = 1; +if ((x == y) !== true) { + throw new Test262Error('#4: var x = 1; var y = 1; (x == y) === true'); +} + +//CHECK#5 +var objectx = new Object(); +var objecty = new Object(); +objectx.prop = 1; +objecty.prop = 1; +if ((objectx.prop == objecty.prop) !== true) { + throw new Test262Error('#5: var objectx = new Object(); var objecty = new Object(); objectx.prop = 1; objecty.prop = 1; (objectx.prop == objecty.prop) === true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A2.1_T2.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A2.1_T2.js new file mode 100644 index 0000000000..a35fef3d10 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_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 == y uses GetValue +es5id: 11.9.1_A2.1_T2 +description: If GetBase(x) is null, throw ReferenceError +---*/ + +//CHECK#1 +try { + x == 1; + throw new Test262Error('#1.1: x == 1 throw ReferenceError. Actual: ' + (x == 1)); +} +catch (e) { + if ((e instanceof ReferenceError) !== true) { + throw new Test262Error('#1.2: x == 1 throw ReferenceError. Actual: ' + (e)); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A2.1_T3.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A2.1_T3.js new file mode 100644 index 0000000000..4f38543299 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A2.1_T3.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 == y uses GetValue +es5id: 11.9.1_A2.1_T3 +description: If GetBase(y) is null, throw ReferenceError +---*/ + +//CHECK#1 +try { + 1 == y; + throw new Test262Error('#1.1: 1 == y throw ReferenceError. Actual: ' + (1 == y)); +} +catch (e) { + if ((e instanceof ReferenceError) !== true) { + throw new Test262Error('#1.2: 1 == y throw ReferenceError. Actual: ' + (e)); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A2.4_T1.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A2.4_T1.js new file mode 100644 index 0000000000..3cf581ebde --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A2.4_T1.js @@ -0,0 +1,22 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: First expression is evaluated first, and then second expression +es5id: 11.9.1_A2.4_T1 +description: Checking with "=" +---*/ + +//CHECK#1 +var x = 0; +if (((x = 1) == x) !== true) { + throw new Test262Error('#1: var x = 0; ((x = 1) == x) === true'); +} + +//CHECK#2 +var x = 0; +if ((x == (x = 1)) !== false) { + throw new Test262Error('#2: var x = 0; (x == (x = 1)) === false'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A2.4_T2.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A2.4_T2.js new file mode 100644 index 0000000000..8227853598 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A2.4_T2.js @@ -0,0 +1,26 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: First expression is evaluated first, and then second expression +es5id: 11.9.1_A2.4_T2 +description: Checking with "throw" +---*/ + +//CHECK#1 +var x = function () { throw "x"; }; +var y = function () { throw "y"; }; +try { + x() == y(); + throw new Test262Error('#1.1: var x = function () { throw "x"; }; var y = function () { throw "y"; }; x() == y() throw "x". Actual: ' + (x() == y())); +} catch (e) { + if (e === "y") { + throw new Test262Error('#1.2: First expression is evaluated first, and then second expression'); + } else { + if (e !== "x") { + throw new Test262Error('#1.3: var x = function () { throw "x"; }; var y = function () { throw "y"; }; x() == y() throw "x". Actual: ' + (e)); + } + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A2.4_T3.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A2.4_T3.js new file mode 100644 index 0000000000..4b369e3840 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A2.4_T3.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: First expression is evaluated first, and then second expression +es5id: 11.9.1_A2.4_T3 +description: Checking with undeclarated variables +---*/ + +//CHECK#1 +try { + x == (x = 1); + throw new Test262Error('#1.1: x == (x = 1) throw ReferenceError. Actual: ' + (x == (x = 1))); +} +catch (e) { + if ((e instanceof ReferenceError) !== true) { + throw new Test262Error('#1.2: x == (x = 1) throw ReferenceError. Actual: ' + (e)); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A2.4_T4.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A2.4_T4.js new file mode 100644 index 0000000000..ed9e99302f --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A2.4_T4.js @@ -0,0 +1,16 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: First expression is evaluated first, and then second expression +es5id: 11.9.1_A2.4_T4 +description: Checking with undeclarated variables +flags: [noStrict] +---*/ + +//CHECK#1 +if (((y = 1) == y) !== true) { + throw new Test262Error('#1: ((y = 1) == y) === true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A3.1.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A3.1.js new file mode 100644 index 0000000000..97ec8afe5c --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A3.1.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: | + Return true, if x and y are both true or both false; otherwise, return + false +es5id: 11.9.1_A3.1 +description: x and y are boolean primitives +---*/ + +//CHECK#1 +if ((true == true) !== true) { + throw new Test262Error('#1: (true == true) === true'); +} + +//CHECK#2 +if ((false == false) !== true) { + throw new Test262Error('#2: (false == false) === true'); +} + +//CHECK#3 +if ((true == false) !== false) { + throw new Test262Error('#3: (true == false) === false'); +} + +//CHECK#4 +if ((false == true) !== false) { + throw new Test262Error('#4: (false == true) === false'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A3.2.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A3.2.js new file mode 100644 index 0000000000..3bb1ae9192 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A3.2.js @@ -0,0 +1,22 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If Type(x) is Boolean and Type(y) is Number, + return the result of comparison ToNumber(x) == y +es5id: 11.9.1_A3.2 +description: x is primitive boolean, y is primitive number +---*/ + +//CHECK#1 +if ((true == 1) !== true) { + throw new Test262Error('#1: (true == 1) === true'); +} + +//CHECK#2 +if ((false == "0") !== true) { + throw new Test262Error('#2: (false == "0") === true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A3.3.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A3.3.js new file mode 100644 index 0000000000..bd434194f0 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A3.3.js @@ -0,0 +1,22 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If Type(y) is Number and Type(y) is Boolean, + return the result of comparison x == ToNumber(y) +es5id: 11.9.1_A3.3 +description: x is primitive number, y is primitive boolean +---*/ + +//CHECK#1 +if ((0 == false) !== true) { + throw new Test262Error('#1: (0 == false) === true'); +} + +//CHECK#2 +if (("1" == true) !== true) { + throw new Test262Error('#2: ("1" == true) === true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A4.1_T1.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A4.1_T1.js new file mode 100644 index 0000000000..2d5dfa9fe1 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A4.1_T1.js @@ -0,0 +1,55 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: If x or y is NaN, return false +es5id: 11.9.1_A4.1_T1 +description: x is NaN +---*/ + +//CHECK#1 +if ((Number.NaN == true) !== false) { + throw new Test262Error('#1: (NaN == true) === false'); +} + +//CHECK#2 +if ((Number.NaN == 1) !== false) { + throw new Test262Error('#2: (NaN == 1) === false'); +} + +//CHECK#3 +if ((Number.NaN == Number.NaN) !== false) { + throw new Test262Error('#3: (NaN == NaN) === false'); +} + +//CHECK#4 +if ((Number.NaN == Number.POSITIVE_INFINITY) !== false) { + throw new Test262Error('#4: (NaN == +Infinity) === false'); +} + +//CHECK#5 +if ((Number.NaN == Number.NEGATIVE_INFINITY) !== false) { + throw new Test262Error('#5: (NaN == -Infinity) === false'); +} + +//CHECK#6 +if ((Number.NaN == Number.MAX_VALUE) !== false) { + throw new Test262Error('#6: (NaN == Number.MAX_VALUE) === false'); +} + +//CHECK#7 +if ((Number.NaN == Number.MIN_VALUE) !== false) { + throw new Test262Error('#7: (NaN == Number.MIN_VALUE) === false'); +} + +//CHECK#8 +if ((Number.NaN == "string") !== false) { + throw new Test262Error('#8: (NaN == "string") === false'); +} + +//CHECK#9 +if ((Number.NaN == new Object()) !== false) { + throw new Test262Error('#9: (NaN == new Object()) === false'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A4.1_T2.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A4.1_T2.js new file mode 100644 index 0000000000..d8ea1f34b9 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A4.1_T2.js @@ -0,0 +1,55 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: If x or y is NaN, return false +es5id: 11.9.1_A4.1_T2 +description: y is NaN +---*/ + +//CHECK#1 +if ((true == Number.NaN) !== false) { + throw new Test262Error('#1: (true == NaN) === false'); +} + +//CHECK#2 +if ((-1 == Number.NaN) !== false) { + throw new Test262Error('#2: (-1 == NaN) === false'); +} + +//CHECK#3 +if ((Number.NaN == Number.NaN) !== false) { + throw new Test262Error('#3: (NaN == NaN) === false'); +} + +//CHECK#4 +if ((Number.POSITIVE_INFINITY == Number.NaN) !== false) { + throw new Test262Error('#4: (+Infinity == NaN) === false'); +} + +//CHECK#5 +if ((Number.NEGATIVE_INFINITY == Number.NaN) !== false) { + throw new Test262Error('#5: (-Infinity == NaN) === false'); +} + +//CHECK#6 +if ((Number.MAX_VALUE == Number.NaN) !== false) { + throw new Test262Error('#6: (Number.MAX_VALUE == NaN) === false'); +} + +//CHECK#7 +if ((Number.MIN_VALUE == Number.NaN) !== false) { + throw new Test262Error('#7: (Number.MIN_VALUE == NaN) === false'); +} + +//CHECK#8 +if (("string" == Number.NaN) !== false) { + throw new Test262Error('#8: ("string" == NaN) === false'); +} + +//CHECK#9 +if ((new Object() == Number.NaN) !== false) { + throw new Test262Error('#9: (new Object() == NaN) === false'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A4.2.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A4.2.js new file mode 100644 index 0000000000..8aa8c6a508 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A4.2.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: If x is +0(-0) and y is -0(+0), return true +es5id: 11.9.1_A4.2 +description: Checking all combinations +---*/ + +//CHECK#1 +if ((+0 == -0) !== true) { + throw new Test262Error('#1: (+0 == -0) === true'); +} + +//CHECK#2 +if ((-0 == +0) !== true) { + throw new Test262Error('#2: (-0 == +0) === true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A4.3.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A4.3.js new file mode 100644 index 0000000000..d41ca431db --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A4.3.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: | + Type(x) and Type(y) are Number-s minus NaN, +0, -0. + Return true, if x is the same number value as y; otherwise, return false +es5id: 11.9.1_A4.3 +description: x and y are primitive numbers +---*/ + +//CHECK#1 +if ((Number.POSITIVE_INFINITY == Number.POSITIVE_INFINITY) !== true) { + throw new Test262Error('#1: (+Infinity == +Infinity) === true'); +} + +//CHECK#2 +if ((Number.NEGATIVE_INFINITY == Number.NEGATIVE_INFINITY) !== true) { + throw new Test262Error('#2: (-Infinity == -Infinity) === true'); +} + +//CHECK#3 +if ((Number.POSITIVE_INFINITY == -Number.NEGATIVE_INFINITY) !== true) { + throw new Test262Error('#3: (+Infinity == -(-Infinity)) === true'); +} + +//CHECK#4 +if ((1 == 0.999999999999) !== false) { + throw new Test262Error('#4: (1 == 0.999999999999) === false'); +} + +//CHECK#5 +if ((1.0 == 1) !== true) { + throw new Test262Error('#5: (1.0 == 1) === true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A5.1.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A5.1.js new file mode 100644 index 0000000000..6197e3c718 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A5.1.js @@ -0,0 +1,47 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + Type(x) and Type(y) are String-s. + Return true, if x and y are exactly the same sequence of characters; otherwise, return false +es5id: 11.9.1_A5.1 +description: x and y are primitive string +---*/ + +//CHECK#1 +if (("" == "") !== true) { + throw new Test262Error('#1: ("" == "") === true'); +} + +//CHECK#2 +if ((" " == " ") !== true) { + throw new Test262Error('#2: " (" == " ") === true'); +} + +//CHECK#3 +if ((" " == "") !== false) { + throw new Test262Error('#3: " (" == "") === false'); +} + +//CHECK#4 +if (("string" == "string") !== true) { + throw new Test262Error('#4: ("string" == "string") === true'); +} + +//CHECK#5 +if ((" string" == "string ") !== false) { + throw new Test262Error('#5: (" string" == "string ") === false'); +} + +//CHECK#6 +if (("1.0" == "1") !== false) { + throw new Test262Error('#6: ("1.0" == "1") === false'); +} + +//CHECK#7 +if (("0xff" == "255") !== false) { + throw new Test262Error('#7: ("0xff" == "255") === false'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A5.2.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A5.2.js new file mode 100644 index 0000000000..b4bd9fcc68 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A5.2.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: | + If Type(x) is Number and Type(y) is String, + return the result of comparison x == ToNumber(y) +es5id: 11.9.1_A5.2 +description: x is primitive number, y is primitive string +---*/ + +//CHECK#1 +if ((1 == "1") !== true) { + throw new Test262Error('#1: (1 == "1") === true'); +} + +//CHECK#2 +if ((1.100 == "+1.10") !== true) { + throw new Test262Error('#2: (1.100 == "+1.10") === true'); +} + +//CHECK#3 +if ((1 == "true") !== false) { + throw new Test262Error('#3: (1 == "true") === false'); +} + +//CHECK#4 +if ((255 == "0xff") !== true) { + throw new Test262Error('#4: (255 == "0xff") === true'); +} + +//CHECK#5 +if ((0 == "") !== true) { + throw new Test262Error('#5: (0 == "") === true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A5.3.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A5.3.js new file mode 100644 index 0000000000..411c227932 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A5.3.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: | + If Type(x) is String and Type(y) is Number, + return the result of comparison ToNumber(x) == y +es5id: 11.9.1_A5.3 +description: x is primitive string, y is primitive number +---*/ + +//CHECK#1 +if (("-1" == -1) !== true) { + throw new Test262Error('#1: ("-1" == -1) === true'); +} + +//CHECK#2 +if (("-1.100" == -1.10) !== true) { + throw new Test262Error('#2: ("-1.100" == -1.10) === true'); +} + +//CHECK#3 +if (("false" == 0) !== false) { + throw new Test262Error('#3: ("false" == 0) === false'); +} + +//CHECK#4 +if (("5e-324" == 5e-324) !== true) { + throw new Test262Error('#4: ("5e-324" == 5e-324) === true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A6.1.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A6.1.js new file mode 100644 index 0000000000..f0708833b2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A6.1.js @@ -0,0 +1,40 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: If Type(x) as well as Type(y) is undefined or null, return true +es5id: 11.9.1_A6.1 +description: Checking all combinations +---*/ + +//CHECK#1 +if ((undefined == undefined) !== true) { + throw new Test262Error('#1: (undefined == undefined) === true'); +} + +//CHECK#2 +if ((void 0 == undefined) !== true) { + throw new Test262Error('#2: (void 0 == undefined) === true'); +} + +//CHECK#3 +if ((undefined == eval("var x")) !== true) { + throw new Test262Error('#3: (undefined == eval("var x")) === true'); +} + +//CHECK#4 +if ((undefined == null) !== true) { + throw new Test262Error('#4: (undefined == null) === true'); +} + +//CHECK#5 +if ((null == void 0) !== true) { + throw new Test262Error('#5: (null == void 0) === true'); +} + +//CHECK#6 +if ((null == null) !== true) { + throw new Test262Error('#6: (null == null) === true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A6.2_T1.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A6.2_T1.js new file mode 100644 index 0000000000..bf7ca5b145 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A6.2_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: If one expression is undefined or null and another is not, return false +es5id: 11.9.1_A6.2_T1 +description: x is null or undefined, y is not +---*/ + +//CHECK#1 +if ((undefined == true) !== false) { + throw new Test262Error('#1: (undefined == true) === false'); +} + +//CHECK#2 +if ((undefined == 0) !== false) { + throw new Test262Error('#2: (undefined == 0) === false'); +} + +//CHECK#3 +if ((undefined == "undefined") !== false) { + throw new Test262Error('#3: (undefined == "undefined") === false'); +} + +//CHECK#4 +if ((undefined == {}) !== false) { + throw new Test262Error('#4: (undefined == {}) === false'); +} + +//CHECK#5 +if ((null == false) !== false) { + throw new Test262Error('#5: (null == false) === false'); +} + +//CHECK#6 +if ((null == 0) !== false) { + throw new Test262Error('#6: (null == 0) === false'); +} + +//CHECK#7 +if ((null == "null") !== false) { + throw new Test262Error('#7: (null == "null") === false'); +} + +//CHECK#8 +if ((null == {}) !== false) { + throw new Test262Error('#8: (null == {}) === false'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A6.2_T2.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A6.2_T2.js new file mode 100644 index 0000000000..c80a3934f1 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A6.2_T2.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: If one expression is undefined or null and another is not, return false +es5id: 11.9.1_A6.2_T2 +description: y is null or undefined, x is not +---*/ + +//CHECK#1 +if ((false == undefined) !== false) { + throw new Test262Error('#1: (false == undefined) === false'); +} + +//CHECK#2 +if ((Number.NaN == undefined) !== false) { + throw new Test262Error('#2: (Number.NaN == undefined) === false'); +} + +//CHECK#3 +if (("undefined" == undefined) !== false) { + throw new Test262Error('#3: ("undefined" == undefined) === false'); +} + +//CHECK#4 +if (({} == undefined) !== false) { + throw new Test262Error('#4: ({} == undefined) === false'); +} + +//CHECK#5 +if ((false == null) !== false) { + throw new Test262Error('#5: (false == null) === false'); +} + +//CHECK#6 +if ((0 == null) !== false) { + throw new Test262Error('#6: (0 == null) === false'); +} + +//CHECK#7 +if (("null" == null) !== false) { + throw new Test262Error('#7: ("null" == null) === false'); +} + +//CHECK#8 +if (({} == null) !== false) { + throw new Test262Error('#8: ({} == null) === false'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.1.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.1.js new file mode 100644 index 0000000000..e76333d376 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.1.js @@ -0,0 +1,57 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + Type(x) and Type(y) are Object-s. + Return true, if x and y are references to the same Object; otherwise, return false +es5id: 11.9.1_A7.1 +description: > + Checking Boolean object, Number object, String object, Object + object +---*/ + +//CHECK#1 +if ((new Boolean(true) == new Boolean(true)) !== false) { + throw new Test262Error('#1: (new Boolean(true) == new Boolean(true)) === false'); +} + +//CHECK#2 +if ((new Number(1) == new Number(1)) !== false) { + throw new Test262Error('#2: (new Number(1) == new Number(1)) === false'); +} + +//CHECK#3 +if ((new String("x") == new String("x")) !== false) { + throw new Test262Error('#3: (new String("x") == new String("x")) === false'); +} + +//CHECK#4 +if ((new Object() == new Object()) !== false) { + throw new Test262Error('#4: (new Object() == new Object()) === false'); +} + +//CHECK#5 +var x, y; +x = {}; +y = x; +if ((x == y) !== true) { + throw new Test262Error('#5: x = {}; y = x; (x == y) === true'); +} + +//CHECK#6 +if ((new Boolean(true) == new Number(1)) !== false) { + throw new Test262Error('#6 (new Boolean(true) == new Number(1)) === false'); +} + +//CHECK#7 +if ((new Number(1) == new String("1")) !== false) { + throw new Test262Error('#7: (new Number(1) == new String("1")) === false'); +} + +//CHECK#8 +if ((new String("1") == new Boolean(true)) !== false) { + throw new Test262Error('#8: (new String("x") == new Boolean(true)) === false'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.2.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.2.js new file mode 100644 index 0000000000..f1ab3cc4ac --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.2.js @@ -0,0 +1,27 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If Type(x) is Object and Type(y) is Boolean, + return ToPrimitive(x) == y +es5id: 11.9.1_A7.2 +description: x is object, y is primitive boolean +---*/ + +//CHECK#1 +if ((new Boolean(true) == true) !== true) { + throw new Test262Error('#1: (new Boolean(true) == true) === true'); +} + +//CHECK#2 +if ((new Number(1) == true) !== true) { + throw new Test262Error('#2: (new Number(1) == true) === true'); +} + +//CHECK#3 +if ((new String("1") == true) !== true) { + throw new Test262Error('#3: (new String("1") == true) === true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.3.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.3.js new file mode 100644 index 0000000000..1286eea598 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.3.js @@ -0,0 +1,27 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If Type(x) is Boolean and Type(y) is Object, + return x == ToPrimitive(y) +es5id: 11.9.1_A7.3 +description: y is object, x is primitive boolean +---*/ + +//CHECK#1 +if ((true == new Boolean(true)) !== true) { + throw new Test262Error('#1: (true == new Boolean(true)) === true'); +} + +//CHECK#2 +if ((true == new Number(1)) !== true) { + throw new Test262Error('#2: (true == new Number(1)) === true'); +} + +//CHECK#3 +if ((true == new String("+1")) !== true) { + throw new Test262Error('#3: (true == new String("+1")) === true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.4.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.4.js new file mode 100644 index 0000000000..efbe60f019 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.4.js @@ -0,0 +1,27 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If Type(x) is Object and Type(y) is Number, + return ToPrimitive(x) == y +es5id: 11.9.1_A7.4 +description: x is object, y is primitive number +---*/ + +//CHECK#1 +if ((new Boolean(true) == 1) !== true) { + throw new Test262Error('#1: (new Boolean(true) == 1) === true'); +} + +//CHECK#2 +if ((new Number(-1) == -1) !== true) { + throw new Test262Error('#2: (new Number(-1) == -1) === true'); +} + +//CHECK#3 +if ((new String("-1") == -1) !== true) { + throw new Test262Error('#3: (new String("-1") == -1) === true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.5.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.5.js new file mode 100644 index 0000000000..f96c7cffa2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.5.js @@ -0,0 +1,27 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If Type(x) is Number and Type(y) is Object, + return x == ToPrimitive(y) +es5id: 11.9.1_A7.5 +description: y is object, x is primitive number +---*/ + +//CHECK#1 +if ((1 == new Boolean(true)) !== true) { + throw new Test262Error('#1: (1 == new Boolean(true)) === true'); +} + +//CHECK#2 +if ((-1 == new Number(-1)) !== true) { + throw new Test262Error('#2: (-1 == new Number(-1)) === true'); +} + +//CHECK#3 +if ((-1 == new String("-1")) !== true) { + throw new Test262Error('#3: (-1 == new String("-1")) === true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.6.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.6.js new file mode 100644 index 0000000000..d4e0801a64 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.6.js @@ -0,0 +1,27 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If Type(x) is Object and Type(y) is String, + return ToPrimitive(x) == y +es5id: 11.9.1_A7.6 +description: x is object, y is primitive string +---*/ + +//CHECK#1 +if ((new Boolean(true) == "1") !== true) { + throw new Test262Error('#1: (new Boolean(true) == "1") === true'); +} + +//CHECK#2 +if ((new Number(-1) == "-1") !== true) { + throw new Test262Error('#2: (new Number(-1) == "-1") === true'); +} + +//CHECK#3 +if ((new String("x") == "x") !== true) { + throw new Test262Error('#3: (new String("x") == "x") === true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.7.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.7.js new file mode 100644 index 0000000000..3351781822 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.7.js @@ -0,0 +1,27 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If Type(x) is String and Type(y) is Object, + return x == ToPrimitive(y) +es5id: 11.9.1_A7.7 +description: y is object, x is primitive string +---*/ + +//CHECK#1 +if (("1" == new Boolean(true)) !== true) { + throw new Test262Error('#1: ("1" == new Boolean(true)) === true'); +} + +//CHECK#2 +if (("-1" == new Number(-1)) !== true) { + throw new Test262Error('#2: ("-1" == new Number(-1)) === true'); +} + +//CHECK#3 +if (("x" == new String("x")) !== true) { + throw new Test262Error('#3: ("x" == new String("x")) === true'); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.8.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.8.js new file mode 100644 index 0000000000..4b4e37f3b4 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.8.js @@ -0,0 +1,77 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If Type(x) is Object and Type(y) is primitive type, + return ToPrimitive(x) == y +es5id: 11.9.1_A7.8 +description: x is object, y is primtitive +---*/ + +//CHECK#1 +if (({valueOf: function() {return 1}} == true) !== true) { + throw new Test262Error('#1: ({valueOf: function() {return 1}} == true) === true'); +} + +//CHECK#2 +if (({valueOf: function() {return 1}, toString: function() {return 0}} == 1) !== true) { + throw new Test262Error('#2: ({valueOf: function() {return 1}, toString: function() {return 0}} == 1) === true'); +} + +//CHECK#3 +if (({valueOf: function() {return 1}, toString: function() {return {}}} == "+1") !== true) { + throw new Test262Error('#3: ({valueOf: function() {return 1}, toString: function() {return {}}} == "+1") === true'); +} + +//CHECK#4 +try { + if (({valueOf: function() {return "+1"}, toString: function() {throw "error"}} == true) !== true) { + throw new Test262Error('#4.1: ({valueOf: function() {return "+1"}, toString: function() {throw "error"}} == true) === true'); + } +} +catch (e) { + if (e === "error") { + throw new Test262Error('#4.2: ({valueOf: function() {return "+1"}, toString: function() {throw "error"}} == true) not throw "error"'); + } else { + throw new Test262Error('#4.3: ({valueOf: function() {return "+1"}, toString: function() {throw "error"}} == true) not throw Error. Actual: ' + (e)); + } +} + +//CHECK#5 +if (({toString: function() {return "+1"}} == 1) !== true) { + throw new Test262Error('#5: ({toString: function() {return "+1"}} == 1) === true'); +} + +//CHECK#6 +if (({valueOf: function() {return {}}, toString: function() {return "+1"}} == "1") !== false) { + throw new Test262Error('#6.1: ({valueOf: function() {return {}}, toString: function() {return "+1"}} == "1") === false'); +} else { + if (({valueOf: function() {return {}}, toString: function() {return "+1"}} == "+1") !== true) { + throw new Test262Error('#6.2: ({valueOf: function() {return {}}, toString: function() {return "+1"}} == "+1") === true'); + } +} + +//CHECK#7 +try { + ({valueOf: function() {throw "error"}, toString: function() {return 1}} == 1); + throw new Test262Error('#7.1: ({valueOf: function() {throw "error"}, toString: function() {return 1}} == 1) throw "error". Actual: ' + (({valueOf: function() {throw "error"}, toString: function() {return 1}} == 1))); +} +catch (e) { + if (e !== "error") { + throw new Test262Error('#7.2: ({valueOf: function() {throw "error"}, toString: function() {return 1}} == 1) throw "error". Actual: ' + (e)); + } +} + +//CHECK#8 +try { + ({valueOf: function() {return {}}, toString: function() {return {}}} == 1); + throw new Test262Error('#8.1: ({valueOf: function() {return {}}, toString: function() {return {}}} == 1) throw TypeError. Actual: ' + (({valueOf: function() {return {}}, toString: function() {return {}}} == 1))); +} +catch (e) { + if ((e instanceof TypeError) !== true) { + throw new Test262Error('#8.2: ({valueOf: function() {return {}}, toString: function() {return {}}} == 1) throw TypeError. Actual: ' + (e)); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.9.js b/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.9.js new file mode 100644 index 0000000000..6b858ef267 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S11.9.1_A7.9.js @@ -0,0 +1,77 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + If Type(x) is primitive type and Type(y) is Object, + return x == ToPrimitive(y) +es5id: 11.9.1_A7.9 +description: y is object, x is primtitive +---*/ + +//CHECK#1 +if ((true == {valueOf: function() {return 1}}) !== true) { + throw new Test262Error('#1: (true == {valueOf: function() {return 1}}) === true'); +} + +//CHECK#2 +if ((1 == {valueOf: function() {return 1}, toString: function() {return 0}}) !== true) { + throw new Test262Error('#2: (1 == {valueOf: function() {return 1}, toString: function() {return 0}}) === true'); +} + +//CHECK#3 +if (("+1" == {valueOf: function() {return 1}, toString: function() {return {}}}) !== true) { + throw new Test262Error('#3: ("+1" == {valueOf: function() {return 1}, toString: function() {return {}}}) === true'); +} + +//CHECK#4 +try { + if ((true == {valueOf: function() {return "+1"}, toString: function() {throw "error"}}) !== true) { + throw new Test262Error('#4.1: (true == {valueOf: function() {return "+1"}, toString: function() {throw "error"}}) === true'); + } +} +catch (e) { + if (e === "error") { + throw new Test262Error('#4.2: (true == {valueOf: function() {return "+1"}, toString: function() {throw "error"}}) not throw "error"'); + } else { + throw new Test262Error('#4.3: (true == {valueOf: function() {return "+1"}, toString: function() {throw "error"}}) not throw Error. Actual: ' + (e)); + } +} + +//CHECK#5 +if ((1 == {toString: function() {return "+1"}}) !== true) { + throw new Test262Error('#5: (1 == {toString: function() {return "+1"}}) === true'); +} + +//CHECK#6 +if (("1" == {valueOf: function() {return {}}, toString: function() {return "+1"}}) !== false) { + throw new Test262Error('#6.1: ("1" == {valueOf: function() {return {}}, toString: function() {return "+1"}}) === false'); +} else { + if (("+1" == {valueOf: function() {return {}}, toString: function() {return "+1"}}) !== true) { + throw new Test262Error('#6.2: ("+1" == {valueOf: function() {return {}}, toString: function() {return "+1"}}) === true'); + } +} + +//CHECK#7 +try { + (1 == {valueOf: function() {throw "error"}, toString: function() {return 1}}); + throw new Test262Error('#7.1: (1 == {valueOf: function() {throw "error"}, toString: function() {return 1}}) throw "error". Actual: ' + ((1 == {valueOf: function() {throw "error"}, toString: function() {return 1}}))); +} +catch (e) { + if (e !== "error") { + throw new Test262Error('#7.2: (1 == {valueOf: function() {throw "error"}, toString: function() {return 1}}) throw "error". Actual: ' + (e)); + } +} + +//CHECK#8 +try { + (1 == {valueOf: function() {return {}}, toString: function() {return {}}}); + throw new Test262Error('#8.1: (1 == {valueOf: function() {return {}}, toString: function() {return {}}}) throw TypeError. Actual: ' + ((1 == {valueOf: function() {return {}}, toString: function() {return {}}}))); +} +catch (e) { + if ((e instanceof TypeError) !== true) { + throw new Test262Error('#8.2: (1 == {valueOf: function() {return {}}, toString: function() {return {}}}) throw TypeError. Actual: ' + (e)); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/S9.1_A1_T3.js b/js/src/tests/test262/language/expressions/equals/S9.1_A1_T3.js new file mode 100644 index 0000000000..00fa3e8416 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/S9.1_A1_T3.js @@ -0,0 +1,26 @@ +// Copyright 2009 the Sputnik authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +info: | + Result of primitive conversion from object is a default value for the + Object +es5id: 9.1_A1_T3 +description: > + Using operator "+". This operator firstly calls ToPrimitive and + then calls ToString or ToNumber +---*/ + +// CHECK#1 +var object = {valueOf: function() {return 1}, toString: function() {return 0}}; +if (object + "" !== "1") { + throw new Test262Error('#1: var object = {valueOf: function() {return 1}, toString: function() {return 0}}; object + "" === "1". Actual: ' + (object + "")); +} + +// CHECK#2 +var object = {valueOf: function() {return "1"}, toString: function() {return 0}}; +if (object + 0 !== "10") { + throw new Test262Error('#2: var object = {valueOf: function() {return "1"}, toString: function() {return 0}}; object + 0 === "10". Actual: ' + (object + 0)); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/bigint-and-bigint.js b/js/src/tests/test262/language/expressions/equals/bigint-and-bigint.js new file mode 100644 index 0000000000..b5a49281e0 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/bigint-and-bigint.js @@ -0,0 +1,173 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Non-strict equality comparison of BigInt values +esid: sec-abstract-equality-comparison +info: | + 1. If Type(x) is the same as Type(y), then + a. Return the result of performing Strict Equality Comparison x === y. + + sec-numeric-types-bigint-equal + BigInt::equal (x, y) + + The abstract operation BigInt::equal with two arguments x and y of BigInt type returns true if x and y have the same mathematical integer value and false otherwise. + +features: [BigInt] +---*/ +assert.sameValue(0n == 0n, true, 'The result of (0n == 0n) is true'); +assert.sameValue(1n == 1n, true, 'The result of (1n == 1n) is true'); +assert.sameValue(-1n == -1n, true, 'The result of (-1n == -1n) is true'); +assert.sameValue(0n == -0n, true, 'The result of (0n == -0n) is true'); +assert.sameValue(-0n == 0n, true, 'The result of (-0n == 0n) is true'); +assert.sameValue(0n == 1n, false, 'The result of (0n == 1n) is false'); +assert.sameValue(1n == 0n, false, 'The result of (1n == 0n) is false'); +assert.sameValue(0n == -1n, false, 'The result of (0n == -1n) is false'); +assert.sameValue(-1n == 0n, false, 'The result of (-1n == 0n) is false'); +assert.sameValue(1n == -1n, false, 'The result of (1n == -1n) is false'); +assert.sameValue(-1n == 1n, false, 'The result of (-1n == 1n) is false'); + +assert.sameValue( + 0x1fffffffffffff01n == 0x1fffffffffffff01n, + true, + 'The result of (0x1fffffffffffff01n == 0x1fffffffffffff01n) is true' +); + +assert.sameValue( + 0x1fffffffffffff01n == 0x1fffffffffffff02n, + false, + 'The result of (0x1fffffffffffff01n == 0x1fffffffffffff02n) is false' +); + +assert.sameValue( + 0x1fffffffffffff02n == 0x1fffffffffffff01n, + false, + 'The result of (0x1fffffffffffff02n == 0x1fffffffffffff01n) is false' +); + +assert.sameValue( + -0x1fffffffffffff01n == -0x1fffffffffffff01n, + true, + 'The result of (-0x1fffffffffffff01n == -0x1fffffffffffff01n) is true' +); + +assert.sameValue( + -0x1fffffffffffff01n == -0x1fffffffffffff02n, + false, + 'The result of (-0x1fffffffffffff01n == -0x1fffffffffffff02n) is false' +); + +assert.sameValue( + -0x1fffffffffffff02n == -0x1fffffffffffff01n, + false, + 'The result of (-0x1fffffffffffff02n == -0x1fffffffffffff01n) is false' +); + +assert.sameValue( + 0x10000000000000000n == 0n, + false, + 'The result of (0x10000000000000000n == 0n) is false' +); + +assert.sameValue( + 0n == 0x10000000000000000n, + false, + 'The result of (0n == 0x10000000000000000n) is false' +); + +assert.sameValue( + 0x10000000000000000n == 1n, + false, + 'The result of (0x10000000000000000n == 1n) is false' +); + +assert.sameValue( + 1n == 0x10000000000000000n, + false, + 'The result of (1n == 0x10000000000000000n) is false' +); + +assert.sameValue( + 0x10000000000000000n == -1n, + false, + 'The result of (0x10000000000000000n == -1n) is false' +); + +assert.sameValue( + -1n == 0x10000000000000000n, + false, + 'The result of (-1n == 0x10000000000000000n) is false' +); + +assert.sameValue( + 0x10000000000000001n == 0n, + false, + 'The result of (0x10000000000000001n == 0n) is false' +); + +assert.sameValue( + 0n == 0x10000000000000001n, + false, + 'The result of (0n == 0x10000000000000001n) is false' +); + +assert.sameValue( + -0x10000000000000000n == 0n, + false, + 'The result of (-0x10000000000000000n == 0n) is false' +); + +assert.sameValue( + 0n == -0x10000000000000000n, + false, + 'The result of (0n == -0x10000000000000000n) is false' +); + +assert.sameValue( + -0x10000000000000000n == 1n, + false, + 'The result of (-0x10000000000000000n == 1n) is false' +); + +assert.sameValue( + 1n == -0x10000000000000000n, + false, + 'The result of (1n == -0x10000000000000000n) is false' +); + +assert.sameValue( + -0x10000000000000000n == -1n, + false, + 'The result of (-0x10000000000000000n == -1n) is false' +); + +assert.sameValue( + -1n == -0x10000000000000000n, + false, + 'The result of (-1n == -0x10000000000000000n) is false' +); + +assert.sameValue( + -0x10000000000000001n == 0n, + false, + 'The result of (-0x10000000000000001n == 0n) is false' +); + +assert.sameValue( + 0n == -0x10000000000000001n, + false, + 'The result of (0n == -0x10000000000000001n) is false' +); + +assert.sameValue( + 0x10000000000000000n == 0x100000000n, + false, + 'The result of (0x10000000000000000n == 0x100000000n) is false' +); + +assert.sameValue( + 0x100000000n == 0x10000000000000000n, + false, + 'The result of (0x100000000n == 0x10000000000000000n) is false' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/bigint-and-boolean.js b/js/src/tests/test262/language/expressions/equals/bigint-and-boolean.js new file mode 100644 index 0000000000..6e330d3653 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/bigint-and-boolean.js @@ -0,0 +1,33 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Non-strict equality comparison of BigInt and Boolean values +esid: sec-abstract-equality-comparison +info: | + 8. If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y. + 9. If Type(y) is Boolean, return the result of the comparison x == ToNumber(y). + ... + 12. If Type(x) is BigInt and Type(y) is Number, or if Type(x) is Number and Type(y) is BigInt, + ... + b. If the mathematical value of x is equal to the mathematical value of y, return true, otherwise return false. + +features: [BigInt] +---*/ +assert.sameValue(-1n == false, false, 'The result of (-1n == false) is false'); +assert.sameValue(false == -1n, false, 'The result of (false == -1n) is false'); +assert.sameValue(-1n == true, false, 'The result of (-1n == true) is false'); +assert.sameValue(true == -1n, false, 'The result of (true == -1n) is false'); +assert.sameValue(0n == false, true, 'The result of (0n == false) is true'); +assert.sameValue(false == 0n, true, 'The result of (false == 0n) is true'); +assert.sameValue(0n == true, false, 'The result of (0n == true) is false'); +assert.sameValue(true == 0n, false, 'The result of (true == 0n) is false'); +assert.sameValue(1n == false, false, 'The result of (1n == false) is false'); +assert.sameValue(false == 1n, false, 'The result of (false == 1n) is false'); +assert.sameValue(1n == true, true, 'The result of (1n == true) is true'); +assert.sameValue(true == 1n, true, 'The result of (true == 1n) is true'); +assert.sameValue(2n == false, false, 'The result of (2n == false) is false'); +assert.sameValue(false == 2n, false, 'The result of (false == 2n) is false'); +assert.sameValue(2n == true, false, 'The result of (2n == true) is false'); +assert.sameValue(true == 2n, false, 'The result of (true == 2n) is false'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/bigint-and-incomparable-primitive.js b/js/src/tests/test262/language/expressions/equals/bigint-and-incomparable-primitive.js new file mode 100644 index 0000000000..b0c6f900b1 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/bigint-and-incomparable-primitive.js @@ -0,0 +1,26 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Non-strict equality comparison of BigInt and miscellaneous primitive values +esid: sec-equality-operators-runtime-semantics-evaluation +info: | + EqualityExpression : EqualityExpression == RelationalExpression + ... + 5. Return the result of performing Abstract Equality Comparison rval == lval. + +features: [BigInt, Symbol] +---*/ +assert.sameValue(0n == undefined, false, 'The result of (0n == undefined) is false'); +assert.sameValue(undefined == 0n, false, 'The result of (undefined == 0n) is false'); +assert.sameValue(1n == undefined, false, 'The result of (1n == undefined) is false'); +assert.sameValue(undefined == 1n, false, 'The result of (undefined == 1n) is false'); +assert.sameValue(0n == null, false, 'The result of (0n == null) is false'); +assert.sameValue(null == 0n, false, 'The result of (null == 0n) is false'); +assert.sameValue(1n == null, false, 'The result of (1n == null) is false'); +assert.sameValue(null == 1n, false, 'The result of (null == 1n) is false'); +assert.sameValue(0n == Symbol('1'), false, 'The result of (0n == Symbol("1")) is false'); +assert.sameValue(Symbol('1') == 0n, false, 'The result of (Symbol("1") == 0n) is false'); +assert.sameValue(1n == Symbol('1'), false, 'The result of (1n == Symbol("1")) is false'); +assert.sameValue(Symbol('1') == 1n, false, 'The result of (Symbol("1") == 1n) is false'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/bigint-and-non-finite.js b/js/src/tests/test262/language/expressions/equals/bigint-and-non-finite.js new file mode 100644 index 0000000000..059bcb36d0 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/bigint-and-non-finite.js @@ -0,0 +1,31 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Non-strict equality comparison of BigInt and non-finite Number values +esid: sec-abstract-equality-comparison +info: | + 12. If Type(x) is BigInt and Type(y) is Number, or if Type(x) is Number and Type(y) is BigInt, + a. If x or y are any of NaN, +∞, or -∞, return false. + +features: [BigInt] +---*/ +assert.sameValue(0n == Infinity, false, 'The result of (0n == Infinity) is false'); +assert.sameValue(Infinity == 0n, false, 'The result of (Infinity == 0n) is false'); +assert.sameValue(1n == Infinity, false, 'The result of (1n == Infinity) is false'); +assert.sameValue(Infinity == 1n, false, 'The result of (Infinity == 1n) is false'); +assert.sameValue(-1n == Infinity, false, 'The result of (-1n == Infinity) is false'); +assert.sameValue(Infinity == -1n, false, 'The result of (Infinity == -1n) is false'); +assert.sameValue(0n == -Infinity, false, 'The result of (0n == -Infinity) is false'); +assert.sameValue(-Infinity == 0n, false, 'The result of (-Infinity == 0n) is false'); +assert.sameValue(1n == -Infinity, false, 'The result of (1n == -Infinity) is false'); +assert.sameValue(-Infinity == 1n, false, 'The result of (-Infinity == 1n) is false'); +assert.sameValue(-1n == -Infinity, false, 'The result of (-1n == -Infinity) is false'); +assert.sameValue(-Infinity == -1n, false, 'The result of (-Infinity == -1n) is false'); +assert.sameValue(0n == NaN, false, 'The result of (0n == NaN) is false'); +assert.sameValue(NaN == 0n, false, 'The result of (NaN == 0n) is false'); +assert.sameValue(1n == NaN, false, 'The result of (1n == NaN) is false'); +assert.sameValue(NaN == 1n, false, 'The result of (NaN == 1n) is false'); +assert.sameValue(-1n == NaN, false, 'The result of (-1n == NaN) is false'); +assert.sameValue(NaN == -1n, false, 'The result of (NaN == -1n) is false'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/bigint-and-number-extremes.js b/js/src/tests/test262/language/expressions/equals/bigint-and-number-extremes.js new file mode 100644 index 0000000000..22d56981f8 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/bigint-and-number-extremes.js @@ -0,0 +1,63 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Non-strict equality comparison of BigInt and large Number values +esid: sec-abstract-equality-comparison +info: | + 12. If Type(x) is BigInt and Type(y) is Number, or if Type(x) is Number and Type(y) is BigInt, + b. If the mathematical value of x is equal to the mathematical value of y, return true, otherwise return false. + +features: [BigInt] +---*/ +assert.sameValue(1n == Number.MAX_VALUE, false, 'The result of (1n == Number.MAX_VALUE) is false'); +assert.sameValue(Number.MAX_VALUE == 1n, false, 'The result of (Number.MAX_VALUE == 1n) is false'); + +assert.sameValue( + 1n == -Number.MAX_VALUE, + false, + 'The result of (1n == -Number.MAX_VALUE) is false' +); + +assert.sameValue( + -Number.MAX_VALUE == 1n, + false, + 'The result of (-Number.MAX_VALUE == 1n) is false' +); + +assert.sameValue( + 0xfffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn == Number.MAX_VALUE, + false, + 'The result of (0xfffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn == Number.MAX_VALUE) is false' +); + +assert.sameValue( + Number.MAX_VALUE == 0xfffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn, + false, + 'The result of (Number.MAX_VALUE == 0xfffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn) is false' +); + +assert.sameValue( + 0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n == Number.MAX_VALUE, + true, + 'The result of (0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n == Number.MAX_VALUE) is true' +); + +assert.sameValue( + Number.MAX_VALUE == 0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, + true, + 'The result of (Number.MAX_VALUE == 0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000n) is true' +); + +assert.sameValue( + 0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001n == Number.MAX_VALUE, + false, + 'The result of (0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001n == Number.MAX_VALUE) is false' +); + +assert.sameValue( + Number.MAX_VALUE == 0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001n, + false, + 'The result of (Number.MAX_VALUE == 0xfffffffffffff800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001n) is false' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/bigint-and-number.js b/js/src/tests/test262/language/expressions/equals/bigint-and-number.js new file mode 100644 index 0000000000..6a2ac3f831 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/bigint-and-number.js @@ -0,0 +1,53 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Non-strict equality comparison of BigInt and Number values +esid: sec-abstract-equality-comparison +info: | + 12. If Type(x) is BigInt and Type(y) is Number, or if Type(x) is Number and Type(y) is BigInt, + b. If the mathematical value of x is equal to the mathematical value of y, return true, otherwise return false. + +features: [BigInt] +---*/ +assert.sameValue(0n == 0, true, 'The result of (0n == 0) is true'); +assert.sameValue(0 == 0n, true, 'The result of (0 == 0n) is true'); +assert.sameValue(0n == -0, true, 'The result of (0n == -0) is true'); +assert.sameValue(-0 == 0n, true, 'The result of (-0 == 0n) is true'); +assert.sameValue(0n == 0.000000000001, false, 'The result of (0n == 0.000000000001) is false'); +assert.sameValue(0.000000000001 == 0n, false, 'The result of (0.000000000001 == 0n) is false'); +assert.sameValue(0n == 1, false, 'The result of (0n == 1) is false'); +assert.sameValue(1 == 0n, false, 'The result of (1 == 0n) is false'); +assert.sameValue(1n == 0, false, 'The result of (1n == 0) is false'); +assert.sameValue(0 == 1n, false, 'The result of (0 == 1n) is false'); +assert.sameValue(1n == 0.999999999999, false, 'The result of (1n == 0.999999999999) is false'); +assert.sameValue(0.999999999999 == 1n, false, 'The result of (0.999999999999 == 1n) is false'); +assert.sameValue(1n == 1, true, 'The result of (1n == 1) is true'); +assert.sameValue(1 == 1n, true, 'The result of (1 == 1n) is true'); +assert.sameValue(0n == Number.MIN_VALUE, false, 'The result of (0n == Number.MIN_VALUE) is false'); +assert.sameValue(Number.MIN_VALUE == 0n, false, 'The result of (Number.MIN_VALUE == 0n) is false'); + +assert.sameValue( + 0n == -Number.MIN_VALUE, + false, + 'The result of (0n == -Number.MIN_VALUE) is false' +); + +assert.sameValue( + -Number.MIN_VALUE == 0n, + false, + 'The result of (-Number.MIN_VALUE == 0n) is false' +); + +assert.sameValue( + -10n == Number.MIN_VALUE, + false, + 'The result of (-10n == Number.MIN_VALUE) is false' +); + +assert.sameValue( + Number.MIN_VALUE == -10n, + false, + 'The result of (Number.MIN_VALUE == -10n) is false' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/bigint-and-object.js b/js/src/tests/test262/language/expressions/equals/bigint-and-object.js new file mode 100644 index 0000000000..f31a5f173e --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/bigint-and-object.js @@ -0,0 +1,136 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Non-strict equality comparison of BigInt values and non-primitive objects +esid: sec-abstract-equality-comparison +info: | + 10. If Type(x) is either String, Number, BigInt, or Symbol and Type(y) is Object, return the result of the comparison x == ? ToPrimitive(y). + 11. If Type(x) is Object and Type(y) is either String, Number, BigInt, or Symbol, return the result of the comparison ? ToPrimitive(x) == y. + + then after the recursion: + + 1. If Type(x) is the same as Type(y), then + a. Return the result of performing Strict Equality Comparison x === y. + ... + 6. If Type(x) is BigInt and Type(y) is String, + a. Let n be StringToBigInt(y). + b. If n is NaN, return false. + c. Return the result of x == n. + 7. If Type(x) is String and Type(y) is BigInt, return the result of y == x. + +features: [BigInt] +---*/ +assert.sameValue(0n == Object(0n), true, 'The result of (0n == Object(0n)) is true'); +assert.sameValue(Object(0n) == 0n, true, 'The result of (Object(0n) == 0n) is true'); +assert.sameValue(0n == Object(1n), false, 'The result of (0n == Object(1n)) is false'); +assert.sameValue(Object(1n) == 0n, false, 'The result of (Object(1n) == 0n) is false'); +assert.sameValue(1n == Object(0n), false, 'The result of (1n == Object(0n)) is false'); +assert.sameValue(Object(0n) == 1n, false, 'The result of (Object(0n) == 1n) is false'); +assert.sameValue(1n == Object(1n), true, 'The result of (1n == Object(1n)) is true'); +assert.sameValue(Object(1n) == 1n, true, 'The result of (Object(1n) == 1n) is true'); +assert.sameValue(2n == Object(0n), false, 'The result of (2n == Object(0n)) is false'); +assert.sameValue(Object(0n) == 2n, false, 'The result of (Object(0n) == 2n) is false'); +assert.sameValue(2n == Object(1n), false, 'The result of (2n == Object(1n)) is false'); +assert.sameValue(Object(1n) == 2n, false, 'The result of (Object(1n) == 2n) is false'); +assert.sameValue(2n == Object(2n), true, 'The result of (2n == Object(2n)) is true'); +assert.sameValue(Object(2n) == 2n, true, 'The result of (Object(2n) == 2n) is true'); +assert.sameValue(0n == {}, false, 'The result of (0n == {}) is false'); +assert.sameValue({} == 0n, false, 'The result of (({}) == 0n) is false'); + +assert.sameValue(0n == { + valueOf: function() { + return 0n; + } +}, true, 'The result of (0n == {valueOf: function() {return 0n;}}) is true'); + +assert.sameValue({ + valueOf: function() { + return 0n; + } +} == 0n, true, 'The result of (({valueOf: function() {return 0n;}}) == 0n) is true'); + +assert.sameValue(0n == { + valueOf: function() { + return 1n; + } +}, false, 'The result of (0n == {valueOf: function() {return 1n;}}) is false'); + +assert.sameValue({ + valueOf: function() { + return 1n; + } +} == 0n, false, 'The result of (({valueOf: function() {return 1n;}}) == 0n) is false'); + +assert.sameValue(0n == { + toString: function() { + return '0'; + } +}, true, 'The result of (0n == {toString: function() {return "0";}}) is true'); + +assert.sameValue({ + toString: function() { + return '0'; + } +} == 0n, true, 'The result of (({toString: function() {return "0";}}) == 0n) is true'); + +assert.sameValue(0n == { + toString: function() { + return '1'; + } +}, false, 'The result of (0n == {toString: function() {return "1";}}) is false'); + +assert.sameValue({ + toString: function() { + return '1'; + } +} == 0n, false, 'The result of (({toString: function() {return "1";}}) == 0n) is false'); + +assert.sameValue(900719925474099101n == { + valueOf: function() { + return 900719925474099101n; + } +}, true, 'The result of (900719925474099101n == {valueOf: function() {return 900719925474099101n;}}) is true'); + +assert.sameValue({ + valueOf: function() { + return 900719925474099101n; + } +} == 900719925474099101n, true, 'The result of (({valueOf: function() {return 900719925474099101n;}}) == 900719925474099101n) is true'); + +assert.sameValue(900719925474099101n == { + valueOf: function() { + return 900719925474099102n; + } +}, false, 'The result of (900719925474099101n == {valueOf: function() {return 900719925474099102n;}}) is false'); + +assert.sameValue({ + valueOf: function() { + return 900719925474099102n; + } +} == 900719925474099101n, false, 'The result of (({valueOf: function() {return 900719925474099102n;}}) == 900719925474099101n) is false'); + +assert.sameValue(900719925474099101n == { + toString: function() { + return '900719925474099101'; + } +}, true, 'The result of (900719925474099101n == {toString: function() {return "900719925474099101";}}) is true'); + +assert.sameValue({ + toString: function() { + return '900719925474099101'; + } +} == 900719925474099101n, true, 'The result of (({toString: function() {return "900719925474099101";}}) == 900719925474099101n) is true'); + +assert.sameValue(900719925474099101n == { + toString: function() { + return '900719925474099102'; + } +}, false, 'The result of (900719925474099101n == {toString: function() {return "900719925474099102";}}) is false'); + +assert.sameValue({ + toString: function() { + return '900719925474099102'; + } +} == 900719925474099101n, false, 'The result of (({toString: function() {return "900719925474099102";}}) == 900719925474099101n) is false'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/bigint-and-string.js b/js/src/tests/test262/language/expressions/equals/bigint-and-string.js new file mode 100644 index 0000000000..6da7bd0e43 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/bigint-and-string.js @@ -0,0 +1,68 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Non-strict equality comparison of BigInt and String values +esid: sec-abstract-equality-comparison +info: | + 1. If Type(x) is different from Type(y), return false. + +features: [BigInt] +---*/ +assert.sameValue(0n == '', true, 'The result of (0n == "") is true'); +assert.sameValue('' == 0n, true, 'The result of ("" == 0n) is true'); +assert.sameValue(0n == '-0', true, 'The result of (0n == "-0") is true'); +assert.sameValue('-0' == 0n, true, 'The result of ("-0" == 0n) is true'); +assert.sameValue(0n == '0', true, 'The result of (0n == "0") is true'); +assert.sameValue('0' == 0n, true, 'The result of ("0" == 0n) is true'); +assert.sameValue(0n == '-1', false, 'The result of (0n == "-1") is false'); +assert.sameValue('-1' == 0n, false, 'The result of ("-1" == 0n) is false'); +assert.sameValue(0n == '1', false, 'The result of (0n == "1") is false'); +assert.sameValue('1' == 0n, false, 'The result of ("1" == 0n) is false'); +assert.sameValue(0n == 'foo', false, 'The result of (0n == "foo") is false'); +assert.sameValue('foo' == 0n, false, 'The result of ("foo" == 0n) is false'); +assert.sameValue(1n == '', false, 'The result of (1n == "") is false'); +assert.sameValue('' == 1n, false, 'The result of ("" == 1n) is false'); +assert.sameValue(1n == '-0', false, 'The result of (1n == "-0") is false'); +assert.sameValue('-0' == 1n, false, 'The result of ("-0" == 1n) is false'); +assert.sameValue(1n == '0', false, 'The result of (1n == "0") is false'); +assert.sameValue('0' == 1n, false, 'The result of ("0" == 1n) is false'); +assert.sameValue(1n == '-1', false, 'The result of (1n == "-1") is false'); +assert.sameValue('-1' == 1n, false, 'The result of ("-1" == 1n) is false'); +assert.sameValue(1n == '1', true, 'The result of (1n == "1") is true'); +assert.sameValue('1' == 1n, true, 'The result of ("1" == 1n) is true'); +assert.sameValue(1n == 'foo', false, 'The result of (1n == "foo") is false'); +assert.sameValue('foo' == 1n, false, 'The result of ("foo" == 1n) is false'); +assert.sameValue(-1n == '-', false, 'The result of (-1n == "-") is false'); +assert.sameValue('-' == -1n, false, 'The result of ("-" == -1n) is false'); +assert.sameValue(-1n == '-0', false, 'The result of (-1n == "-0") is false'); +assert.sameValue('-0' == -1n, false, 'The result of ("-0" == -1n) is false'); +assert.sameValue(-1n == '-1', true, 'The result of (-1n == "-1") is true'); +assert.sameValue('-1' == -1n, true, 'The result of ("-1" == -1n) is true'); +assert.sameValue(-1n == '-foo', false, 'The result of (-1n == "-foo") is false'); +assert.sameValue('-foo' == -1n, false, 'The result of ("-foo" == -1n) is false'); + +assert.sameValue( + 900719925474099101n == '900719925474099101', + true, + 'The result of (900719925474099101n == "900719925474099101") is true' +); + +assert.sameValue( + '900719925474099101' == 900719925474099101n, + true, + 'The result of ("900719925474099101" == 900719925474099101n) is true' +); + +assert.sameValue( + 900719925474099102n == '900719925474099101', + false, + 'The result of (900719925474099102n == "900719925474099101") is false' +); + +assert.sameValue( + '900719925474099101' == 900719925474099102n, + false, + 'The result of ("900719925474099101" == 900719925474099102n) is false' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/browser.js b/js/src/tests/test262/language/expressions/equals/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/browser.js diff --git a/js/src/tests/test262/language/expressions/equals/coerce-symbol-to-prim-err.js b/js/src/tests/test262/language/expressions/equals/coerce-symbol-to-prim-err.js new file mode 100644 index 0000000000..7bb8cf0b73 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/coerce-symbol-to-prim-err.js @@ -0,0 +1,39 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.10.3 +description: > + Behavior when error thrown by invocation of `Symbol.toPrimitive` method + during coercion +info: | + [...] + 7. Return the result of performing Abstract Equality Comparison rval == + lval. + + ES6 Section 7.2.12 Abstract Equality Comparison + + [...] + 10. If Type(x) is either String, Number, or Symbol and Type(y) is Object, + then return the result of the comparison x == ToPrimitive(y). + + ES6 Section 7.1.1 ToPrimitive ( input [, PreferredType] ) + + [...] + 4. Let exoticToPrim be GetMethod(input, @@toPrimitive). + 5. ReturnIfAbrupt(exoticToPrim). + 6. If exoticToPrim is not undefined, then + a. Let result be Call(exoticToPrim, input, «hint»). + b. ReturnIfAbrupt(result). +features: [Symbol.toPrimitive] +---*/ + +var y = {}; +y[Symbol.toPrimitive] = function() { + throw new Test262Error(); +}; + +assert.throws(Test262Error, function() { + 0 == y; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/coerce-symbol-to-prim-invocation.js b/js/src/tests/test262/language/expressions/equals/coerce-symbol-to-prim-invocation.js new file mode 100644 index 0000000000..01174e4717 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/coerce-symbol-to-prim-invocation.js @@ -0,0 +1,50 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.10.3 +description: Invocation of `Symbol.toPrimitive` method during coercion +info: | + [...] + 7. Return the result of performing Abstract Equality Comparison rval == + lval. + + ES6 Section 7.2.12 Abstract Equality Comparison + + [...] + 10. If Type(x) is either String, Number, or Symbol and Type(y) is Object, + then return the result of the comparison x == ToPrimitive(y). + + ES6 Section 7.1.1 ToPrimitive ( input [, PreferredType] ) + + 1. If PreferredType was not passed, let hint be "default". + [...] + 4. Let exoticToPrim be GetMethod(input, @@toPrimitive). + 5. ReturnIfAbrupt(exoticToPrim). + 6. If exoticToPrim is not undefined, then + a. Let result be Call(exoticToPrim, input, «hint»). + [...] +features: [Symbol.toPrimitive] +---*/ + +var y = {}; +var callCount = 0; +var thisVal, args; + +y[Symbol.toPrimitive] = function() { + callCount += 1; + thisVal = this; + args = arguments; +}; + +0 == y; + +assert.sameValue(callCount, 1, 'method invoked exactly once'); +assert.sameValue(thisVal, y, '`this` value is the object being compared'); +assert.sameValue(args.length, 1, 'method invoked with exactly one argument'); +assert.sameValue( + args[0], + 'default', + 'method invoked with the string "default" as the first argument' +); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/coerce-symbol-to-prim-return-obj.js b/js/src/tests/test262/language/expressions/equals/coerce-symbol-to-prim-return-obj.js new file mode 100644 index 0000000000..6ba1d7fb9b --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/coerce-symbol-to-prim-return-obj.js @@ -0,0 +1,53 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.10.3 +description: > + Behavior when coercion via `Symbol.toPrimitive` yields an Object +info: | + [...] + 7. Return the result of performing Abstract Equality Comparison rval == + lval. + + ES6 Section 7.2.12 Abstract Equality Comparison + + [...] + 10. If Type(x) is either String, Number, or Symbol and Type(y) is Object, + then return the result of the comparison x == ToPrimitive(y). + + ES6 Section 7.1.1 ToPrimitive ( input [, PreferredType] ) + + [...] + 4. Let exoticToPrim be GetMethod(input, @@toPrimitive). + 5. ReturnIfAbrupt(exoticToPrim). + 6. If exoticToPrim is not undefined, then + a. Let result be Call(exoticToPrim, input, «hint»). + b. ReturnIfAbrupt(result). + c. If Type(result) is not Object, return result. + d. Throw a TypeError exception. +features: [Symbol.toPrimitive] +---*/ + +var y = {}; +var retVal; + +y[Symbol.toPrimitive] = function() { + return retVal; +}; + +retVal = {}; +assert.throws(TypeError, function() { + 0 == y; +}); + +retVal = new Number(); +assert.throws(TypeError, function() { + 0 == y; +}); + +retVal = new String(); +assert.throws(TypeError, function() { + 0 == y; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/coerce-symbol-to-prim-return-prim.js b/js/src/tests/test262/language/expressions/equals/coerce-symbol-to-prim-return-prim.js new file mode 100644 index 0000000000..30dcfe105c --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/coerce-symbol-to-prim-return-prim.js @@ -0,0 +1,49 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.10.3 +description: > + Behavior when coercion via `Symbol.toPrimitive` yields a primitive value +info: | + [...] + 7. Return the result of performing Abstract Equality Comparison rval == + lval. + + ES6 Section 7.2.12 Abstract Equality Comparison + + [...] + 10. If Type(x) is either String, Number, or Symbol and Type(y) is Object, + then return the result of the comparison x == ToPrimitive(y). + + ES6 Section 7.1.1 ToPrimitive ( input [, PreferredType] ) + + [...] + 4. Let exoticToPrim be GetMethod(input, @@toPrimitive). + 5. ReturnIfAbrupt(exoticToPrim). + 6. If exoticToPrim is not undefined, then + a. Let result be Call(exoticToPrim, input, «hint»). + b. ReturnIfAbrupt(result). + c. If Type(result) is not Object, return result. +features: [Symbol.toPrimitive] +---*/ + +var y = {}; +var retVal; + +y[Symbol.toPrimitive] = function() { + return retVal; +}; + +retVal = 86; +assert.sameValue(0 == y, false, 'number primitive (not equal)'); +assert.sameValue(86 == y, true, 'number primitive (equal)'); + +retVal = 'str'; +assert.sameValue(0 == y, false, 'string primitive (not equal)'); +assert.sameValue('str' == y, true, 'sting primitive (equal)'); + +retVal = Symbol.toPrimitive; +assert.sameValue(0 == y, false, 'symbol (not equal)'); +assert.sameValue(Symbol.toPrimitive == y, true, 'symbol (equal)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/get-symbol-to-prim-err.js b/js/src/tests/test262/language/expressions/equals/get-symbol-to-prim-err.js new file mode 100644 index 0000000000..bb342d7643 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/get-symbol-to-prim-err.js @@ -0,0 +1,36 @@ +// Copyright (C) 2015 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 12.10.3 +description: > + Behavior when error thrown while accessing `Symbol.toPrimitive` property +info: | + [...] + 7. Return the result of performing Abstract Equality Comparison rval == + lval. + + ES6 Section 7.2.12 Abstract Equality Comparison + + [...] + 10. If Type(x) is either String, Number, or Symbol and Type(y) is Object, + then return the result of the comparison x == ToPrimitive(y). + + ES6 Section 7.1.1 ToPrimitive ( input [, PreferredType] ) + + [...] + 4. Let exoticToPrim be GetMethod(input, @@toPrimitive). + 5. ReturnIfAbrupt(exoticToPrim). +features: [Symbol.toPrimitive] +---*/ + +var y = Object.defineProperty({}, Symbol.toPrimitive, { + get: function() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + 0 == y; +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/shell.js b/js/src/tests/test262/language/expressions/equals/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/shell.js diff --git a/js/src/tests/test262/language/expressions/equals/symbol-abstract-equality-comparison.js b/js/src/tests/test262/language/expressions/equals/symbol-abstract-equality-comparison.js new file mode 100644 index 0000000000..ae8c9ec1e0 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/symbol-abstract-equality-comparison.js @@ -0,0 +1,23 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 7.2.12 +description: > + Abstract Equality Comparison: Symbol +features: [Symbol] +---*/ +var symA = Symbol('66'); +var symB = Symbol('66'); + +assert.sameValue(symA == symA, true, "The result of `symA == symA` is `true`"); +assert.sameValue(symA == symA.valueOf(), true, "The result of `symA == symA.valueOf()` is `true`"); +assert.sameValue(symA.valueOf() == symA, true, "The result of `symA.valueOf() == symA` is `true`"); + +assert.sameValue(symB == symB, true, "The result of `symB == symB` is `true`"); +assert.sameValue(symB == symB.valueOf(), true, "The result of `symB == symB.valueOf()` is `true`"); +assert.sameValue(symB.valueOf() == symB, true, "The result of `symB.valueOf() == symB` is `true`"); + +assert.sameValue(symA == symB, false, "The result of `symA == symB` is `false`"); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/symbol-strict-equality-comparison.js b/js/src/tests/test262/language/expressions/equals/symbol-strict-equality-comparison.js new file mode 100644 index 0000000000..3e6413f0af --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/symbol-strict-equality-comparison.js @@ -0,0 +1,22 @@ +// Copyright (C) 2013 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +es6id: 7.2.13 +description: > + Strict Equality Comparison: Symbol +features: [Symbol] +---*/ +var symA = Symbol('66'); +var symB = Symbol('66'); + +assert.sameValue(symA === symA, true, "The result of `symA === symA` is `true`"); +assert.sameValue(symA === symA.valueOf(), true, "The result of `symA === symA.valueOf()` is `true`"); +assert.sameValue(symA.valueOf() === symA, true, "The result of `symA.valueOf() === symA` is `true`"); + +assert.sameValue(symB === symB, true, "The result of `symB === symB` is `true`"); +assert.sameValue(symB === symB.valueOf(), true, "The result of `symB === symB.valueOf()` is `true`"); +assert.sameValue(symB.valueOf() === symB, true, "The result of `symB.valueOf() === symB` is `true`"); + +assert.sameValue(symA === symB, false, "The result of `symA === symB` is `false`"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/equals/to-prim-hint.js b/js/src/tests/test262/language/expressions/equals/to-prim-hint.js new file mode 100644 index 0000000000..53e7925c17 --- /dev/null +++ b/js/src/tests/test262/language/expressions/equals/to-prim-hint.js @@ -0,0 +1,37 @@ +// Copyright (C) 2017 Robin Templeton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-abstract-equality-comparison +description: Object operands coerced without ToPrimitive hint +info: | + 7.2.14 Abstract Equality Comparison + + ... + 6. If Type(x) is Boolean, return the result of the comparison ! + ToNumber(x) == y. + 7. If Type(y) is Boolean, return the result of the comparison x == ! + ToNumber(y). + 8. If Type(x) is either String, Number, or Symbol and Type(y) is + Object, return the result of the comparison x == ToPrimitive(y). + 9. If Type(x) is Object and Type(y) is either String, Number, or + Symbol, return the result of the comparison ToPrimitive(x) == y. + ... +features: [Symbol.toPrimitive] +---*/ + +let count = 0; +let obj = { + [Symbol.toPrimitive](hint) { + count += 1; + assert.sameValue(hint, "default"); + return 1; + } +}; + +assert.sameValue(true == obj, true); +assert.sameValue(count, 1); +assert.sameValue(obj == true, true); +assert.sameValue(count, 2); + +reportCompare(0, 0); |