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 | 18 |
19 utils.Import(function(from) { | 19 utils.Import(function(from) { |
20 MakeTypeError = from.MakeTypeError; | 20 MakeTypeError = from.MakeTypeError; |
21 }); | 21 }); |
22 | 22 |
23 //---------------------------------------------------------------------------- | 23 //---------------------------------------------------------------------------- |
24 | 24 |
25 function ProxyCreateFunction(handler, callTrap, constructTrap) { | |
26 if (!IS_SPEC_OBJECT(handler)) | |
27 throw MakeTypeError(kProxyHandlerNonObject, "createFunction") | |
28 if (!IS_CALLABLE(callTrap)) | |
29 throw MakeTypeError(kProxyTrapFunctionExpected, "call") | |
30 if (IS_UNDEFINED(constructTrap)) { | |
31 constructTrap = DerivedConstructTrap(callTrap) | |
32 } else if (IS_CALLABLE(constructTrap)) { | |
33 // Make sure the trap receives 'undefined' as this. | |
34 var construct = constructTrap | |
35 constructTrap = function() { | |
36 return %Apply(construct, UNDEFINED, arguments, 0, %_ArgumentsLength()); | |
37 } | |
38 } else { | |
39 throw MakeTypeError(kProxyTrapFunctionExpected, "construct") | |
40 } | |
41 return %CreateJSFunctionProxy( | |
42 {}, handler, callTrap, constructTrap, GlobalFunction.prototype) | |
43 } | |
44 | |
45 function ProxyCreateRevocable(target, handler) { | 25 function ProxyCreateRevocable(target, handler) { |
46 var p = new GlobalProxy(target, handler); | 26 var p = new GlobalProxy(target, handler); |
47 return {proxy: p, revoke: () => %RevokeProxy(p)}; | 27 return {proxy: p, revoke: () => %RevokeProxy(p)}; |
48 } | 28 } |
49 | 29 |
50 // ------------------------------------------------------------------- | 30 // ------------------------------------------------------------------- |
51 // Proxy Builtins | 31 // Proxy Builtins |
52 | 32 |
53 function DerivedConstructTrap(callTrap) { | 33 function DerivedConstructTrap(callTrap) { |
54 return function() { | 34 return function() { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 } | 122 } |
143 result.push(key); | 123 result.push(key); |
144 } | 124 } |
145 return result; | 125 return result; |
146 } | 126 } |
147 | 127 |
148 //------------------------------------------------------------------- | 128 //------------------------------------------------------------------- |
149 | 129 |
150 //Set up non-enumerable properties of the Proxy object. | 130 //Set up non-enumerable properties of the Proxy object. |
151 utils.InstallFunctions(GlobalProxy, DONT_ENUM, [ | 131 utils.InstallFunctions(GlobalProxy, DONT_ENUM, [ |
152 "revocable", ProxyCreateRevocable, | 132 "revocable", ProxyCreateRevocable |
153 "createFunction", ProxyCreateFunction | |
154 ]); | 133 ]); |
155 | 134 |
156 // ------------------------------------------------------------------- | 135 // ------------------------------------------------------------------- |
157 // Exports | 136 // Exports |
158 | 137 |
159 utils.Export(function(to) { | 138 utils.Export(function(to) { |
160 to.ProxyDelegateCallAndConstruct = DelegateCallAndConstruct; | 139 to.ProxyDelegateCallAndConstruct = DelegateCallAndConstruct; |
161 to.ProxyDerivedHasOwnTrap = DerivedHasOwnTrap; | 140 to.ProxyDerivedHasOwnTrap = DerivedHasOwnTrap; |
162 }); | 141 }); |
163 | 142 |
164 %InstallToContext([ | 143 %InstallToContext([ |
165 "proxy_enumerate", ProxyEnumerate, | 144 "proxy_enumerate", ProxyEnumerate, |
166 ]); | 145 ]); |
167 | 146 |
168 }) | 147 }) |
OLD | NEW |