OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --harmony-exponentiation |
| 6 |
| 7 (function testPrecedence() { |
| 8 assertEquals(8, 2 ** 3); |
| 9 assertEquals(24, 3 * 2 ** 3); |
| 10 assertEquals(512, 2 ** 3 ** 2); |
| 11 assertEquals(512, 2 ** (3 ** 2)); |
| 12 assertEquals(8, 0 || 2 ** 3); |
| 13 assertEquals(0, 0 && 2 ** 3); |
| 14 assertEquals(1, 2 ** -1 * 2); |
| 15 var x = 2; |
| 16 assertEquals(8, 2 ** ++x); |
| 17 assertEquals(4, 2 ** --x); |
| 18 assertEquals(3, 2 ** 2 - 1); |
| 19 assertEquals(9007199254740991, 2 ** 53 - 1); |
| 20 })(); |
| 21 |
| 22 |
| 23 (function testTypeCoercion() { |
| 24 assertEquals(4, 2 ** '2'); |
| 25 assertEquals(4, 2 ** { valueOf: function() { return 2; } }); |
| 26 assertEquals(NaN, 2 ** {}); |
| 27 |
| 28 function MyError() {} |
| 29 |
| 30 assertThrows(function() { |
| 31 return 2 ** { valueOf: function() { throw new MyError(); } }; |
| 32 }, MyError); |
| 33 |
| 34 assertThrows(function() { |
| 35 return { valueOf: function() { throw new MyError(); } } ** 2; |
| 36 }, MyError); |
| 37 })(); |
| 38 |
| 39 |
| 40 (function testCommonCases() { |
| 41 assertEquals(1, 0 ** 0); // Undefined case, but consistent with Math.pow |
| 42 for (var i = 1; i < 10; ++i) { |
| 43 assertEquals(0, 0 ** i); |
| 44 assertEquals(Infinity, 0 ** -i); |
| 45 assertEquals(1, i ** 0); |
| 46 assertEquals(1, -i ** 0); |
| 47 if (i & 1) { |
| 48 assertEquals(-1, -1 ** i); |
| 49 } else { |
| 50 assertEquals(1, -1 ** i); |
| 51 } |
| 52 } |
| 53 |
| 54 for (var i = 0, j = 1; i < 32; ++i, j *= 2) { |
| 55 assertEquals(j, 2 ** i); |
| 56 } |
| 57 })(); |
| 58 |
| 59 |
| 60 (function testAssignment() { |
| 61 var calls = 0; |
| 62 var q = { q: 3 }; |
| 63 var o = { |
| 64 get p() { |
| 65 calls++; |
| 66 return q; |
| 67 } |
| 68 }; |
| 69 |
| 70 o.p.q **= 2; |
| 71 assertEquals(1, calls); |
| 72 assertEquals(9, o.p.q); |
| 73 })(); |
OLD | NEW |