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); |
11 | 11 |
12 assertSame(Object.getPrototypeOf(proxy), target.__proto__ ); | 12 assertSame(Object.getPrototypeOf(proxy), target.__proto__ ); |
13 | 13 |
14 target.__proto__ = []; | 14 target.__proto__ = []; |
15 assertSame(Object.getPrototypeOf(proxy), target.__proto__); | 15 assertSame(Object.getPrototypeOf(proxy), target.__proto__); |
16 | 16 |
17 handler.getPrototypeOf = function() { | 17 handler.getPrototypeOf = function() { |
18 return 1; | 18 return 1; |
19 } | 19 } |
20 assertThrows(function() { Object.getPrototypeOf(proxy) }, TypeError); | 20 assertThrows(function() { Object.getPrototypeOf(proxy) }, TypeError); |
21 | 21 |
22 var target_prototype = {a:1, b:2}; | 22 var target_prototype = {a:1, b:2}; |
23 handler.getPrototypeOf = function() { | 23 handler.getPrototypeOf = function() { |
24 return target_prototype ; | 24 return target_prototype ; |
25 } | 25 } |
26 assertSame(Object.getPrototypeOf(proxy), target_prototype); | 26 assertSame(Object.getPrototypeOf(proxy), target_prototype); |
27 | 27 |
28 // Test with proxy target: | 28 // Test with proxy target: |
29 var proxy2 = new Proxy(proxy, {}); | 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 // TODO(neis,cbruni): Uncomment once the get trap works again. | 33 var proxy3_prototype = {'proto3':true}; |
34 // var proxy3_prototype = {}; | 34 var handler_proxy = new Proxy({ |
35 // var handler_proxy = new Proxy({ | 35 getPrototypeOf: function() { return proxy3_prototype } |
36 // getPrototypeOf: function() { return proxy3_prototype } | 36 }, {}); |
37 // }, {}); | 37 var proxy3 = new Proxy(target, handler_proxy); |
38 // var proxy3 = new Proxy(target, handler_proxy); | 38 assertSame(Object.getPrototypeOf(proxy3), proxy3_prototype); |
39 // assertSame(Object.getPrototypeOf(proxy3), target_prototype); | |
OLD | NEW |