| Index: test/mjsunit/harmony/exponentiation.js
|
| diff --git a/test/mjsunit/harmony/exponentiation.js b/test/mjsunit/harmony/exponentiation.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..415c397e4d03f3376f45b83c0b5bc94d2185dc75
|
| --- /dev/null
|
| +++ b/test/mjsunit/harmony/exponentiation.js
|
| @@ -0,0 +1,82 @@
|
| +// Copyright 2014 the V8 project authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +// Flags: --harmony-exponentiation
|
| +
|
| +(function testPrecedence() {
|
| + assertEquals(8, 2 ** 3);
|
| + assertEquals(24, 3 * 2 ** 3);
|
| + assertEquals(512, 2 ** 3 ** 2);
|
| + assertEquals(512, 2 ** (3 ** 2));
|
| + assertEquals(8, 0 || 2 ** 3);
|
| + assertEquals(0, 0 && 2 ** 3);
|
| + assertEquals(1, 2 ** -1 * 2);
|
| + var x = 2;
|
| + assertEquals(8, 2 ** ++x);
|
| + assertEquals(4, 2 ** --x);
|
| + assertEquals(3, 2 ** 2 - 1);
|
| + assertEquals(9007199254740991, 2 ** 53 - 1);
|
| +})();
|
| +
|
| +
|
| +(function testTypeCoercion() {
|
| + assertEquals(4, 2 ** '2');
|
| + assertEquals(4, 2 ** { valueOf: function() { return 2; } });
|
| + assertEquals(4, 2 ** { toString: function() { return 2; } });
|
| + assertEquals(4, { valueOf: function() { return 2; } } ** 2);
|
| + assertEquals(4, { toString: function() { return 2; } } ** 2);
|
| + assertEquals(NaN, 2 ** {});
|
| + assertEquals(4, 2 ** [2]);
|
| + assertEquals(4, [2] ** 2);
|
| + assertEquals(4, [2] ** [2]);
|
| +})();
|
| +
|
| +
|
| +(function testErrors() {
|
| + function MyError() {}
|
| +
|
| + assertThrows(function() {
|
| + return 2 ** { valueOf: function() { throw new MyError(); } };
|
| + }, MyError);
|
| +
|
| + assertThrows(function() {
|
| + return { valueOf: function() { throw new MyError(); } } ** 2;
|
| + }, MyError);
|
| +})();
|
| +
|
| +
|
| +(function testCommonCases() {
|
| + assertEquals(1, 0 ** 0); // Undefined case, but consistent with Math.pow
|
| + for (var i = 1; i < 10; ++i) {
|
| + assertEquals(0, 0 ** i);
|
| + assertEquals(Infinity, 0 ** -i);
|
| + assertEquals(1, i ** 0);
|
| + assertEquals(1, -i ** 0);
|
| + if (i & 1) {
|
| + assertEquals(-1, -1 ** i);
|
| + } else {
|
| + assertEquals(1, -1 ** i);
|
| + }
|
| + }
|
| +
|
| + for (var i = 0, j = 1; i < 32; ++i, j *= 2) {
|
| + assertEquals(j, 2 ** i);
|
| + }
|
| +})();
|
| +
|
| +
|
| +(function testAssignment() {
|
| + var calls = 0;
|
| + var q = { q: 3 };
|
| + var o = {
|
| + get p() {
|
| + calls++;
|
| + return q;
|
| + }
|
| + };
|
| +
|
| + o.p.q **= 2;
|
| + assertEquals(1, calls);
|
| + assertEquals(9, o.p.q);
|
| +})();
|
|
|