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

Unified Diff: test/mjsunit/compiler/object-isprototypeof.js

Issue 2934893002: [builtins] Properly optimize Object.prototype.isPrototypeOf. (Closed)
Patch Set: Address feedback. Created 3 years, 6 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-object.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/compiler/object-isprototypeof.js
diff --git a/test/mjsunit/compiler/object-isprototypeof.js b/test/mjsunit/compiler/object-isprototypeof.js
new file mode 100644
index 0000000000000000000000000000000000000000..284a4387d60b455c7590122364817dd929f186fd
--- /dev/null
+++ b/test/mjsunit/compiler/object-isprototypeof.js
@@ -0,0 +1,153 @@
+// Copyright 2017 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
+
+// Test corner cases with null/undefined receivers.
+(function() {
+ function foo(x, y) { return Object.prototype.isPrototypeOf.call(x, y); }
+
+ assertThrows(() => foo(null, {}));
+ assertThrows(() => foo(undefined, {}));
+ assertThrows(() => foo(null, []));
+ assertThrows(() => foo(undefined, []));
+ assertFalse(foo(null, 0));
+ assertFalse(foo(undefined, 0));
+ assertFalse(foo(null, ""));
+ assertFalse(foo(undefined, ""));
+ assertFalse(foo(null, null));
+ assertFalse(foo(undefined, null));
+ assertFalse(foo(null, undefined));
+ assertFalse(foo(undefined, undefined));
+ %OptimizeFunctionOnNextCall(foo);
+ assertThrows(() => foo(null, {}));
+ assertThrows(() => foo(undefined, {}));
+ assertThrows(() => foo(null, []));
+ assertThrows(() => foo(undefined, []));
+ assertFalse(foo(null, 0));
+ assertFalse(foo(undefined, 0));
+ assertFalse(foo(null, ""));
+ assertFalse(foo(undefined, ""));
+ assertFalse(foo(null, null));
+ assertFalse(foo(undefined, null));
+ assertFalse(foo(null, undefined));
+ assertFalse(foo(undefined, undefined));
+})();
+
+// Test general constructor prototype case.
+(function() {
+ function A() {}
+ A.prototype = {};
+ var a = new A;
+
+ function foo(x) { return A.prototype.isPrototypeOf(x); }
+
+ assertFalse(foo(0));
+ assertFalse(foo(""));
+ assertFalse(foo(null));
+ assertFalse(foo(undefined));
+ assertFalse(foo({}));
+ assertFalse(foo([]));
+ assertTrue(foo(a));
+ assertTrue(foo(new A));
+ assertTrue(foo({__proto__: a}));
+ assertTrue(foo({__proto__: A.prototype}));
+ %OptimizeFunctionOnNextCall(foo);
+ assertFalse(foo(0));
+ assertFalse(foo(""));
+ assertFalse(foo(null));
+ assertFalse(foo(undefined));
+ assertFalse(foo({}));
+ assertFalse(foo([]));
+ assertTrue(foo(a));
+ assertTrue(foo(new A));
+ assertTrue(foo({__proto__: a}));
+ assertTrue(foo({__proto__: A.prototype}));
+})();
+
+// Test known primitive values.
+(function() {
+ function A() {}
+ A.prototype = {};
+ var a = new A;
+
+ function foo() { return A.prototype.isPrototypeOf(0); }
+
+ assertFalse(foo());
+ assertFalse(foo());
+ %OptimizeFunctionOnNextCall(foo);
+ assertFalse(foo());
+})();
+(function() {
+ function A() {}
+ A.prototype = {};
+ var a = new A;
+
+ function foo() { return A.prototype.isPrototypeOf(null); }
+
+ assertFalse(foo());
+ assertFalse(foo());
+ %OptimizeFunctionOnNextCall(foo);
+ assertFalse(foo());
+})();
+(function() {
+ function A() {}
+ A.prototype = {};
+ var a = new A;
+
+ function foo() { return A.prototype.isPrototypeOf(undefined); }
+
+ assertFalse(foo());
+ assertFalse(foo());
+ %OptimizeFunctionOnNextCall(foo);
+ assertFalse(foo());
+})();
+
+// Test constant-folded prototype chain checks.
+(function() {
+ function A() {}
+ A.prototype = {};
+ var a = new A;
+
+ function foo() { return A.prototype.isPrototypeOf(a); }
+
+ assertTrue(foo());
+ assertTrue(foo());
+ %OptimizeFunctionOnNextCall(foo);
+ assertTrue(foo());
+})();
+(function() {
+ function A() {}
+ var a = new A;
+ A.prototype = {};
+
+ function foo() { return A.prototype.isPrototypeOf(a); }
+
+ assertFalse(foo());
+ assertFalse(foo());
+ %OptimizeFunctionOnNextCall(foo);
+ assertFalse(foo());
+})();
+
+// Test Array prototype chain checks.
+(function() {
+ var a = [];
+
+ function foo() { return Array.prototype.isPrototypeOf(a); }
+
+ assertTrue(foo());
+ assertTrue(foo());
+ %OptimizeFunctionOnNextCall(foo);
+ assertTrue(foo());
+})();
+(function() {
+ var a = [];
+
+ function foo() { return Object.prototype.isPrototypeOf(a); }
+
+ assertTrue(foo());
+ assertTrue(foo());
+ %OptimizeFunctionOnNextCall(foo);
+ assertTrue(foo());
+})();
« no previous file with comments | « src/runtime/runtime-object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698