OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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: --allow-natives-syntax |
| 6 |
| 7 // Test corner cases with null/undefined receivers. |
| 8 (function() { |
| 9 function foo(x, y) { return Object.prototype.isPrototypeOf.call(x, y); } |
| 10 |
| 11 assertThrows(() => foo(null, {})); |
| 12 assertThrows(() => foo(undefined, {})); |
| 13 assertThrows(() => foo(null, [])); |
| 14 assertThrows(() => foo(undefined, [])); |
| 15 assertFalse(foo(null, 0)); |
| 16 assertFalse(foo(undefined, 0)); |
| 17 assertFalse(foo(null, "")); |
| 18 assertFalse(foo(undefined, "")); |
| 19 assertFalse(foo(null, null)); |
| 20 assertFalse(foo(undefined, null)); |
| 21 assertFalse(foo(null, undefined)); |
| 22 assertFalse(foo(undefined, undefined)); |
| 23 %OptimizeFunctionOnNextCall(foo); |
| 24 assertThrows(() => foo(null, {})); |
| 25 assertThrows(() => foo(undefined, {})); |
| 26 assertThrows(() => foo(null, [])); |
| 27 assertThrows(() => foo(undefined, [])); |
| 28 assertFalse(foo(null, 0)); |
| 29 assertFalse(foo(undefined, 0)); |
| 30 assertFalse(foo(null, "")); |
| 31 assertFalse(foo(undefined, "")); |
| 32 assertFalse(foo(null, null)); |
| 33 assertFalse(foo(undefined, null)); |
| 34 assertFalse(foo(null, undefined)); |
| 35 assertFalse(foo(undefined, undefined)); |
| 36 })(); |
| 37 |
| 38 // Test general constructor prototype case. |
| 39 (function() { |
| 40 function A() {} |
| 41 A.prototype = {}; |
| 42 var a = new A; |
| 43 |
| 44 function foo(x) { return A.prototype.isPrototypeOf(x); } |
| 45 |
| 46 assertFalse(foo(0)); |
| 47 assertFalse(foo("")); |
| 48 assertFalse(foo(null)); |
| 49 assertFalse(foo(undefined)); |
| 50 assertFalse(foo({})); |
| 51 assertFalse(foo([])); |
| 52 assertTrue(foo(a)); |
| 53 assertTrue(foo(new A)); |
| 54 assertTrue(foo({__proto__: a})); |
| 55 assertTrue(foo({__proto__: A.prototype})); |
| 56 %OptimizeFunctionOnNextCall(foo); |
| 57 assertFalse(foo(0)); |
| 58 assertFalse(foo("")); |
| 59 assertFalse(foo(null)); |
| 60 assertFalse(foo(undefined)); |
| 61 assertFalse(foo({})); |
| 62 assertFalse(foo([])); |
| 63 assertTrue(foo(a)); |
| 64 assertTrue(foo(new A)); |
| 65 assertTrue(foo({__proto__: a})); |
| 66 assertTrue(foo({__proto__: A.prototype})); |
| 67 })(); |
| 68 |
| 69 // Test known primitive values. |
| 70 (function() { |
| 71 function A() {} |
| 72 A.prototype = {}; |
| 73 var a = new A; |
| 74 |
| 75 function foo() { return A.prototype.isPrototypeOf(0); } |
| 76 |
| 77 assertFalse(foo()); |
| 78 assertFalse(foo()); |
| 79 %OptimizeFunctionOnNextCall(foo); |
| 80 assertFalse(foo()); |
| 81 })(); |
| 82 (function() { |
| 83 function A() {} |
| 84 A.prototype = {}; |
| 85 var a = new A; |
| 86 |
| 87 function foo() { return A.prototype.isPrototypeOf(null); } |
| 88 |
| 89 assertFalse(foo()); |
| 90 assertFalse(foo()); |
| 91 %OptimizeFunctionOnNextCall(foo); |
| 92 assertFalse(foo()); |
| 93 })(); |
| 94 (function() { |
| 95 function A() {} |
| 96 A.prototype = {}; |
| 97 var a = new A; |
| 98 |
| 99 function foo() { return A.prototype.isPrototypeOf(undefined); } |
| 100 |
| 101 assertFalse(foo()); |
| 102 assertFalse(foo()); |
| 103 %OptimizeFunctionOnNextCall(foo); |
| 104 assertFalse(foo()); |
| 105 })(); |
| 106 |
| 107 // Test constant-folded prototype chain checks. |
| 108 (function() { |
| 109 function A() {} |
| 110 A.prototype = {}; |
| 111 var a = new A; |
| 112 |
| 113 function foo() { return A.prototype.isPrototypeOf(a); } |
| 114 |
| 115 assertTrue(foo()); |
| 116 assertTrue(foo()); |
| 117 %OptimizeFunctionOnNextCall(foo); |
| 118 assertTrue(foo()); |
| 119 })(); |
| 120 (function() { |
| 121 function A() {} |
| 122 var a = new A; |
| 123 A.prototype = {}; |
| 124 |
| 125 function foo() { return A.prototype.isPrototypeOf(a); } |
| 126 |
| 127 assertFalse(foo()); |
| 128 assertFalse(foo()); |
| 129 %OptimizeFunctionOnNextCall(foo); |
| 130 assertFalse(foo()); |
| 131 })(); |
| 132 |
| 133 // Test Array prototype chain checks. |
| 134 (function() { |
| 135 var a = []; |
| 136 |
| 137 function foo() { return Array.prototype.isPrototypeOf(a); } |
| 138 |
| 139 assertTrue(foo()); |
| 140 assertTrue(foo()); |
| 141 %OptimizeFunctionOnNextCall(foo); |
| 142 assertTrue(foo()); |
| 143 })(); |
| 144 (function() { |
| 145 var a = []; |
| 146 |
| 147 function foo() { return Object.prototype.isPrototypeOf(a); } |
| 148 |
| 149 assertTrue(foo()); |
| 150 assertTrue(foo()); |
| 151 %OptimizeFunctionOnNextCall(foo); |
| 152 assertTrue(foo()); |
| 153 })(); |
OLD | NEW |