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

Unified Diff: test/mjsunit/undetectable.js

Issue 1132303003: Add %GetUndetectable() test intrinsic and add tests for undetectables. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 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 | « src/runtime/runtime-test.cc ('k') | test/mjsunit/undetectable-compare.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/undetectable.js
diff --git a/test/mjsunit/undetectable.js b/test/mjsunit/undetectable.js
new file mode 100644
index 0000000000000000000000000000000000000000..f4871f995c53cfbdaadcdaffbd737bf2215c9930
--- /dev/null
+++ b/test/mjsunit/undetectable.js
@@ -0,0 +1,87 @@
+// Copyright 2015 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: --allow-natives-syntax
+
+var obj = %GetUndetectable();
+
+function shouldNotBeTaken() {
+ fail("Undetectable branch should not be taken", "branch was taken");
+}
+
+function shouldBeTaken() {
+ fail("Inverted Undetectable branch should be taken", "branch was not taken");
+}
+
+function testCompares() {
+ assertTrue(!obj);
+ assertFalse(!!obj);
+ assertFalse(obj == true);
+ assertFalse(obj == false);
+ assertFalse(obj === true);
+ assertFalse(obj === false);
+ assertEquals(2, obj ? 1 : 2);
+ assertEquals(obj, true && obj);
+ assertEquals(obj, false || obj);
+}
+
+function testIfs() {
+ if (obj) {
+ shouldNotBeTaken();
+ }
+
+ if (obj) {
+ shouldNotBeTaken();
+ } else {
+ // do nothing
+ }
+
+ if (!obj) {
+ // do nothing
+ } else {
+ shouldBeTaken();
+ }
+}
+
+function testWhiles() {
+ while (obj) {
+ shouldNotBeTaken();
+ }
+
+ var i = 0;
+ while (!obj) {
+ i++;
+ break;
+ }
+
+ assertEquals(1, i);
+}
+
+function testFors() {
+ for (var i = 0; obj; i++) {
+ shouldNotBeTaken();
+ }
+
+ var j = 0;
+ for (var i = 0; !obj; i++) {
+ j++;
+ break;
+ }
+
+ assertEquals(1, j);
+}
+
+for (var j = 0; j < 5; j++) {
+ testCompares();
+ testIfs();
+ testWhiles();
+ testFors();
+
+ if (j == 3) {
+ %OptimizeFunctionOnNextCall(testCompares);
+ %OptimizeFunctionOnNextCall(testIfs);
+ %OptimizeFunctionOnNextCall(testWhiles);
+ %OptimizeFunctionOnNextCall(testFors);
+ }
+}
« no previous file with comments | « src/runtime/runtime-test.cc ('k') | test/mjsunit/undetectable-compare.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698