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 (function(global, utils) { | 5 (function(global, utils) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
11 // ---------------------------------------------------------------------------- | 11 // ---------------------------------------------------------------------------- |
12 // Imports | 12 // Imports |
13 // | 13 // |
14 var GlobalProxy = global.Proxy; | 14 var GlobalProxy = global.Proxy; |
15 var GlobalFunction = global.Function; | 15 var GlobalFunction = global.Function; |
16 var GlobalObject = global.Object; | 16 var GlobalObject = global.Object; |
17 var MakeTypeError; | 17 var MakeTypeError; |
18 var ToNameArray; | 18 var ToNameArray; |
19 | 19 |
20 utils.Import(function(from) { | 20 utils.Import(function(from) { |
21 MakeTypeError = from.MakeTypeError; | 21 MakeTypeError = from.MakeTypeError; |
22 ToNameArray = from.ToNameArray; | 22 ToNameArray = from.ToNameArray; |
23 }); | 23 }); |
24 | 24 |
25 //---------------------------------------------------------------------------- | 25 //---------------------------------------------------------------------------- |
26 | 26 |
27 function ProxyCreate(target, handler) { | 27 function ProxyCreate(target, handler) { |
28 if (!%_IsConstructCall()) { | 28 if (IS_UNDEFINED(new.target)) { |
29 throw MakeTypeError(kConstructorNotFunction, "Proxy"); | 29 throw MakeTypeError(kConstructorNotFunction, "Proxy"); |
30 } | 30 } |
31 return %CreateJSProxy(target, handler); | 31 return %CreateJSProxy(target, handler); |
32 } | 32 } |
33 | 33 |
34 function ProxyCreateFunction(handler, callTrap, constructTrap) { | 34 function ProxyCreateFunction(handler, callTrap, constructTrap) { |
35 if (!IS_SPEC_OBJECT(handler)) | 35 if (!IS_SPEC_OBJECT(handler)) |
36 throw MakeTypeError(kProxyHandlerNonObject, "createFunction") | 36 throw MakeTypeError(kProxyHandlerNonObject, "createFunction") |
37 if (!IS_CALLABLE(callTrap)) | 37 if (!IS_CALLABLE(callTrap)) |
38 throw MakeTypeError(kProxyTrapFunctionExpected, "call") | 38 throw MakeTypeError(kProxyTrapFunctionExpected, "call") |
(...skipping 20 matching lines...) Expand all Loading... |
59 var proto = this.prototype | 59 var proto = this.prototype |
60 if (!IS_SPEC_OBJECT(proto)) proto = GlobalObject.prototype | 60 if (!IS_SPEC_OBJECT(proto)) proto = GlobalObject.prototype |
61 var obj = { __proto__: proto }; | 61 var obj = { __proto__: proto }; |
62 var result = %Apply(callTrap, obj, arguments, 0, %_ArgumentsLength()); | 62 var result = %Apply(callTrap, obj, arguments, 0, %_ArgumentsLength()); |
63 return IS_SPEC_OBJECT(result) ? result : obj | 63 return IS_SPEC_OBJECT(result) ? result : obj |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 function DelegateCallAndConstruct(callTrap, constructTrap) { | 67 function DelegateCallAndConstruct(callTrap, constructTrap) { |
68 return function() { | 68 return function() { |
69 return %Apply(%_IsConstructCall() ? constructTrap : callTrap, | 69 return %Apply(IS_UNDEFINED(new.target) ? callTrap : constructTrap, |
70 this, arguments, 0, %_ArgumentsLength()) | 70 this, arguments, 0, %_ArgumentsLength()) |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
74 function DerivedGetTrap(receiver, name) { | 74 function DerivedGetTrap(receiver, name) { |
75 var desc = this.getPropertyDescriptor(name) | 75 var desc = this.getPropertyDescriptor(name) |
76 if (IS_UNDEFINED(desc)) { return desc } | 76 if (IS_UNDEFINED(desc)) { return desc } |
77 if ('value' in desc) { | 77 if ('value' in desc) { |
78 return desc.value | 78 return desc.value |
79 } else { | 79 } else { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 }); | 197 }); |
198 | 198 |
199 %InstallToContext([ | 199 %InstallToContext([ |
200 "derived_get_trap", DerivedGetTrap, | 200 "derived_get_trap", DerivedGetTrap, |
201 "derived_has_trap", DerivedHasTrap, | 201 "derived_has_trap", DerivedHasTrap, |
202 "derived_set_trap", DerivedSetTrap, | 202 "derived_set_trap", DerivedSetTrap, |
203 "proxy_enumerate", ProxyEnumerate, | 203 "proxy_enumerate", ProxyEnumerate, |
204 ]); | 204 ]); |
205 | 205 |
206 }) | 206 }) |
OLD | NEW |