OLD | NEW |
1 // Copyright 2011 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 // ---------------------------------------------------------------------------- |
(...skipping 11 matching lines...) Expand all Loading... |
23 | 23 |
24 //---------------------------------------------------------------------------- | 24 //---------------------------------------------------------------------------- |
25 | 25 |
26 function ProxyCreate(handler, proto) { | 26 function ProxyCreate(handler, proto) { |
27 if (!IS_SPEC_OBJECT(handler)) | 27 if (!IS_SPEC_OBJECT(handler)) |
28 throw MakeTypeError(kProxyHandlerNonObject, "create") | 28 throw MakeTypeError(kProxyHandlerNonObject, "create") |
29 if (IS_UNDEFINED(proto)) | 29 if (IS_UNDEFINED(proto)) |
30 proto = null | 30 proto = null |
31 else if (!(IS_SPEC_OBJECT(proto) || IS_NULL(proto))) | 31 else if (!(IS_SPEC_OBJECT(proto) || IS_NULL(proto))) |
32 throw MakeTypeError(kProxyProtoNonObject) | 32 throw MakeTypeError(kProxyProtoNonObject) |
33 return %CreateJSProxy(handler, proto) | 33 return %CreateJSProxy({}, handler, proto) |
34 } | 34 } |
35 | 35 |
36 function ProxyCreateFunction(handler, callTrap, constructTrap) { | 36 function ProxyCreateFunction(handler, callTrap, constructTrap) { |
37 if (!IS_SPEC_OBJECT(handler)) | 37 if (!IS_SPEC_OBJECT(handler)) |
38 throw MakeTypeError(kProxyHandlerNonObject, "createFunction") | 38 throw MakeTypeError(kProxyHandlerNonObject, "createFunction") |
39 if (!IS_CALLABLE(callTrap)) | 39 if (!IS_CALLABLE(callTrap)) |
40 throw MakeTypeError(kProxyTrapFunctionExpected, "call") | 40 throw MakeTypeError(kProxyTrapFunctionExpected, "call") |
41 if (IS_UNDEFINED(constructTrap)) { | 41 if (IS_UNDEFINED(constructTrap)) { |
42 constructTrap = DerivedConstructTrap(callTrap) | 42 constructTrap = DerivedConstructTrap(callTrap) |
43 } else if (IS_CALLABLE(constructTrap)) { | 43 } else if (IS_CALLABLE(constructTrap)) { |
44 // Make sure the trap receives 'undefined' as this. | 44 // Make sure the trap receives 'undefined' as this. |
45 var construct = constructTrap | 45 var construct = constructTrap |
46 constructTrap = function() { | 46 constructTrap = function() { |
47 return %Apply(construct, UNDEFINED, arguments, 0, %_ArgumentsLength()); | 47 return %Apply(construct, UNDEFINED, arguments, 0, %_ArgumentsLength()); |
48 } | 48 } |
49 } else { | 49 } else { |
50 throw MakeTypeError(kProxyTrapFunctionExpected, "construct") | 50 throw MakeTypeError(kProxyTrapFunctionExpected, "construct") |
51 } | 51 } |
52 return %CreateJSFunctionProxy( | 52 return %CreateJSFunctionProxy( |
53 handler, callTrap, constructTrap, GlobalFunction.prototype) | 53 {}, handler, callTrap, constructTrap, GlobalFunction.prototype) |
54 } | 54 } |
55 | 55 |
56 // ------------------------------------------------------------------- | 56 // ------------------------------------------------------------------- |
57 // Proxy Builtins | 57 // Proxy Builtins |
58 | 58 |
59 function DerivedConstructTrap(callTrap) { | 59 function DerivedConstructTrap(callTrap) { |
60 return function() { | 60 return function() { |
61 var proto = this.prototype | 61 var proto = this.prototype |
62 if (!IS_SPEC_OBJECT(proto)) proto = GlobalObject.prototype | 62 if (!IS_SPEC_OBJECT(proto)) proto = GlobalObject.prototype |
63 var obj = { __proto__: proto }; | 63 var obj = { __proto__: proto }; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 }); | 202 }); |
203 | 203 |
204 %InstallToContext([ | 204 %InstallToContext([ |
205 "derived_get_trap", DerivedGetTrap, | 205 "derived_get_trap", DerivedGetTrap, |
206 "derived_has_trap", DerivedHasTrap, | 206 "derived_has_trap", DerivedHasTrap, |
207 "derived_set_trap", DerivedSetTrap, | 207 "derived_set_trap", DerivedSetTrap, |
208 "proxy_enumerate", ProxyEnumerate, | 208 "proxy_enumerate", ProxyEnumerate, |
209 ]); | 209 ]); |
210 | 210 |
211 }) | 211 }) |
OLD | NEW |