OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --harmony-proxies | 5 // Flags: --harmony-proxies |
6 | 6 |
7 var target = { target: 1 }; | 7 var target = { target: 1 }; |
8 target.__proto__ = {}; | 8 target.__proto__ = {}; |
9 var handler = { handler: 1 }; | 9 var handler = { handler: 1 }; |
10 var proxy = new Proxy(target, handler); | 10 var proxy = new Proxy(target, handler); |
(...skipping 18 matching lines...) Expand all Loading... |
29 var proxy2 = new Proxy(proxy, {'handler':1}); | 29 var proxy2 = new Proxy(proxy, {'handler':1}); |
30 assertSame(Object.getPrototypeOf(proxy2), target_prototype); | 30 assertSame(Object.getPrototypeOf(proxy2), target_prototype); |
31 | 31 |
32 // Test with Proxy handler: | 32 // Test with Proxy handler: |
33 var proxy3_prototype = {'proto3':true}; | 33 var proxy3_prototype = {'proto3':true}; |
34 var handler_proxy = new Proxy({ | 34 var handler_proxy = new Proxy({ |
35 getPrototypeOf: function() { return proxy3_prototype } | 35 getPrototypeOf: function() { return proxy3_prototype } |
36 }, {}); | 36 }, {}); |
37 var proxy3 = new Proxy(target, handler_proxy); | 37 var proxy3 = new Proxy(target, handler_proxy); |
38 assertSame(Object.getPrototypeOf(proxy3), proxy3_prototype); | 38 assertSame(Object.getPrototypeOf(proxy3), proxy3_prototype); |
| 39 |
| 40 |
| 41 // Some tests with Object.prototype.isPrototypeOf |
| 42 |
| 43 (function () { |
| 44 var object = {}; |
| 45 var handler = {}; |
| 46 var proto = new Proxy({}, handler); |
| 47 object.__proto__ = proto; |
| 48 |
| 49 assertTrue(proto.isPrototypeOf(object)); |
| 50 assertTrue(Object.prototype.isPrototypeOf.call(proto, object)); |
| 51 |
| 52 handler.getPrototypeOf = function () { return Object.prototype }; |
| 53 assertTrue(proto.isPrototypeOf(object)); |
| 54 assertTrue(Object.prototype.isPrototypeOf.call(proto, object)); |
| 55 assertTrue(Object.prototype.isPrototypeOf(object)); |
| 56 assertFalse(Object.prototype.isPrototypeOf.call(Array.prototype, object)); |
| 57 assertFalse(Array.prototype.isPrototypeOf(object)); |
| 58 |
| 59 handler.getPrototypeOf = function () { return object }; |
| 60 assertTrue(Object.prototype.isPrototypeOf.call(proto, object)); |
| 61 assertTrue(proto.isPrototypeOf(object)); |
| 62 assertTrue(Object.prototype.isPrototypeOf.call(object, object)); |
| 63 assertTrue(object.isPrototypeOf(object)); |
| 64 |
| 65 handler.getPrototypeOf = function () { throw "foo" }; |
| 66 assertTrue(proto.isPrototypeOf(object)); |
| 67 assertTrue(Object.prototype.isPrototypeOf.call(proto, object)); |
| 68 assertThrows(()=> Object.prototype.isPrototypeOf(object)); |
| 69 assertThrows(()=> Object.prototype.isPrototypeOf.call(Array.prototype, object)
); |
| 70 assertThrows(()=> Array.prototype.isPrototypeOf(object)); |
| 71 })(); |
| 72 |
| 73 (function () { |
| 74 var handler = {}; |
| 75 var object = new Proxy({}, handler); |
| 76 var proto = {}; |
| 77 |
| 78 assertFalse(Object.prototype.isPrototypeOf.call(object, object)); |
| 79 assertFalse(Object.prototype.isPrototypeOf.call(proto, object)); |
| 80 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, object)); |
| 81 |
| 82 handler.getPrototypeOf = function () { return proto }; |
| 83 assertTrue(Object.prototype.isPrototypeOf.call(proto, object)); |
| 84 assertFalse(Object.prototype.isPrototypeOf.call({}, object)); |
| 85 assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, object)); |
| 86 |
| 87 handler.getPrototypeOf = function () { return object }; |
| 88 assertTrue(Object.prototype.isPrototypeOf.call(object, object)); |
| 89 |
| 90 handler.getPrototypeOf = function () { throw "foo" }; |
| 91 assertThrows(()=> Object.prototype.isPrototypeOf.call(object, object)); |
| 92 assertThrows(()=> Object.prototype.isPrototypeOf(object)); |
| 93 })(); |
OLD | NEW |