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: --allow-natives-syntax --harmony-proxies --harmony-reflect | 5 // Flags: --allow-natives-syntax --harmony-proxies --harmony-reflect |
6 | 6 |
7 function CreateConstructableProxy(handler) { | 7 function CreateConstructableProxy(handler) { |
8 return Proxy.createFunction(handler, function() {}, function() {}); | 8 return Proxy.createFunction(handler, function() {}, function() {}); |
9 } | 9 } |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 var log = []; | 29 var log = []; |
30 | 30 |
31 var proxy = CreateConstructableProxy({ | 31 var proxy = CreateConstructableProxy({ |
32 get(k) { | 32 get(k) { |
33 log.push("get trap"); | 33 log.push("get trap"); |
34 return 10; | 34 return 10; |
35 }}); | 35 }}); |
36 | 36 |
37 var o = Reflect.construct(Number, [100], proxy); | 37 var o = Reflect.construct(Number, [100], proxy); |
38 assertEquals(["get trap"], log); | 38 assertEquals(["get trap"], log); |
39 assertTrue(Object.getPrototypeOf(o) === Object.prototype); | 39 assertTrue(Object.getPrototypeOf(o) === Number.prototype); |
40 assertEquals(100, Number.prototype.valueOf.call(o)); | 40 assertEquals(100, Number.prototype.valueOf.call(o)); |
41 })(); | 41 })(); |
42 | 42 |
43 (function() { | 43 (function() { |
44 var prototype = { x: 1 }; | 44 var prototype = { x: 1 }; |
45 var log = []; | 45 var log = []; |
46 | 46 |
47 var proxy = CreateConstructableProxy({ | 47 var proxy = CreateConstructableProxy({ |
48 get(k) { | 48 get(k) { |
49 log.push("get trap"); | 49 log.push("get trap"); |
(...skipping 14 matching lines...) Expand all Loading... |
64 get(k) { | 64 get(k) { |
65 log.push("get trap"); | 65 log.push("get trap"); |
66 return prototype; | 66 return prototype; |
67 }}); | 67 }}); |
68 | 68 |
69 var o = Reflect.construct(Array, [1, 2, 3], proxy); | 69 var o = Reflect.construct(Array, [1, 2, 3], proxy); |
70 assertEquals(["get trap"], log); | 70 assertEquals(["get trap"], log); |
71 assertTrue(Object.getPrototypeOf(o) === prototype); | 71 assertTrue(Object.getPrototypeOf(o) === prototype); |
72 assertEquals([1, 2, 3], o); | 72 assertEquals([1, 2, 3], o); |
73 })(); | 73 })(); |
OLD | NEW |