OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 var $proxyDelegateCallAndConstruct; | 5 var $proxyDelegateCallAndConstruct; |
6 var $proxyDerivedGetTrap; | 6 var $proxyDerivedGetTrap; |
7 var $proxyDerivedHasTrap; | 7 var $proxyDerivedHasTrap; |
8 var $proxyDerivedHasOwnTrap; | 8 var $proxyDerivedHasOwnTrap; |
9 var $proxyDerivedKeysTrap; | 9 var $proxyDerivedKeysTrap; |
10 var $proxyDerivedSetTrap; | 10 var $proxyDerivedSetTrap; |
11 var $proxyEnumerate; | 11 var $proxyEnumerate; |
12 | 12 |
13 (function() { | 13 (function() { |
14 | 14 |
15 "use strict"; | 15 "use strict"; |
16 | 16 |
17 %CheckIsBootstrapping(); | 17 %CheckIsBootstrapping(); |
18 | 18 |
| 19 var GlobalFunction = global.Function; |
19 var GlobalObject = global.Object; | 20 var GlobalObject = global.Object; |
20 | 21 |
21 // ------------------------------------------------------------------- | 22 // ------------------------------------------------------------------- |
22 | 23 |
23 function ProxyCreate(handler, proto) { | 24 function ProxyCreate(handler, proto) { |
24 if (!IS_SPEC_OBJECT(handler)) | 25 if (!IS_SPEC_OBJECT(handler)) |
25 throw MakeTypeError("handler_non_object", ["create"]) | 26 throw MakeTypeError("handler_non_object", ["create"]) |
26 if (IS_UNDEFINED(proto)) | 27 if (IS_UNDEFINED(proto)) |
27 proto = null | 28 proto = null |
28 else if (!(IS_SPEC_OBJECT(proto) || IS_NULL(proto))) | 29 else if (!(IS_SPEC_OBJECT(proto) || IS_NULL(proto))) |
(...skipping 12 matching lines...) Expand all Loading... |
41 // Make sure the trap receives 'undefined' as this. | 42 // Make sure the trap receives 'undefined' as this. |
42 var construct = constructTrap | 43 var construct = constructTrap |
43 constructTrap = function() { | 44 constructTrap = function() { |
44 return %Apply(construct, UNDEFINED, arguments, 0, %_ArgumentsLength()); | 45 return %Apply(construct, UNDEFINED, arguments, 0, %_ArgumentsLength()); |
45 } | 46 } |
46 } else { | 47 } else { |
47 throw MakeTypeError("trap_function_expected", | 48 throw MakeTypeError("trap_function_expected", |
48 ["createFunction", "construct"]) | 49 ["createFunction", "construct"]) |
49 } | 50 } |
50 return %CreateJSFunctionProxy( | 51 return %CreateJSFunctionProxy( |
51 handler, callTrap, constructTrap, $Function.prototype) | 52 handler, callTrap, constructTrap, GlobalFunction.prototype) |
52 } | 53 } |
53 | 54 |
54 // ------------------------------------------------------------------- | 55 // ------------------------------------------------------------------- |
55 // Proxy Builtins | 56 // Proxy Builtins |
56 | 57 |
57 function DerivedConstructTrap(callTrap) { | 58 function DerivedConstructTrap(callTrap) { |
58 return function() { | 59 return function() { |
59 var proto = this.prototype | 60 var proto = this.prototype |
60 if (!IS_SPEC_OBJECT(proto)) proto = $Object.prototype | 61 if (!IS_SPEC_OBJECT(proto)) proto = GlobalObject.prototype |
61 var obj = { __proto__: proto }; | 62 var obj = { __proto__: proto }; |
62 var result = %Apply(callTrap, obj, arguments, 0, %_ArgumentsLength()); | 63 var result = %Apply(callTrap, obj, arguments, 0, %_ArgumentsLength()); |
63 return IS_SPEC_OBJECT(result) ? result : obj | 64 return IS_SPEC_OBJECT(result) ? result : obj |
64 } | 65 } |
65 } | 66 } |
66 | 67 |
67 function DelegateCallAndConstruct(callTrap, constructTrap) { | 68 function DelegateCallAndConstruct(callTrap, constructTrap) { |
68 return function() { | 69 return function() { |
69 return %Apply(%_IsConstructCall() ? constructTrap : callTrap, | 70 return %Apply(%_IsConstructCall() ? constructTrap : callTrap, |
70 this, arguments, 0, %_ArgumentsLength()) | 71 this, arguments, 0, %_ArgumentsLength()) |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 | 193 |
193 $proxyDelegateCallAndConstruct = DelegateCallAndConstruct; | 194 $proxyDelegateCallAndConstruct = DelegateCallAndConstruct; |
194 $proxyDerivedGetTrap = DerivedGetTrap; | 195 $proxyDerivedGetTrap = DerivedGetTrap; |
195 $proxyDerivedHasTrap = DerivedHasTrap; | 196 $proxyDerivedHasTrap = DerivedHasTrap; |
196 $proxyDerivedHasOwnTrap = DerivedHasOwnTrap; | 197 $proxyDerivedHasOwnTrap = DerivedHasOwnTrap; |
197 $proxyDerivedKeysTrap = DerivedKeysTrap; | 198 $proxyDerivedKeysTrap = DerivedKeysTrap; |
198 $proxyDerivedSetTrap = DerivedSetTrap; | 199 $proxyDerivedSetTrap = DerivedSetTrap; |
199 $proxyEnumerate = ProxyEnumerate; | 200 $proxyEnumerate = ProxyEnumerate; |
200 | 201 |
201 })(); | 202 })(); |
OLD | NEW |