Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Side by Side Diff: test/mjsunit/harmony/exponentiation.js

Issue 953563002: Implement experimental exponentiation operator (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: use Number() instead of OrderedNumber() to include NaN Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/compiler/test-run-jsops.cc ('k') | test/unittests/compiler/js-operator-unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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(4, 2 ** { toString: function() { return 2; } });
27 assertEquals(4, { valueOf: function() { return 2; } } ** 2);
28 assertEquals(4, { toString: function() { return 2; } } ** 2);
29 assertEquals(NaN, 2 ** {});
30 assertEquals(4, 2 ** [2]);
31 assertEquals(4, [2] ** 2);
32 assertEquals(4, [2] ** [2]);
33 })();
34
35
36 (function testErrors() {
37 function MyError() {}
38
39 assertThrows(function() {
40 return 2 ** { valueOf: function() { throw new MyError(); } };
41 }, MyError);
42
43 assertThrows(function() {
44 return { valueOf: function() { throw new MyError(); } } ** 2;
45 }, MyError);
46 })();
47
48
49 (function testCommonCases() {
50 assertEquals(1, 0 ** 0); // Undefined case, but consistent with Math.pow
51 for (var i = 1; i < 10; ++i) {
52 assertEquals(0, 0 ** i);
53 assertEquals(Infinity, 0 ** -i);
54 assertEquals(1, i ** 0);
55 assertEquals(1, -i ** 0);
56 if (i & 1) {
57 assertEquals(-1, -1 ** i);
58 } else {
59 assertEquals(1, -1 ** i);
60 }
61 }
62
63 for (var i = 0, j = 1; i < 32; ++i, j *= 2) {
64 assertEquals(j, 2 ** i);
65 }
66 })();
67
68
69 (function testAssignment() {
70 var calls = 0;
71 var q = { q: 3 };
72 var o = {
73 get p() {
74 calls++;
75 return q;
76 }
77 };
78
79 o.p.q **= 2;
80 assertEquals(1, calls);
81 assertEquals(9, o.p.q);
82 })();
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-run-jsops.cc ('k') | test/unittests/compiler/js-operator-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698