diff options
Diffstat (limited to 'js/src/tests/test262/language/expressions/exponentiation')
46 files changed, 1868 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A1.js b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A1.js new file mode 100644 index 0000000000..13799f60d5 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A1.js @@ -0,0 +1,31 @@ +// Copyright 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: If exponent is NaN, the result is NaN. +features: [exponentiation] +---*/ + +var exponent = NaN; +var bases = []; +bases[0] = -Infinity; +bases[1] = -1.7976931348623157E308; //largest (by module) finite number +bases[2] = -0.000000000000001; +bases[3] = -0; +bases[4] = +0 +bases[5] = 0.000000000000001; +bases[6] = 1.7976931348623157E308; //largest finite number +bases[7] = +Infinity; +bases[8] = NaN; + + +for (var i = 0; i < bases.length; i++) { + assert.sameValue( + bases[i] ** exponent, + NaN, + bases[i] + " ** " + exponent + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A10.js b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A10.js new file mode 100644 index 0000000000..62328f4b5c --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A10.js @@ -0,0 +1,25 @@ +// Copyright 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: If abs(base) < 1 and exponent is −∞, the result is +∞. +---*/ + + +var exponent = -Infinity; +var bases = []; +bases[0] = 0.999999999999999; +bases[1] = 0.5; +bases[2] = +0; +bases[3] = -0; +bases[4] = -0.5; +bases[5] = -0.999999999999999; + +for (var i = 0; i < bases.length; i++) { + if (Math.pow(bases[i], exponent) !== +Infinity) { + throw new Test262Error("(" + bases[i] + " ** " + exponent + ") !== +Infinity"); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A11.js b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A11.js new file mode 100644 index 0000000000..9cc32051cd --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A11.js @@ -0,0 +1,24 @@ +// Copyright 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: If base is +∞ and exponent > 0, the result is +∞. +features: [exponentiation] +---*/ + + +var base = +Infinity; +var exponents = []; +exponents[3] = Infinity; +exponents[2] = 1.7976931348623157E308; //largest (by module) finite number +exponents[1] = 1; +exponents[0] = 0.000000000000001; + +for (var i = 0; i < exponents.length; i++) { + if (base ** exponents[i] !== +Infinity) { + throw new Test262Error("(" + base + " ** " + exponents[i] + ") !== +Infinity"); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A12.js b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A12.js new file mode 100644 index 0000000000..fdd51ea96d --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A12.js @@ -0,0 +1,24 @@ +// Copyright 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: If base is +∞ and exponent < 0, the result is +0. +features: [exponentiation] +---*/ + + +var base = +Infinity; +var exponents = []; +exponents[0] = -Infinity; +exponents[1] = -1.7976931348623157E308; //largest (by module) finite number +exponents[2] = -1; +exponents[3] = -0.000000000000001; + +for (var i = 0; i < exponents.length; i++) { + if ((base ** exponents[i]) !== +0) { + throw new Test262Error("(" + base + " ** " + exponents[i] + ") !== +0"); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A13.js b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A13.js new file mode 100644 index 0000000000..00d8517b6f --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A13.js @@ -0,0 +1,23 @@ +// Copyright 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: If base is −∞ and exponent > 0 and exponent is an odd integer, the result is −∞. +features: [exponentiation] +---*/ + + +var base = -Infinity; +var exponents = []; +exponents[0] = 1; +exponents[1] = 111; +exponents[2] = 111111; + +for (var i = 0; i < exponents.length; i++) { + if ((base ** exponents[i]) !== -Infinity) { + throw new Test262Error("(" + base + " ** " + exponents[i] + ") !== -Infinity"); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A14.js b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A14.js new file mode 100644 index 0000000000..e486d64ca0 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A14.js @@ -0,0 +1,25 @@ +// Copyright 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: If base is −∞ and exponent > 0 and exponent is not an odd integer, the result is +∞. +features: [exponentiation] +---*/ + + +var base = -Infinity; +var exponents = []; +exponents[0] = 0.000000000000001; +exponents[1] = 2; +exponents[2] = Math.PI; +exponents[3] = 1.7976931348623157E308; //largest finite number +exponents[4] = +Infinity; + +for (var i = 0; i < exponents.length; i++) { + if ((base ** exponents[i]) !== +Infinity) { + throw new Test262Error("(" + base + " ** " + exponents[i] + ") !== +Infinity"); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A15.js b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A15.js new file mode 100644 index 0000000000..1fb80c4bc8 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A15.js @@ -0,0 +1,21 @@ +// Copyright 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: If base is −∞ and exponent < 0 and exponent is an odd integer, the result is −0. +features: [exponentiation] +---*/ + + +var base = -Infinity; +var exponents = []; +exponents[2] = -1; +exponents[1] = -111; +exponents[0] = -111111; + +for (var i = 0; i < exponents.length; i++) { + assert.sameValue(base ** exponents[i], -0, base + " ** " + exponents[i]); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A16.js b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A16.js new file mode 100644 index 0000000000..64feeec702 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A16.js @@ -0,0 +1,25 @@ +// Copyright 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: If base is −∞ and exponent < 0 and exponent is not an odd integer, the result is +0. +features: [exponentiation] +---*/ + + +var base = -Infinity; +var exponents = []; +exponents[4] = -0.000000000000001; +exponents[3] = -2; +exponents[2] = -Math.PI; +exponents[1] = -1.7976931348623157E308; //largest (by module) finite number +exponents[0] = -Infinity; + +for (var i = 0; i < exponents.length; i++) { + if ((base ** exponents[i]) !== +0) { + throw new Test262Error("(" + base + " ** " + exponents[i] + ") !== +0"); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A17.js b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A17.js new file mode 100644 index 0000000000..be4e07dae6 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A17.js @@ -0,0 +1,24 @@ +// Copyright 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: If base is +0 and exponent > 0, the result is +0. +features: [exponentiation] +---*/ + + +var base = +0; +var exponents = []; +exponents[3] = Infinity; +exponents[2] = 1.7976931348623157E308; //largest finite number +exponents[1] = 1; +exponents[0] = 0.000000000000001; + +for (var i = 0; i < exponents.length; i++) { + if ((base ** exponents[i]) !== +0) { + throw new Test262Error("(" + base + " ** " + exponents[i] + ") !== +0"); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A18.js b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A18.js new file mode 100644 index 0000000000..3dd8266e2c --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A18.js @@ -0,0 +1,24 @@ +// Copyright 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: If base is +0 and exponent < 0, the result is +∞. +features: [exponentiation] +---*/ + + +var base = +0; +var exponents = []; +exponents[0] = -Infinity; +exponents[1] = -1.7976931348623157E308; //largest (by module) finite number +exponents[2] = -1; +exponents[3] = -0.000000000000001; + +for (var i = 0; i < exponents.length; i++) { + if ((base ** exponents[i]) !== +Infinity) { + throw new Test262Error("(" + base + " ** " + exponents[i] + ") !== +Infinity"); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A19.js b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A19.js new file mode 100644 index 0000000000..dfef9836e8 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A19.js @@ -0,0 +1,21 @@ +// Copyright 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: If base is −0 and exponent > 0 and exponent is an odd integer, the result is −0. +features: [exponentiation] +---*/ + + +var base = -0; +var exponents = []; +exponents[0] = 1; +exponents[1] = 111; +exponents[2] = 111111; + +for (var i = 0; i < exponents.length; i++) { + assert.sameValue(base ** exponents[i], -0, base + " ** " + exponents[i]); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A2.js b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A2.js new file mode 100644 index 0000000000..86344c4ee7 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A2.js @@ -0,0 +1,30 @@ +// Copyright 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: > + If exponent is +0, the result is 1, even if base is NaN. +features: [exponentiation] +---*/ + + +var exponent = +0; +var bases = []; +bases[0] = -Infinity; +bases[1] = -1.7976931348623157E308; //largest (by module) finite number +bases[2] = -0.000000000000001; +bases[3] = -0; +bases[4] = +0 +bases[5] = 0.000000000000001; +bases[6] = 1.7976931348623157E308; //largest finite number +bases[7] = +Infinity; +bases[8] = NaN; + +for (var i = 0; i < bases.length; i++) { + if ((bases[i] ** exponent) !== 1) { + throw new Test262Error("(" + bases[i] + " ** " + exponent + ") !== 1"); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A20.js b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A20.js new file mode 100644 index 0000000000..c2c4382741 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A20.js @@ -0,0 +1,25 @@ +// Copyright 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: If base is −0 and exponent > 0 and exponent is not an odd integer, the result is +0. +features: [exponentiation] +---*/ + + +var base = -0; +var exponents = []; +exponents[0] = 0.000000000000001; +exponents[1] = 2; +exponents[2] = Math.PI; +exponents[3] = 1.7976931348623157E308; //largest finite number +exponents[4] = +Infinity; + +for (var i = 0; i < exponents.length; i++) { + if ((base ** exponents[i]) !== +0) { + throw new Test262Error("(" + base + " ** " + exponents[i] + ") !== +0"); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A21.js b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A21.js new file mode 100644 index 0000000000..e51cc41f37 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A21.js @@ -0,0 +1,23 @@ +// Copyright 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: If base is −0 and exponent < 0 and exponent is an odd integer, the result is −∞. +features: [exponentiation] +---*/ + + +var base = -0; +var exponents = []; +exponents[2] = -1; +exponents[1] = -111; +exponents[0] = -111111; + +for (var i = 0; i < exponents.length; i++) { + if ((base ** exponents[i]) !== -Infinity) { + throw new Test262Error("(" + base + " ** " + exponents[i] + ") !== -Infinity"); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A22.js b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A22.js new file mode 100644 index 0000000000..b11692c8fb --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A22.js @@ -0,0 +1,25 @@ +// Copyright 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: If base is −0 and exponent < 0 and exponent is not an odd integer, the result is +∞. +features: [exponentiation] +---*/ + + +var base = -0; +var exponents = []; +exponents[4] = -0.000000000000001; +exponents[3] = -2; +exponents[2] = -Math.PI; +exponents[1] = -1.7976931348623157E308; //largest (by module) finite number +exponents[0] = -Infinity; + +for (var i = 0; i < exponents.length; i++) { + if ((base ** exponents[i]) !== +Infinity) { + throw new Test262Error("(" + base + " ** " + exponents[i] + ") !== +Infinity"); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A23.js b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A23.js new file mode 100644 index 0000000000..c79cb5b758 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A23.js @@ -0,0 +1,38 @@ +// Copyright 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: If base < 0 and base is finite and exponent is finite and exponent is not an integer, the result is NaN. +features: [exponentiation] +---*/ + + +var exponents = []; +var bases = []; +bases[0] = -1.7976931348623157E308; //largest (by module) finite number +bases[1] = -Math.PI; +bases[2] = -1; +bases[3] = -0.000000000000001; + +exponents[0] = -Math.PI; +exponents[1] = -Math.E; +exponents[2] = -1.000000000000001; +exponents[3] = -0.000000000000001; +exponents[4] = 0.000000000000001; +exponents[5] = 1.000000000000001; +exponents[6] = Math.E; +exponents[7] = Math.PI; + +for (var i = 0; i < bases.length; i++) { + for (var j = 0; j < exponents.length; j++) { + assert.sameValue( + bases[i] ** exponents[j], + NaN, + bases[i] + " ** " + exponents[j] + ); + } +} + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A3.js b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A3.js new file mode 100644 index 0000000000..e7bdff5882 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A3.js @@ -0,0 +1,30 @@ +// Copyright 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: > + If exponent is −0, the result is 1, even if base is NaN. +features: [exponentiation] +---*/ + + +var exponent = -0; +var bases = []; +bases[0] = -Infinity; +bases[1] = -1.7976931348623157E308; //largest (by module) finite number +bases[2] = -0.000000000000001; +bases[3] = -0; +bases[4] = +0 +bases[5] = 0.000000000000001; +bases[6] = 1.7976931348623157E308; //largest finite number +bases[7] = +Infinity; +bases[8] = NaN; + +for (var i = 0; i < bases.length; i++) { + if ((bases[i] ** exponent) !== 1) { + throw new Test262Error("(" + bases[i] + " ** -0) !== 1"); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A4.js b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A4.js new file mode 100644 index 0000000000..83bfb1bb53 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A4.js @@ -0,0 +1,29 @@ +// Copyright 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: If base is NaN and exponent is nonzero, the result is NaN. +features: [exponentiation] +---*/ + + +var base = NaN; +var exponents = []; +exponents[0] = -Infinity; +exponents[1] = -1.7976931348623157E308; //largest (by module) finite number +exponents[2] = -0.000000000000001; +exponents[3] = 0.000000000000001; +exponents[4] = 1.7976931348623157E308; //largest finite number +exponents[5] = +Infinity; +exponents[6] = NaN; + +for (var i = 0; i < exponents.length; i++) { + assert.sameValue( + base ** exponents[i], + NaN, + base + " ** " + exponents[i] + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A5.js b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A5.js new file mode 100644 index 0000000000..3c98349ff3 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A5.js @@ -0,0 +1,26 @@ +// Copyright 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: If abs(base) > 1 and exponent is +∞, the result is +∞. +features: [exponentiation] +---*/ + + +var exponent = +Infinity; +var bases = []; +bases[0] = -Infinity; +bases[1] = -1.7976931348623157E308; //largest (by module) finite number +bases[2] = -1.000000000000001; +bases[3] = 1.000000000000001; +bases[4] = 1.7976931348623157E308; //largest finite number +bases[5] = +Infinity; + +for (var i = 0; i < bases.length; i++) { + if ((bases[i] ** exponent) !== +Infinity) { + throw new Test262Error("(" + bases[i] + " ** " + exponent + ") !== +Infinity"); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A6.js b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A6.js new file mode 100644 index 0000000000..1c677b6cd8 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A6.js @@ -0,0 +1,26 @@ +// Copyright 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: If abs(base) > 1 and exponent is −∞, the result is +0. +features: [exponentiation] +---*/ + + +var exponent = -Infinity; +var bases = []; +bases[0] = -Infinity; +bases[1] = -1.7976931348623157E308; //largest (by module) finite number +bases[2] = -1.000000000000001; +bases[3] = 1.000000000000001; +bases[4] = 1.7976931348623157E308; //largest finite number +bases[5] = +Infinity; + +for (var i = 0; i < bases.length; i++) { + if ((bases[i] ** exponent) !== +0) { + throw new Test262Error("(" + bases[i] + " ** " + exponent + ") !== +0"); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A7.js b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A7.js new file mode 100644 index 0000000000..afcb133f33 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A7.js @@ -0,0 +1,24 @@ +// Copyright 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: If abs(base) is 1 and exponent is +∞, the result is NaN. +features: [exponentiation] +---*/ + + +var exponent = +Infinity; +var bases = []; +bases[0] = -1; +bases[1] = 1 + +for (var i = 0; i < bases.length; i++) { + assert.sameValue( + bases[i] ** exponent, + NaN, + bases[i] + " ** " + exponent + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A8.js b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A8.js new file mode 100644 index 0000000000..08272fc202 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A8.js @@ -0,0 +1,24 @@ +// Copyright 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: If abs(base) is 1 and exponent is −∞, the result is NaN. +features: [exponentiation] +---*/ + + +var exponent = -Infinity; +var bases = []; +bases[0] = -1; +bases[1] = 1 + +for (var i = 0; i < bases.length; i++) { + assert.sameValue( + bases[i] ** exponent, + NaN, + bases[i] + " ** " + exponent + ); +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A9.js b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A9.js new file mode 100644 index 0000000000..c8fa9e61f8 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/applying-the-exp-operator_A9.js @@ -0,0 +1,26 @@ +// Copyright 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: If abs(base) < 1 and exponent is +∞, the result is +0. +features: [exponentiation] +---*/ + + +var exponent = +Infinity; +var bases = []; +bases[0] = 0.999999999999999; +bases[1] = 0.5; +bases[2] = +0; +bases[3] = -0; +bases[4] = -0.5; +bases[5] = -0.999999999999999; + +for (var i = 0; i < bases.length; i++) { + if ((bases[i] ** exponent) !== +0) { + throw new Test262Error("(" + bases[i] + " ** " + exponent + ") !== +0"); + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/bigint-and-number.js b/js/src/tests/test262/language/expressions/exponentiation/bigint-and-number.js new file mode 100644 index 0000000000..2a8ae8d156 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/bigint-and-number.js @@ -0,0 +1,92 @@ +// Copyright (C) 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-exp-operator-runtime-semantics-evaluation +description: Mixing BigInt and Number produces a TypeError for exponentiation operator +features: [BigInt, exponentiation] +info: | + Let base be ? ToNumeric(leftValue). + Let exponent be ? ToNumeric(rightValue). + If Type(base) does not equal Type(exponent), throw a TypeError exception. +---*/ +assert.throws(TypeError, function() { + 1n ** 1; +}, '1n ** 1 throws TypeError'); + +assert.throws(TypeError, function() { + 1 ** 1n; +}, '1 ** 1n throws TypeError'); + +assert.throws(TypeError, function() { + Object(1n) ** 1; +}, 'Object(1n) ** 1 throws TypeError'); + +assert.throws(TypeError, function() { + 1 ** Object(1n); +}, '1 ** Object(1n) throws TypeError'); + +assert.throws(TypeError, function() { + 1n ** Object(1); +}, '1n ** Object(1) throws TypeError'); + +assert.throws(TypeError, function() { + Object(1) ** 1n; +}, 'Object(1) ** 1n throws TypeError'); + +assert.throws(TypeError, function() { + Object(1n) ** Object(1); +}, 'Object(1n) ** Object(1) throws TypeError'); + +assert.throws(TypeError, function() { + Object(1) ** Object(1n); +}, 'Object(1) ** Object(1n) throws TypeError'); + +assert.throws(TypeError, function() { + 1n ** NaN; +}, '1n ** NaN throws TypeError'); + +assert.throws(TypeError, function() { + NaN ** 1n; +}, 'NaN ** 1n throws TypeError'); + +assert.throws(TypeError, function() { + 1n ** Infinity; +}, '1n ** Infinity throws TypeError'); + +assert.throws(TypeError, function() { + Infinity ** 1n; +}, 'Infinity ** 1n throws TypeError'); + +assert.throws(TypeError, function() { + 1n ** true; +}, '1n ** true throws TypeError'); + +assert.throws(TypeError, function() { + true ** 1n; +}, 'true ** 1n throws TypeError'); + +assert.throws(TypeError, function() { + 1n ** '1'; +}, '1n ** "1" throws TypeError'); + +assert.throws(TypeError, function() { + '1' ** 1n; +}, '"1" ** 1n throws TypeError'); + +assert.throws(TypeError, function() { + 1n ** null; +}, '1n ** null throws TypeError'); + +assert.throws(TypeError, function() { + null ** 1n; +}, 'null ** 1n throws TypeError'); + +assert.throws(TypeError, function() { + 1n ** undefined; +}, '1n ** undefined throws TypeError'); + +assert.throws(TypeError, function() { + undefined ** 1n; +}, 'undefined ** 1n throws TypeError'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/bigint-arithmetic.js b/js/src/tests/test262/language/expressions/exponentiation/bigint-arithmetic.js new file mode 100644 index 0000000000..e754501274 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/bigint-arithmetic.js @@ -0,0 +1,77 @@ +// Copyright (C) 2017 Robin Templeton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-exp-operator-runtime-semantics-evaluation +description: BigInt exponentiation arithmetic +features: [BigInt, exponentiation] +---*/ +assert.sameValue( + 0x123n ** 0x123n, + 0x37AA7FAA38F2F6026AABEFE979EA730BA9EA4CB99E2E3F645D515D3BBE2D84BCD89F8A034BADF3E3DC0CF417258371B31F4555DC0883DA96760AB157DB7DFFF5E3E97A3EAAB8328B2B178060B5A5E4C4DD8BC8D66B7F4D9F0E0B1AC3A566FDE0A15EBF8DBDBD0565C5FBDB7C123CF250E271DF5C38BC6746A1327F09C7FB4B96E0EDA45C429799CA80B1DB039692C70DFFE4E66F1D9CAB4270863B09A7918F774D686F685F560FEDC6B7B85CB45DE5EEEF6A5FE2FC8B5037FB421204641909347C91F2DC252F49B8F310E867E56D1CA2E81EE9A3AA568682C7B8B41D709A2E7F8D9A8D8C56D6BE78B6CA8365E362B81A64974C315FB8FA50CED4F7944F28FA3ECA77B8BCB56DC69814328F891E6065D108EEE7B8E695038090CCA10C0E68DD7A36CFAA1C26CDFEC369FBn, + 'The result of (0x123n ** 0x123n) is 0x37AA7FAA38F2F6026AABEFE979EA730BA9EA4CB99E2E3F645D515D3BBE2D84BCD89F8A034BADF3E3DC0CF417258371B31F4555DC0883DA96760AB157DB7DFFF5E3E97A3EAAB8328B2B178060B5A5E4C4DD8BC8D66B7F4D9F0E0B1AC3A566FDE0A15EBF8DBDBD0565C5FBDB7C123CF250E271DF5C38BC6746A1327F09C7FB4B96E0EDA45C429799CA80B1DB039692C70DFFE4E66F1D9CAB4270863B09A7918F774D686F685F560FEDC6B7B85CB45DE5EEEF6A5FE2FC8B5037FB421204641909347C91F2DC252F49B8F310E867E56D1CA2E81EE9A3AA568682C7B8B41D709A2E7F8D9A8D8C56D6BE78B6CA8365E362B81A64974C315FB8FA50CED4F7944F28FA3ECA77B8BCB56DC69814328F891E6065D108EEE7B8E695038090CCA10C0E68DD7A36CFAA1C26CDFEC369FBn' +); + +assert.sameValue( + 0x123n ** 0xFFn, + 0x8D5BB75861377EC967BF78FDF39CE51696FBD34722999943F8865938772B517167CD5ED775A78987F5106831F4978E0709032B26ED8F13F814699DB8AB3ACD5CF631F2D8B8B706FCF5EF441AAEE745A795EC5CB86A5E8D87D09F648EFC557B98F73E750FEC9AED061D47806F269CCCDFB6D513912A82AE79B171D76AF6D926BC4F4C4DA43A6EFB4D9D1672E356CC1F74A29AF80D53A8F27592F6191AB9B3D57FA2C435CB2CE8F18A3B3448F88F4BAD3606A9878DA9528B569BADAC0C1EC0B1A2B06CD4C64DEEC940807DFD05C56E3E17ADB1A88EDAF0D67C87C1F871BFB5C47CAE8365FE33538317EE2DF4EE52636CE1BDA9E41C7DA72826E4C097A53BD73D8D697E10D28Bn, + 'The result of (0x123n ** 0xFFn) is 0x8D5BB75861377EC967BF78FDF39CE51696FBD34722999943F8865938772B517167CD5ED775A78987F5106831F4978E0709032B26ED8F13F814699DB8AB3ACD5CF631F2D8B8B706FCF5EF441AAEE745A795EC5CB86A5E8D87D09F648EFC557B98F73E750FEC9AED061D47806F269CCCDFB6D513912A82AE79B171D76AF6D926BC4F4C4DA43A6EFB4D9D1672E356CC1F74A29AF80D53A8F27592F6191AB9B3D57FA2C435CB2CE8F18A3B3448F88F4BAD3606A9878DA9528B569BADAC0C1EC0B1A2B06CD4C64DEEC940807DFD05C56E3E17ADB1A88EDAF0D67C87C1F871BFB5C47CAE8365FE33538317EE2DF4EE52636CE1BDA9E41C7DA72826E4C097A53BD73D8D697E10D28Bn' +); + +assert.sameValue(0x123n ** 0x3n, 0x178027Bn, 'The result of (0x123n ** 0x3n) is 0x178027Bn'); +assert.sameValue(0x123n ** 0x2n, 0x14AC9n, 'The result of (0x123n ** 0x2n) is 0x14AC9n'); +assert.sameValue(0x123n ** 0x1n, 0x123n, 'The result of (0x123n ** 0x1n) is 0x123n'); + +assert.sameValue( + 0xFFn ** 0x123n, + 0x51F5CA2E1A36F5FF1ED3D393D76FBC3612B38EB64E00EDAC5E95ADE0D16D0B044C8E9F2B77B3F31AF9159F482205541E9D3BE9D248FF39CE6524874EBCA60E06302E8B505D11EEEEE869C7F801A82B9739C197E6D63A1EB2D29B5AD5EED4773C762106E9F66BFCB6C11450218973C69DED3FE51FF881AD0430675BF54320513EA766117C50C554E86E22A5ACFD8047D5470B4FCBCB9EFC86196CA77C58F1BEB09F76160D641B82E2481BEDAE089207D49FE0FB7DE14B6C4BC82E9C58140746AC8E74C3353AAF5F9CF47ED1F87C52F463C053DB63CD08CC9866EBA274D39B6B357ADADAD4D210167EF7363453D42BC225D90070336861F2D259489D78B7F04B05FE65E29151ADD2B8F4D318011988550CE590DBA4C868AC65AA325051DF613D6C2E22FFn, + 'The result of (0xFFn ** 0x123n) is 0x51F5CA2E1A36F5FF1ED3D393D76FBC3612B38EB64E00EDAC5E95ADE0D16D0B044C8E9F2B77B3F31AF9159F482205541E9D3BE9D248FF39CE6524874EBCA60E06302E8B505D11EEEEE869C7F801A82B9739C197E6D63A1EB2D29B5AD5EED4773C762106E9F66BFCB6C11450218973C69DED3FE51FF881AD0430675BF54320513EA766117C50C554E86E22A5ACFD8047D5470B4FCBCB9EFC86196CA77C58F1BEB09F76160D641B82E2481BEDAE089207D49FE0FB7DE14B6C4BC82E9C58140746AC8E74C3353AAF5F9CF47ED1F87C52F463C053DB63CD08CC9866EBA274D39B6B357ADADAD4D210167EF7363453D42BC225D90070336861F2D259489D78B7F04B05FE65E29151ADD2B8F4D318011988550CE590DBA4C868AC65AA325051DF613D6C2E22FFn' +); + +assert.sameValue( + 0xFFn ** 0xFFn, + 0x5E5C8B0EB95AB08F9D37EF127FC01BD0E33DE52647528396D78D5F8DA31989E67814F6BBA1FB0F0207010FF5F2347B19D5F6598FC91BF5A88F77DAA3D7B382FEC484F3D205C06A34445384C0E7AB0D883788C68C012CB433055EDDA746A48409444EA91147273B79FC3EABB70ECA552AF650C234BB01ED404427F17CDDDD71D08E39EF9C3982E3CE44E670456AA8154C1FDBD9C35947F494636A425C69BF89E9C75AD3B7A0A559AF0F5DA9947C8DEBA64417310713B23E7EF4DE50BB2A3E90BC2AC3DA5201CCA8D6E5DFEA887C4F7A4E92175D9F88BD2779B57F9EB35BE7528F965A06DA0AC41DCB3A34F1D8AB7D8FEE620A94FAA42C395997756B007FFEFFn, + 'The result of (0xFFn ** 0xFFn) is 0x5E5C8B0EB95AB08F9D37EF127FC01BD0E33DE52647528396D78D5F8DA31989E67814F6BBA1FB0F0207010FF5F2347B19D5F6598FC91BF5A88F77DAA3D7B382FEC484F3D205C06A34445384C0E7AB0D883788C68C012CB433055EDDA746A48409444EA91147273B79FC3EABB70ECA552AF650C234BB01ED404427F17CDDDD71D08E39EF9C3982E3CE44E670456AA8154C1FDBD9C35947F494636A425C69BF89E9C75AD3B7A0A559AF0F5DA9947C8DEBA64417310713B23E7EF4DE50BB2A3E90BC2AC3DA5201CCA8D6E5DFEA887C4F7A4E92175D9F88BD2779B57F9EB35BE7528F965A06DA0AC41DCB3A34F1D8AB7D8FEE620A94FAA42C395997756B007FFEFFn' +); + +assert.sameValue(0xFFn ** 0x3n, 0xFD02FFn, 'The result of (0xFFn ** 0x3n) is 0xFD02FFn'); +assert.sameValue(0xFFn ** 0x2n, 0xFE01n, 'The result of (0xFFn ** 0x2n) is 0xFE01n'); +assert.sameValue(0xFFn ** 0x1n, 0xFFn, 'The result of (0xFFn ** 0x1n) is 0xFFn'); + +assert.sameValue( + 0x3n ** 0x123n, + 0x25609213623D7D6219085CF49D306450BF6519835586C19D3A4F3A2C5F35B44A300C8A76E11708B5495B9C3EE756BBF19E3FD15CE625D3C0539Bn, + 'The result of (0x3n ** 0x123n) is 0x25609213623D7D6219085CF49D306450BF6519835586C19D3A4F3A2C5F35B44A300C8A76E11708B5495B9C3EE756BBF19E3FD15CE625D3C0539Bn' +); + +assert.sameValue( + 0x3n ** 0xFFn, + 0x11F1B08E87EC42C5D83C3218FC83C41DCFD9F4428F4F92AF1AAA80AA46162B1F71E981273601F4AD1DD4709B5ACA650265A6ABn, + 'The result of (0x3n ** 0xFFn) is 0x11F1B08E87EC42C5D83C3218FC83C41DCFD9F4428F4F92AF1AAA80AA46162B1F71E981273601F4AD1DD4709B5ACA650265A6ABn' +); + +assert.sameValue(0x3n ** 0x3n, 0x1Bn, 'The result of (0x3n ** 0x3n) is 0x1Bn'); +assert.sameValue(0x3n ** 0x2n, 0x9n, 'The result of (0x3n ** 0x2n) is 0x9n'); +assert.sameValue(0x3n ** 0x1n, 0x3n, 'The result of (0x3n ** 0x1n) is 0x3n'); + +assert.sameValue( + 0x2n ** 0x123n, + 0x8000000000000000000000000000000000000000000000000000000000000000000000000n, + 'The result of (0x2n ** 0x123n) is 0x8000000000000000000000000000000000000000000000000000000000000000000000000n' +); + +assert.sameValue( + 0x2n ** 0xFFn, + 0x8000000000000000000000000000000000000000000000000000000000000000n, + 'The result of (0x2n ** 0xFFn) is 0x8000000000000000000000000000000000000000000000000000000000000000n' +); + +assert.sameValue(0x2n ** 0x3n, 0x8n, 'The result of (0x2n ** 0x3n) is 0x8n'); +assert.sameValue(0x2n ** 0x2n, 0x4n, 'The result of (0x2n ** 0x2n) is 0x4n'); +assert.sameValue(0x2n ** 0x1n, 0x2n, 'The result of (0x2n ** 0x1n) is 0x2n'); +assert.sameValue(0x1n ** 0x123n, 0x1n, 'The result of (0x1n ** 0x123n) is 0x1n'); +assert.sameValue(0x1n ** 0xFFn, 0x1n, 'The result of (0x1n ** 0xFFn) is 0x1n'); +assert.sameValue(0x1n ** 0x3n, 0x1n, 'The result of (0x1n ** 0x3n) is 0x1n'); +assert.sameValue(0x1n ** 0x2n, 0x1n, 'The result of (0x1n ** 0x2n) is 0x1n'); +assert.sameValue(0x1n ** 0x1n, 0x1n, 'The result of (0x1n ** 0x1n) is 0x1n'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/bigint-errors.js b/js/src/tests/test262/language/expressions/exponentiation/bigint-errors.js new file mode 100644 index 0000000000..bae2a71624 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/bigint-errors.js @@ -0,0 +1,72 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: exponentiation operator ToNumeric with BigInt operands +esid: sec-exp-operator-runtime-semantics-evaluation +features: [BigInt, Symbol, Symbol.toPrimitive, computed-property-names, exponentiation] +---*/ +assert.throws(TypeError, function() { + Symbol('1') ** 0n; +}, 'Symbol("1") ** 0n throws TypeError'); + +assert.throws(TypeError, function() { + 0n ** Symbol('1'); +}, '0n ** Symbol("1") throws TypeError'); + +assert.throws(TypeError, function() { + Object(Symbol('1')) ** 0n; +}, 'Object(Symbol("1")) ** 0n throws TypeError'); + +assert.throws(TypeError, function() { + 0n ** Object(Symbol('1')); +}, '0n ** Object(Symbol("1")) throws TypeError'); + +assert.throws(TypeError, function() { + ({ + [Symbol.toPrimitive]: function() { + return Symbol('1'); + } + }) ** 0n; +}, '({[Symbol.toPrimitive]: function() {return Symbol("1");}}) ** 0n throws TypeError'); + +assert.throws(TypeError, function() { + 0n ** { + [Symbol.toPrimitive]: function() { + return Symbol('1'); + } + }; +}, '0n ** {[Symbol.toPrimitive]: function() {return Symbol("1");}} throws TypeError'); + +assert.throws(TypeError, function() { + ({ + valueOf: function() { + return Symbol('1'); + } + }) ** 0n; +}, '({valueOf: function() {return Symbol("1");}}) ** 0n throws TypeError'); + +assert.throws(TypeError, function() { + 0n ** { + valueOf: function() { + return Symbol('1'); + } + }; +}, '0n ** {valueOf: function() {return Symbol("1");}} throws TypeError'); + +assert.throws(TypeError, function() { + ({ + toString: function() { + return Symbol('1'); + } + }) ** 0n; +}, '({toString: function() {return Symbol("1");}}) ** 0n throws TypeError'); + +assert.throws(TypeError, function() { + 0n ** { + toString: function() { + return Symbol('1'); + } + }; +}, '0n ** {toString: function() {return Symbol("1");}} throws TypeError'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/bigint-negative-exponent-throws.js b/js/src/tests/test262/language/expressions/exponentiation/bigint-negative-exponent-throws.js new file mode 100644 index 0000000000..4e23375900 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/bigint-negative-exponent-throws.js @@ -0,0 +1,34 @@ +// Copyright (C) 2017 Robin Templeton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: If the BigInt exponent is < 0, throw a RangeError exception +esid: sec-exp-operator-runtime-semantics-evaluation +info: | + ExponentiationExpression: UpdateExpression ** ExponentiationExpression + + ... + 9. Return ? Type(base)::exponentiate(base, exponent). + + BigInt::exponentiate (base, exponent) + + 1. If exponent < 0, throw a RangeError exception. + ... +features: [BigInt, exponentiation] +---*/ +assert.throws(RangeError, function() { + 1n ** -1n; +}, '1n ** -1n throws RangeError'); + +assert.throws(RangeError, function() { + 0n ** -1n; +}, '0n ** -1n throws RangeError'); + +assert.throws(RangeError, function() { + (-1n) ** -1n; +}, '(-1n) ** -1n throws RangeError'); + +assert.throws(RangeError, function() { + 1n ** -100000000000000000n; +}, '1n ** -100000000000000000n throws RangeError'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/bigint-toprimitive.js b/js/src/tests/test262/language/expressions/exponentiation/bigint-toprimitive.js new file mode 100644 index 0000000000..5f2bb567dd --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/bigint-toprimitive.js @@ -0,0 +1,374 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: exponentiation operator ToNumeric with BigInt operands +esid: sec-exp-operator-runtime-semantics-evaluation +features: [BigInt, Symbol.toPrimitive, computed-property-names, exponentiation] +---*/ +function err() { + throw new Test262Error(); +} + +function MyError() {} + +assert.sameValue({ + [Symbol.toPrimitive]: function() { + return 2n; + }, + + valueOf: err, + toString: err +} ** 1n, 2n, 'The result of (({[Symbol.toPrimitive]: function() {return 2n;}, valueOf: err, toString: err}) ** 1n) is 2n'); + +assert.sameValue(1n ** { + [Symbol.toPrimitive]: function() { + return 2n; + }, + + valueOf: err, + toString: err +}, 1n, 'The result of (1n ** {[Symbol.toPrimitive]: function() {return 2n;}, valueOf: err, toString: err}) is 1n'); + +assert.sameValue({ + valueOf: function() { + return 2n; + }, + + toString: err +} ** 1n, 2n, 'The result of (({valueOf: function() {return 2n;}, toString: err}) ** 1n) is 2n'); + +assert.sameValue(1n ** { + valueOf: function() { + return 2n; + }, + + toString: err +}, 1n, 'The result of (1n ** {valueOf: function() {return 2n;}, toString: err}) is 1n'); + +assert.sameValue({ + toString: function() { + return 2n; + } +} ** 1n, 2n, 'The result of (({toString: function() {return 2n;}}) ** 1n) is 2n'); + +assert.sameValue(1n ** { + toString: function() { + return 2n; + } +}, 1n, 'The result of (1n ** {toString: function() {return 2n;}}) is 1n'); + +assert.sameValue({ + [Symbol.toPrimitive]: undefined, + + valueOf: function() { + return 2n; + } +} ** 1n, 2n, 'The result of (({[Symbol.toPrimitive]: undefined, valueOf: function() {return 2n;}}) ** 1n) is 2n'); + +assert.sameValue(1n ** { + [Symbol.toPrimitive]: undefined, + + valueOf: function() { + return 2n; + } +}, 1n, 'The result of (1n ** {[Symbol.toPrimitive]: undefined, valueOf: function() {return 2n;}}) is 1n'); + +assert.sameValue({ + [Symbol.toPrimitive]: null, + + valueOf: function() { + return 2n; + } +} ** 1n, 2n, 'The result of (({[Symbol.toPrimitive]: null, valueOf: function() {return 2n;}}) ** 1n) is 2n'); + +assert.sameValue(1n ** { + [Symbol.toPrimitive]: null, + + valueOf: function() { + return 2n; + } +}, 1n, 'The result of (1n ** {[Symbol.toPrimitive]: null, valueOf: function() {return 2n;}}) is 1n'); + +assert.sameValue({ + valueOf: null, + + toString: function() { + return 2n; + } +} ** 1n, 2n, 'The result of (({valueOf: null, toString: function() {return 2n;}}) ** 1n) is 2n'); + +assert.sameValue(1n ** { + valueOf: null, + + toString: function() { + return 2n; + } +}, 1n, 'The result of (1n ** {valueOf: null, toString: function() {return 2n;}}) is 1n'); + +assert.sameValue({ + valueOf: 1, + + toString: function() { + return 2n; + } +} ** 1n, 2n, 'The result of (({valueOf: 1, toString: function() {return 2n;}}) ** 1n) is 2n'); + +assert.sameValue(1n ** { + valueOf: 1, + + toString: function() { + return 2n; + } +}, 1n, 'The result of (1n ** {valueOf: 1, toString: function() {return 2n;}}) is 1n'); + +assert.sameValue({ + valueOf: {}, + + toString: function() { + return 2n; + } +} ** 1n, 2n, 'The result of (({valueOf: {}, toString: function() {return 2n;}}) ** 1n) is 2n'); + +assert.sameValue(1n ** { + valueOf: {}, + + toString: function() { + return 2n; + } +}, 1n, 'The result of (1n ** {valueOf: {}, toString: function() {return 2n;}}) is 1n'); + +assert.sameValue({ + valueOf: function() { + return {}; + }, + + toString: function() { + return 2n; + } +} ** 1n, 2n, 'The result of (({valueOf: function() {return {};}, toString: function() {return 2n;}}) ** 1n) is 2n'); + +assert.sameValue(1n ** { + valueOf: function() { + return {}; + }, + + toString: function() { + return 2n; + } +}, 1n, 'The result of (1n ** {valueOf: function() {return {};}, toString: function() {return 2n;}}) is 1n'); + +assert.sameValue({ + valueOf: function() { + return Object(12345); + }, + + toString: function() { + return 2n; + } +} ** 1n, 2n, 'The result of (({valueOf: function() {return Object(12345);}, toString: function() {return 2n;}}) ** 1n) is 2n'); + +assert.sameValue(1n ** { + valueOf: function() { + return Object(12345); + }, + + toString: function() { + return 2n; + } +}, 1n, 'The result of (1n ** {valueOf: function() {return Object(12345);}, toString: function() {return 2n;}}) is 1n'); + +assert.throws(TypeError, function() { + ({ + [Symbol.toPrimitive]: 1 + }) ** 0n; +}, '({[Symbol.toPrimitive]: 1}) ** 0n throws TypeError'); + +assert.throws(TypeError, function() { + 0n ** { + [Symbol.toPrimitive]: 1 + }; +}, '0n ** {[Symbol.toPrimitive]: 1} throws TypeError'); + +assert.throws(TypeError, function() { + ({ + [Symbol.toPrimitive]: {} + }) ** 0n; +}, '({[Symbol.toPrimitive]: {}}) ** 0n throws TypeError'); + +assert.throws(TypeError, function() { + 0n ** { + [Symbol.toPrimitive]: {} + }; +}, '0n ** {[Symbol.toPrimitive]: {}} throws TypeError'); + +assert.throws(TypeError, function() { + ({ + [Symbol.toPrimitive]: function() { + return Object(1); + } + }) ** 0n; +}, '({[Symbol.toPrimitive]: function() {return Object(1);}}) ** 0n throws TypeError'); + +assert.throws(TypeError, function() { + 0n ** { + [Symbol.toPrimitive]: function() { + return Object(1); + } + }; +}, '0n ** {[Symbol.toPrimitive]: function() {return Object(1);}} throws TypeError'); + +assert.throws(TypeError, function() { + ({ + [Symbol.toPrimitive]: function() { + return {}; + } + }) ** 0n; +}, '({[Symbol.toPrimitive]: function() {return {};}}) ** 0n throws TypeError'); + +assert.throws(TypeError, function() { + 0n ** { + [Symbol.toPrimitive]: function() { + return {}; + } + }; +}, '0n ** {[Symbol.toPrimitive]: function() {return {};}} throws TypeError'); + +assert.throws(MyError, function() { + ({ + [Symbol.toPrimitive]: function() { + throw new MyError(); + } + }) ** 0n; +}, '({[Symbol.toPrimitive]: function() {throw new MyError();}}) ** 0n throws MyError'); + +assert.throws(MyError, function() { + 0n ** { + [Symbol.toPrimitive]: function() { + throw new MyError(); + } + }; +}, '0n ** {[Symbol.toPrimitive]: function() {throw new MyError();}} throws MyError'); + +assert.throws(MyError, function() { + ({ + valueOf: function() { + throw new MyError(); + } + }) ** 0n; +}, '({valueOf: function() {throw new MyError();}}) ** 0n throws MyError'); + +assert.throws(MyError, function() { + 0n ** { + valueOf: function() { + throw new MyError(); + } + }; +}, '0n ** {valueOf: function() {throw new MyError();}} throws MyError'); + +assert.throws(MyError, function() { + ({ + toString: function() { + throw new MyError(); + } + }) ** 0n; +}, '({toString: function() {throw new MyError();}}) ** 0n throws MyError'); + +assert.throws(MyError, function() { + 0n ** { + toString: function() { + throw new MyError(); + } + }; +}, '0n ** {toString: function() {throw new MyError();}} throws MyError'); + +assert.throws(TypeError, function() { + ({ + valueOf: null, + toString: null + }) ** 0n; +}, '({valueOf: null, toString: null}) ** 0n throws TypeError'); + +assert.throws(TypeError, function() { + 0n ** { + valueOf: null, + toString: null + }; +}, '0n ** {valueOf: null, toString: null} throws TypeError'); + +assert.throws(TypeError, function() { + ({ + valueOf: 1, + toString: 1 + }) ** 0n; +}, '({valueOf: 1, toString: 1}) ** 0n throws TypeError'); + +assert.throws(TypeError, function() { + 0n ** { + valueOf: 1, + toString: 1 + }; +}, '0n ** {valueOf: 1, toString: 1} throws TypeError'); + +assert.throws(TypeError, function() { + ({ + valueOf: {}, + toString: {} + }) ** 0n; +}, '({valueOf: {}, toString: {}}) ** 0n throws TypeError'); + +assert.throws(TypeError, function() { + 0n ** { + valueOf: {}, + toString: {} + }; +}, '0n ** {valueOf: {}, toString: {}} throws TypeError'); + +assert.throws(TypeError, function() { + ({ + valueOf: function() { + return Object(1); + }, + + toString: function() { + return Object(1); + } + }) ** 0n; +}, '({valueOf: function() {return Object(1);}, toString: function() {return Object(1);}}) ** 0n throws TypeError'); + +assert.throws(TypeError, function() { + 0n ** { + valueOf: function() { + return Object(1); + }, + + toString: function() { + return Object(1); + } + }; +}, '0n ** {valueOf: function() {return Object(1);}, toString: function() {return Object(1);}} throws TypeError'); + +assert.throws(TypeError, function() { + ({ + valueOf: function() { + return {}; + }, + + toString: function() { + return {}; + } + }) ** 0n; +}, '({valueOf: function() {return {};}, toString: function() {return {};}}) ** 0n throws TypeError'); + +assert.throws(TypeError, function() { + 0n ** { + valueOf: function() { + return {}; + }, + + toString: function() { + return {}; + } + }; +}, '0n ** {valueOf: function() {return {};}, toString: function() {return {};}} throws TypeError'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/bigint-wrapped-values.js b/js/src/tests/test262/language/expressions/exponentiation/bigint-wrapped-values.js new file mode 100644 index 0000000000..9d272bbdb9 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/bigint-wrapped-values.js @@ -0,0 +1,47 @@ +// Copyright (C) 2017 Josh Wolfe. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: exponentiation operator ToNumeric with BigInt operands +esid: sec-exp-operator-runtime-semantics-evaluation +features: [BigInt, Symbol.toPrimitive, computed-property-names, exponentiation] +---*/ +assert.sameValue(Object(2n) ** 1n, 2n, 'The result of (Object(2n) ** 1n) is 2n'); +assert.sameValue(1n ** Object(2n), 1n, 'The result of (1n ** Object(2n)) is 1n'); + +assert.sameValue({ + [Symbol.toPrimitive]: function() { + return 2n; + } +} ** 1n, 2n, 'The result of (({[Symbol.toPrimitive]: function() {return 2n;}}) ** 1n) is 2n'); + +assert.sameValue(1n ** { + [Symbol.toPrimitive]: function() { + return 2n; + } +}, 1n, 'The result of (1n ** {[Symbol.toPrimitive]: function() {return 2n;}}) is 1n'); + +assert.sameValue({ + valueOf: function() { + return 2n; + } +} ** 1n, 2n, 'The result of (({valueOf: function() {return 2n;}}) ** 1n) is 2n'); + +assert.sameValue(1n ** { + valueOf: function() { + return 2n; + } +}, 1n, 'The result of (1n ** {valueOf: function() {return 2n;}}) is 1n'); + +assert.sameValue({ + toString: function() { + return 2n; + } +} ** 1n, 2n, 'The result of (({toString: function() {return 2n;}}) ** 1n) is 2n'); + +assert.sameValue(1n ** { + toString: function() { + return 2n; + } +}, 1n, 'The result of (1n ** {toString: function() {return 2n;}}) is 1n'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/bigint-zero-base-zero-exponent.js b/js/src/tests/test262/language/expressions/exponentiation/bigint-zero-base-zero-exponent.js new file mode 100644 index 0000000000..903a163ab1 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/bigint-zero-base-zero-exponent.js @@ -0,0 +1,22 @@ +// Copyright (C) 2017 Robin Templeton. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: If the BigInt base and exponent are both 0n, return 1n +esid: sec-exp-operator-runtime-semantics-evaluation +info: | + ExponentiationExpression: UpdateExpression ** ExponentiationExpression + + ... + 9. Return ? Type(base)::exponentiate(base, exponent). + + BigInt::exponentiate (base, exponent) + + 1. If exponent < 0, throw a RangeError exception. + 2. If base is 0n and exponent is 0n, return 1n. + 3. Return a BigInt representing the mathematical value of base raised to the power exponent. + ... +features: [BigInt, exponentiation] +---*/ +assert.sameValue(0n ** 0n, 1n, 'The result of (0n ** 0n) is 1n'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/browser.js b/js/src/tests/test262/language/expressions/exponentiation/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/browser.js diff --git a/js/src/tests/test262/language/expressions/exponentiation/exp-assignment-operator.js b/js/src/tests/test262/language/expressions/exponentiation/exp-assignment-operator.js new file mode 100644 index 0000000000..90562bbbec --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/exp-assignment-operator.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Rick Waldron +esid: sec-assignment-operators-runtime-semantics-evaluation +description: Compound Exponentiation Assignment Operator +info: | + AssignmentExpression: + LeftHandSideExpression AssignmentOperator AssignmentExpression + + 1. Let lref be the result of evaluating LeftHandSideExpression. + 2. Let lval be ? GetValue(lref). + 3. Let rref be the result of evaluating AssignmentExpression. + 4. Let rval be ? GetValue(rref). + 5. Let op be the @ where AssignmentOperator is @=. + 6. Let r be the result of applying op to lval and rval as if evaluating the expression lval op rval. + 7. Perform ? PutValue(lref, r). + 8. Return r. +features: [exponentiation] +---*/ + +var base = -3; + +assert.sameValue(base **= 3, -27, "(base **= 3) === -27; where base is -3"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/exp-operator-evaluation-order.js b/js/src/tests/test262/language/expressions/exponentiation/exp-operator-evaluation-order.js new file mode 100644 index 0000000000..93d4e64379 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/exp-operator-evaluation-order.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 Rick Waldron, André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Rick Waldron, André Bargull +esid: sec-exp-operator-runtime-semantics-evaluation +description: Exponentiation Operator expression order of evaluation +info: | + ExponentiationExpression: + UpdateExpression ** ExponentiationExpression + + 1. Let left be the result of evaluating UpdateExpression. + 2. Let leftValue be ? GetValue(left). + 3. Let right be the result of evaluating ExponentiationExpression. + 4. Let rightValue be ? GetValue(right). + 5. Let base be ? ToNumber(leftValue). + 6. Let exponent be ? ToNumber(rightValue). + 7. Return the result of Applying the ** operator with base and exponent as specified in 12.7.3.4. +features: [exponentiation] +---*/ + +var capture = []; +var leftValue = { valueOf() { capture.push("leftValue"); return 3; }}; +var rightValue = { valueOf() { capture.push("rightValue"); return 2; }}; + +(capture.push("left"), leftValue) ** (capture.push("right"), rightValue); + +// Expected per operator evaluation order: "left", "right", "leftValue", "rightValue" + +assert.sameValue(capture[0], "left", "Expected the 1st element captured to be 'left'"); +assert.sameValue(capture[1], "right", "Expected the 2nd element captured to be 'right'"); +assert.sameValue(capture[2], "leftValue", "Expected the 3rd element captured to be 'leftValue'"); +assert.sameValue(capture[3], "rightValue", "Expected the 4th element captured to be 'rightValue'"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/exp-operator-precedence-unary-expression-semantics.js b/js/src/tests/test262/language/expressions/exponentiation/exp-operator-precedence-unary-expression-semantics.js new file mode 100644 index 0000000000..eb52485c4a --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/exp-operator-precedence-unary-expression-semantics.js @@ -0,0 +1,69 @@ +// Copyright (C) 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Rick Waldron +esid: sec-unary-operators +description: Exponentiation Operator expression precedence of unary operators +info: | + ExponentiationExpression : + UnaryExpression + ... + + UnaryExpression : + ... + `delete` UnaryExpression + `void` UnaryExpression + `typeof` UnaryExpression + `+` UnaryExpression + `-` UnaryExpression + `~` UnaryExpression + `!` UnaryExpression +features: [exponentiation] +---*/ + +assert.sameValue(-(3 ** 2), -9, "-(3 ** 2) === -9"); +assert.sameValue(+(3 ** 2), 9, "+(3 ** 2) === 9"); +assert.sameValue(~(3 ** 2), -10, "~(3 ** 2) === -10"); +assert.sameValue(!(3 ** 2), false, "!(3 ** 2) === false"); + + +assert.sameValue(2 ** -2, 0.25); + +var o = { p: 1 }; + +assert.sameValue(2 ** delete o.p, 2, "delete o.p -> true -> ToNumber(true) -> 1"); +assert.sameValue(2 ** void 1, NaN, "void 1 -> undefined -> ToNumber(undefined) -> NaN"); +assert.sameValue(2 ** typeof 1, NaN, "typeof 1 -> 'number' -> ToNumber('number') -> NaN"); + +var s = "2"; +var n = 2; + +assert.sameValue(2 ** +s, 4, "+s -> +'2' -> 2 -> ToNumber(2) -> 2"); +assert.sameValue(2 ** +n, 4, "+s -> +2 -> 2 -> ToNumber(2) -> 2"); + +assert.sameValue(2 ** -s, 0.25, "-s -> -'2' -> -2 -> ToNumber(-2) -> -2"); +assert.sameValue(2 ** -n, 0.25, "-s -> -2 -> -2 -> ToNumber(-2) -> -2"); + +assert.sameValue(2 ** ~s, 0.125, "~s -> ~'2' -> -3 -> ToNumber(-3) -> -3"); +assert.sameValue(2 ** ~n, 0.125, "~s -> ~2 -> -3 -> ToNumber(-3) -> -3"); + +assert.sameValue(2 ** !s, 1, "!s -> !'2' -> false -> ToNumber(false) -> 0"); +assert.sameValue(2 ** !n, 1, "!s -> !2 -> false -> ToNumber(false) -> 0"); + + +var capture = []; +var leftValue = { valueOf() { capture.push("leftValue"); return 3; }}; +var rightValue = { valueOf() { capture.push("rightValue"); return 2; }}; + +(capture.push("left"), leftValue) ** +(capture.push("right"), rightValue); +// ^ +// Changes the order + +// Expected per operator evaluation order: "left", "right", "rightValue", "leftValue" +assert.sameValue(capture[0], "left", "Expected the 1st element captured to be 'left'"); +assert.sameValue(capture[1], "right", "Expected the 2nd element captured to be 'right'"); +assert.sameValue(capture[2], "rightValue", "Expected the 3rd element captured to be 'rightValue'"); +assert.sameValue(capture[3], "leftValue", "Expected the 4th element captured to be 'leftValue'"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/exp-operator-precedence-update-expression-semantics.js b/js/src/tests/test262/language/expressions/exponentiation/exp-operator-precedence-update-expression-semantics.js new file mode 100644 index 0000000000..c799fd3422 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/exp-operator-precedence-update-expression-semantics.js @@ -0,0 +1,60 @@ +// Copyright (C) 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Rick Waldron +esid: sec-update-expressions +description: Exponentiation Operator expression precedence of update operators +info: | + ExponentiationExpression : + ... + UpdateExpression `**` ExponentiationExpression + + UpdateExpression : + LeftHandSideExpression `++` + LeftHandSideExpression `--` + `++` UnaryExpression + `--` UnaryExpression +features: [exponentiation] +---*/ + +var base = 4; +assert.sameValue(--base ** 2, 9, "(--base ** 2) === 9"); +assert.sameValue(++base ** 2, 16, "(++base ** 2) === 16"); +assert.sameValue(base++ ** 2, 16, "(base++ ** 2) === 16"); +assert.sameValue(base-- ** 2, 25, "(base-- ** 2) === 25"); + +base = 4; + +// --base ** --base ** 2 -> 3 ** 2 ** 2 -> 3 ** (2 ** 2) -> 81 +assert.sameValue( + --base ** --base ** 2, + Math.pow(3, Math.pow(2, 2)), + "(--base ** --base ** 2) === Math.pow(3, Math.pow(2, 2))" +); + +// ++base ** ++base ** 2 -> 3 ** 4 ** 2 -> 3 ** (4 ** 2) -> 43046721 +assert.sameValue( + ++base ** ++base ** 2, + Math.pow(3, Math.pow(4, 2)), + "(++base ** ++base ** 2) === Math.pow(3, Math.pow(4, 2))" +); + +base = 4; + +// base-- ** base-- ** 2 -> 4 ** 3 ** 2 -> 4 ** (3 ** 2) -> 262144 +assert.sameValue( + base-- ** base-- ** 2, + Math.pow(4, Math.pow(3, 2)), + "(base-- ** base-- ** 2) === Math.pow(4, Math.pow(3, 2))" +); + +// base++ ** base++ ** 2 -> 2 ** 3 ** 2 -> 2 ** (3 ** 2) -> 262144 +assert.sameValue( + base++ ** base++ ** 2, + Math.pow(2, Math.pow(3, 2)), + "(base++ ** base++ ** 2) === Math.pow(2, Math.pow(3, 2))" +); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/exp-operator-syntax-error-bitnot-unary-expression-base.js b/js/src/tests/test262/language/expressions/exponentiation/exp-operator-syntax-error-bitnot-unary-expression-base.js new file mode 100644 index 0000000000..a2e5f9dd8c --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/exp-operator-syntax-error-bitnot-unary-expression-base.js @@ -0,0 +1,26 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Rick Waldron +esid: sec-unary-operators +description: Exponentiation Expression syntax error, `~` UnaryExpression +info: | + ExponentiationExpression : + UnaryExpression + ... + + UnaryExpression : + ... + `~` UnaryExpression + ... +features: [exponentiation] + +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +~3 ** 2; diff --git a/js/src/tests/test262/language/expressions/exponentiation/exp-operator-syntax-error-delete-unary-expression-base.js b/js/src/tests/test262/language/expressions/exponentiation/exp-operator-syntax-error-delete-unary-expression-base.js new file mode 100644 index 0000000000..71a1807a02 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/exp-operator-syntax-error-delete-unary-expression-base.js @@ -0,0 +1,26 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Rick Waldron +esid: sec-unary-operators +description: Exponentiation Expression syntax error, `delete` UnaryExpression +info: | + ExponentiationExpression : + UnaryExpression + ... + + UnaryExpression : + ... + `delete` UnaryExpression + ... +features: [exponentiation] + +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +delete o.p ** 2; diff --git a/js/src/tests/test262/language/expressions/exponentiation/exp-operator-syntax-error-logical-not-unary-expression-base.js b/js/src/tests/test262/language/expressions/exponentiation/exp-operator-syntax-error-logical-not-unary-expression-base.js new file mode 100644 index 0000000000..8c1eabdeb1 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/exp-operator-syntax-error-logical-not-unary-expression-base.js @@ -0,0 +1,26 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Rick Waldron +esid: sec-unary-operators +description: Exponentiation Expression syntax error, `!` UnaryExpression +info: | + ExponentiationExpression : + UnaryExpression + ... + + UnaryExpression : + ... + `!` UnaryExpression + ... +features: [exponentiation] + +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +!1 ** 2; diff --git a/js/src/tests/test262/language/expressions/exponentiation/exp-operator-syntax-error-negate-unary-expression-base.js b/js/src/tests/test262/language/expressions/exponentiation/exp-operator-syntax-error-negate-unary-expression-base.js new file mode 100644 index 0000000000..bf87dc531a --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/exp-operator-syntax-error-negate-unary-expression-base.js @@ -0,0 +1,26 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Rick Waldron +esid: sec-unary-operators +description: Exponentiation Expression syntax error, `-` UnaryExpression +info: | + ExponentiationExpression : + UnaryExpression + ... + + UnaryExpression : + ... + `-` UnaryExpression + ... +features: [exponentiation] + +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +-3 ** 2; diff --git a/js/src/tests/test262/language/expressions/exponentiation/exp-operator-syntax-error-plus-unary-expression-base.js b/js/src/tests/test262/language/expressions/exponentiation/exp-operator-syntax-error-plus-unary-expression-base.js new file mode 100644 index 0000000000..b15267e339 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/exp-operator-syntax-error-plus-unary-expression-base.js @@ -0,0 +1,26 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Rick Waldron +esid: sec-unary-operators +description: Exponentiation Expression syntax error, `+` UnaryExpression +info: | + ExponentiationExpression : + UnaryExpression + ... + + UnaryExpression : + ... + `+` UnaryExpression + ... +features: [exponentiation] + +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); ++1 ** 2; diff --git a/js/src/tests/test262/language/expressions/exponentiation/exp-operator-syntax-error-typeof-unary-expression-base.js b/js/src/tests/test262/language/expressions/exponentiation/exp-operator-syntax-error-typeof-unary-expression-base.js new file mode 100644 index 0000000000..ed1bdbaaf9 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/exp-operator-syntax-error-typeof-unary-expression-base.js @@ -0,0 +1,26 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Rick Waldron +esid: sec-unary-operators +description: Exponentiation Expression syntax error, `typeof` UnaryExpression +info: | + ExponentiationExpression : + UnaryExpression + ... + + UnaryExpression : + ... + `typeof` UnaryExpression + ... +features: [exponentiation] + +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +typeof 1 ** 2; diff --git a/js/src/tests/test262/language/expressions/exponentiation/exp-operator-syntax-error-void-unary-expression-base.js b/js/src/tests/test262/language/expressions/exponentiation/exp-operator-syntax-error-void-unary-expression-base.js new file mode 100644 index 0000000000..4322445aff --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/exp-operator-syntax-error-void-unary-expression-base.js @@ -0,0 +1,26 @@ +// |reftest| error:SyntaxError +// Copyright (C) 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Rick Waldron +esid: sec-unary-operators +description: Exponentiation Expression syntax error, `void` UnaryExpression +info: | + ExponentiationExpression : + UnaryExpression + ... + + UnaryExpression : + ... + `void` UnaryExpression + ... +features: [exponentiation] + +negative: + phase: parse + type: SyntaxError +---*/ + +$DONOTEVALUATE(); +void 1 ** 2; diff --git a/js/src/tests/test262/language/expressions/exponentiation/exp-operator.js b/js/src/tests/test262/language/expressions/exponentiation/exp-operator.js new file mode 100644 index 0000000000..1cb99d0a12 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/exp-operator.js @@ -0,0 +1,23 @@ +// Copyright (C) 2016 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: Rick Waldron +esid: sec-exp-operator +description: > + Performs exponential calculation on operands. Same algorithm as %MathPow%(base, exponent) +features: [exponentiation] +---*/ + +var exponent = 2; +assert.sameValue(2 ** 3, 8, "(2 ** 3) === 8"); +assert.sameValue(3 * 2 ** 3, 24, "(3 * 2 ** 3) === 24"); +assert.sameValue(2 ** ++exponent, 8, "(2 ** ++exponent) === 8"); +assert.sameValue(2 ** -1 * 2, 1, "(2 ** -1 * 2) === 1"); +assert.sameValue(2 ** 2 * 4, 16, "(2 ** 2 * 4) === 16"); +assert.sameValue(2 ** 2 / 2, 2, "(2 ** 2 / 2) === 2"); +assert.sameValue(2 ** (3 ** 2), 512, "(2 ** (3 ** 2)) === 512"); +assert.sameValue(2 ** 3 ** 2, 512, "(2 ** 3 ** 2) === 512"); +assert.sameValue(16 / 2 ** 2, 4, "(16 / 2 ** 2) === 4"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/int32_min-exponent.js b/js/src/tests/test262/language/expressions/exponentiation/int32_min-exponent.js new file mode 100644 index 0000000000..ae10edbc53 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/int32_min-exponent.js @@ -0,0 +1,21 @@ +// Copyright (C) 2018 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-applying-the-exp-operator +description: > + Using -(2**31) as exponent with the exponentiation operator should behave + as expected. +features: [exponentiation] +---*/ + +const INT32_MIN = -2147483648; + +assert.sameValue(2**INT32_MIN, +0.0, + "2**-(gonzo huge exponent > 1074) should be +0 because " + + "2**-1074 is the smallest positive IEEE-754 number"); + +assert.sameValue(1**INT32_MIN, 1, + "1**-(gonzo huge exponent > 1074) should be 1"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/order-of-evaluation.js b/js/src/tests/test262/language/expressions/exponentiation/order-of-evaluation.js new file mode 100644 index 0000000000..f1e5fc82ac --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/order-of-evaluation.js @@ -0,0 +1,140 @@ +// Copyright (C) 2018 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-exp-operator-runtime-semantics-evaluation +description: Type coercion order of operations for exponentiation operator +features: [Symbol, exponentiation] +info: | + Evaluate lhs + Evaluate rhs + ToNumeric(lhs) + ToNumeric(rhs) +---*/ + +function MyError() {} +var trace; + +// ?GetValue(lhs) throws. +trace = ""; +assert.throws(MyError, function() { + (function() { + trace += "1"; + throw new MyError(); + })() ** (function() { + trace += "2"; + throw new Test262Error("should not be evaluated"); + })(); +}, "?GetValue(lhs) throws."); +assert.sameValue(trace, "1", "?GetValue(lhs) throws."); + +// ?GetValue(rhs) throws. +trace = ""; +assert.throws(MyError, function() { + (function() { + trace += "1"; + return { + valueOf: function() { + trace += "3"; + throw new Test262Error("should not be evaluated"); + } + }; + })() ** (function() { + trace += "2"; + throw new MyError(); + })(); +}, "?GetValue(rhs) throws."); +assert.sameValue(trace, "12", "?GetValue(rhs) throws."); + +// ?ToPrimive(lhs) throws. +trace = ""; +assert.throws(MyError, function() { + (function() { + trace += "1"; + return { + valueOf: function() { + trace += "3"; + throw new MyError(); + } + }; + })() ** (function() { + trace += "2"; + return { + valueOf: function() { + trace += "4"; + throw new Test262Error("should not be evaluated"); + } + }; + })(); +}, "?ToPrimive(lhs) throws."); +assert.sameValue(trace, "123", "?ToPrimive(lhs) throws."); + +// ?ToPrimive(rhs) throws. +trace = ""; +assert.throws(MyError, function() { + (function() { + trace += "1"; + return { + valueOf: function() { + trace += "3"; + return 1; + } + }; + })() ** (function() { + trace += "2"; + return { + valueOf: function() { + trace += "4"; + throw new MyError(); + } + }; + })(); +}, "?ToPrimive(rhs) throws."); +assert.sameValue(trace, "1234", "?ToPrimive(rhs) throws."); + +// ?ToNumeric(lhs) throws. +trace = ""; +assert.throws(TypeError, function() { + (function() { + trace += "1"; + return { + valueOf: function() { + trace += "3"; + return Symbol("1"); + } + }; + })() ** (function() { + trace += "2"; + return { + valueOf: function() { + trace += "4"; + throw new Test262Error("should not be evaluated"); + } + }; + })(); +}, "?ToNumeric(lhs) throws."); +assert.sameValue(trace, "123", "?ToNumeric(lhs) throws."); + +// GetValue(lhs) throws. +trace = ""; +assert.throws(TypeError, function() { + (function() { + trace += "1"; + return { + valueOf: function() { + trace += "3"; + return 1; + } + }; + })() ** (function() { + trace += "2"; + return { + valueOf: function() { + trace += "4"; + return Symbol("1"); + } + }; + })(); +}, "GetValue(lhs) throws."); +assert.sameValue(trace, "1234", "GetValue(lhs) throws."); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/language/expressions/exponentiation/shell.js b/js/src/tests/test262/language/expressions/exponentiation/shell.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/exponentiation/shell.js |