OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 function A() {} |
| 8 var a = new A(); |
| 9 |
| 10 var B = { |
| 11 [Symbol.hasInstance](o) { |
| 12 return false; |
| 13 } |
| 14 }; |
| 15 %ToFastProperties(B.__proto__); |
| 16 |
| 17 var C = Object.create({ |
| 18 [Symbol.hasInstance](o) { |
| 19 return true; |
| 20 } |
| 21 }); |
| 22 %ToFastProperties(C.__proto__); |
| 23 |
| 24 var D = Object.create({ |
| 25 [Symbol.hasInstance](o) { |
| 26 return o === a; |
| 27 } |
| 28 }); |
| 29 %ToFastProperties(D.__proto__); |
| 30 |
| 31 var E = Object.create({ |
| 32 [Symbol.hasInstance](o) { |
| 33 if (o === a) throw o; |
| 34 return true; |
| 35 } |
| 36 }); |
| 37 %ToFastProperties(E.__proto__); |
| 38 |
| 39 function F() {} |
| 40 F.__proto__ = null; |
| 41 |
| 42 (function() { |
| 43 function foo(o) { return o instanceof A; } |
| 44 |
| 45 assertTrue(foo(a)); |
| 46 assertTrue(foo(a)); |
| 47 assertTrue(foo(new A())); |
| 48 %OptimizeFunctionOnNextCall(foo); |
| 49 assertTrue(foo(a)); |
| 50 assertTrue(foo(new A())); |
| 51 })(); |
| 52 |
| 53 (function() { |
| 54 function foo(o) { |
| 55 try { |
| 56 return o instanceof A; |
| 57 } catch (e) { |
| 58 return e; |
| 59 } |
| 60 } |
| 61 |
| 62 assertTrue(foo(a)); |
| 63 assertTrue(foo(a)); |
| 64 assertTrue(foo(new A())); |
| 65 assertEquals(1, foo(new Proxy({}, {getPrototypeOf() { throw 1; }}))); |
| 66 %OptimizeFunctionOnNextCall(foo); |
| 67 assertTrue(foo(a)); |
| 68 assertTrue(foo(new A())); |
| 69 assertEquals(1, foo(new Proxy({}, {getPrototypeOf() { throw 1; }}))); |
| 70 })(); |
| 71 |
| 72 (function() { |
| 73 function foo(o) { return o instanceof B; } |
| 74 |
| 75 assertFalse(foo(a)); |
| 76 assertFalse(foo(a)); |
| 77 assertFalse(foo(new A())); |
| 78 %OptimizeFunctionOnNextCall(foo); |
| 79 assertFalse(foo(a)); |
| 80 assertFalse(foo(new A())); |
| 81 })(); |
| 82 |
| 83 (function() { |
| 84 function foo(o) { return o instanceof C; } |
| 85 |
| 86 assertTrue(foo(a)); |
| 87 assertTrue(foo(a)); |
| 88 assertTrue(foo(new A())); |
| 89 %OptimizeFunctionOnNextCall(foo); |
| 90 assertTrue(foo(a)); |
| 91 assertTrue(foo(new A())); |
| 92 })(); |
| 93 |
| 94 (function() { |
| 95 function foo(o) { return o instanceof D; } |
| 96 |
| 97 assertTrue(foo(a)); |
| 98 assertTrue(foo(a)); |
| 99 assertFalse(foo(new A())); |
| 100 %OptimizeFunctionOnNextCall(foo); |
| 101 assertTrue(foo(a)); |
| 102 assertFalse(foo(new A())); |
| 103 })(); |
| 104 |
| 105 (function() { |
| 106 function foo(o) { |
| 107 try { |
| 108 return o instanceof E; |
| 109 } catch (e) { |
| 110 return false; |
| 111 } |
| 112 } |
| 113 |
| 114 assertFalse(foo(a)); |
| 115 assertTrue(foo(new A())); |
| 116 %OptimizeFunctionOnNextCall(foo); |
| 117 assertFalse(foo(a)); |
| 118 assertTrue(foo(new A())); |
| 119 })(); |
| 120 |
| 121 (function() { |
| 122 function foo(o) { |
| 123 return o instanceof F; |
| 124 } |
| 125 |
| 126 assertFalse(foo(a)); |
| 127 assertFalse(foo(new A())); |
| 128 assertTrue(foo(new F())); |
| 129 %OptimizeFunctionOnNextCall(foo); |
| 130 assertFalse(foo(a)); |
| 131 assertFalse(foo(new A())); |
| 132 assertTrue(foo(new F())); |
| 133 })(); |
OLD | NEW |