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 |
(...skipping 10 matching lines...) Expand all Loading... |
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 (!%_IsConstructCall()) { |
29 throw MakeTypeError(kConstructorNotFunction, "Proxy"); | 29 throw MakeTypeError(kConstructorNotFunction, "Proxy"); |
30 } | 30 } |
31 // TODO(cbruni): Get the construct call right, this is just a prelimiary | 31 return %CreateJSProxy(target, handler); |
32 // version to get started with tests. | |
33 return %CreateJSProxy(this, target, handler); | |
34 } | 32 } |
35 | 33 |
36 function ProxyCreateFunction(handler, callTrap, constructTrap) { | 34 function ProxyCreateFunction(handler, callTrap, constructTrap) { |
37 if (!IS_SPEC_OBJECT(handler)) | 35 if (!IS_SPEC_OBJECT(handler)) |
38 throw MakeTypeError(kProxyHandlerNonObject, "createFunction") | 36 throw MakeTypeError(kProxyHandlerNonObject, "createFunction") |
39 if (!IS_CALLABLE(callTrap)) | 37 if (!IS_CALLABLE(callTrap)) |
40 throw MakeTypeError(kProxyTrapFunctionExpected, "call") | 38 throw MakeTypeError(kProxyTrapFunctionExpected, "call") |
41 if (IS_UNDEFINED(constructTrap)) { | 39 if (IS_UNDEFINED(constructTrap)) { |
42 constructTrap = DerivedConstructTrap(callTrap) | 40 constructTrap = DerivedConstructTrap(callTrap) |
43 } else if (IS_CALLABLE(constructTrap)) { | 41 } else if (IS_CALLABLE(constructTrap)) { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 var handler = %GetHandler(proxy) | 174 var handler = %GetHandler(proxy) |
177 if (IS_UNDEFINED(handler.enumerate)) { | 175 if (IS_UNDEFINED(handler.enumerate)) { |
178 return %Apply(DerivedEnumerateTrap, handler, [], 0, 0) | 176 return %Apply(DerivedEnumerateTrap, handler, [], 0, 0) |
179 } else { | 177 } else { |
180 return ToNameArray(handler.enumerate(), "enumerate", false) | 178 return ToNameArray(handler.enumerate(), "enumerate", false) |
181 } | 179 } |
182 } | 180 } |
183 | 181 |
184 //------------------------------------------------------------------- | 182 //------------------------------------------------------------------- |
185 %SetCode(GlobalProxy, ProxyCreate); | 183 %SetCode(GlobalProxy, ProxyCreate); |
186 %FunctionSetPrototype(GlobalProxy, new GlobalObject()); | |
187 | 184 |
188 //Set up non-enumerable properties of the Proxy object. | 185 //Set up non-enumerable properties of the Proxy object. |
189 utils.InstallFunctions(GlobalProxy, DONT_ENUM, [ | 186 utils.InstallFunctions(GlobalProxy, DONT_ENUM, [ |
190 "createFunction", ProxyCreateFunction | 187 "createFunction", ProxyCreateFunction |
191 ]); | 188 ]); |
192 | 189 |
193 %AddNamedProperty(GlobalProxy.prototype, "constructor", GlobalProxy, DONT_ENUM); | |
194 // ------------------------------------------------------------------- | 190 // ------------------------------------------------------------------- |
195 // Exports | 191 // Exports |
196 | 192 |
197 utils.Export(function(to) { | 193 utils.Export(function(to) { |
198 to.ProxyDelegateCallAndConstruct = DelegateCallAndConstruct; | 194 to.ProxyDelegateCallAndConstruct = DelegateCallAndConstruct; |
199 to.ProxyDerivedHasOwnTrap = DerivedHasOwnTrap; | 195 to.ProxyDerivedHasOwnTrap = DerivedHasOwnTrap; |
200 to.ProxyDerivedKeysTrap = DerivedKeysTrap; | 196 to.ProxyDerivedKeysTrap = DerivedKeysTrap; |
201 }); | 197 }); |
202 | 198 |
203 %InstallToContext([ | 199 %InstallToContext([ |
204 "derived_get_trap", DerivedGetTrap, | 200 "derived_get_trap", DerivedGetTrap, |
205 "derived_has_trap", DerivedHasTrap, | 201 "derived_has_trap", DerivedHasTrap, |
206 "derived_set_trap", DerivedSetTrap, | 202 "derived_set_trap", DerivedSetTrap, |
207 "proxy_enumerate", ProxyEnumerate, | 203 "proxy_enumerate", ProxyEnumerate, |
208 ]); | 204 ]); |
209 | 205 |
210 }) | 206 }) |
OLD | NEW |