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

Unified 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, 10 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+})();
« 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