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

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: Add more tests and fix some bugs 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
« src/compiler/typer.cc ('K') | « src/typing.cc ('k') | no next file » | 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..71cb5063ecaa9ef9b7ec1318674b423c91b9f3dd
--- /dev/null
+++ b/test/mjsunit/harmony/exponentiation.js
@@ -0,0 +1,73 @@
+// 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(NaN, 2 ** {});
+
+ 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);
+})();
« src/compiler/typer.cc ('K') | « src/typing.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698