| 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 (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 var GlobalProxy = global.Proxy; |
| 14 var GlobalFunction = global.Function; | 14 var GlobalFunction = global.Function; |
| 15 var GlobalObject = global.Object; | 15 var GlobalObject = global.Object; |
| 16 var MakeTypeError; | 16 var MakeTypeError; |
| 17 var ToNameArray; | 17 var ToNameArray; |
| 18 | 18 |
| 19 utils.Import(function(from) { | 19 utils.Import(function(from) { |
| 20 MakeTypeError = from.MakeTypeError; | 20 MakeTypeError = from.MakeTypeError; |
| 21 ToNameArray = from.ToNameArray; | 21 ToNameArray = from.ToNameArray; |
| 22 }); | 22 }); |
| 23 | 23 |
| 24 //---------------------------------------------------------------------------- | 24 //---------------------------------------------------------------------------- |
| 25 | 25 |
| 26 function ProxyCreate(handler, proto) { | 26 function ProxyCreate(handler, proto) { |
| 27 if (!IS_SPEC_OBJECT(handler)) | 27 if (!%_IsConstructCall()) { |
| 28 throw MakeTypeError(kConstructorNotFunction, "Proxy"); |
| 29 } else if (!IS_SPEC_OBJECT(handler)) { |
| 28 throw MakeTypeError(kProxyHandlerNonObject, "create") | 30 throw MakeTypeError(kProxyHandlerNonObject, "create") |
| 29 if (IS_UNDEFINED(proto)) | 31 } |
| 32 if (IS_UNDEFINED(proto)) { |
| 30 proto = null | 33 proto = null |
| 31 else if (!(IS_SPEC_OBJECT(proto) || IS_NULL(proto))) | 34 } else if (!(IS_SPEC_OBJECT(proto) || IS_NULL(proto))) { |
| 32 throw MakeTypeError(kProxyProtoNonObject) | 35 throw MakeTypeError(kProxyProtoNonObject) |
| 36 } |
| 33 return %CreateJSProxy(handler, proto) | 37 return %CreateJSProxy(handler, proto) |
| 34 } | 38 } |
| 35 | 39 |
| 36 function ProxyCreateFunction(handler, callTrap, constructTrap) { | 40 function ProxyCreateFunction(handler, callTrap, constructTrap) { |
| 37 if (!IS_SPEC_OBJECT(handler)) | 41 if (!IS_SPEC_OBJECT(handler)) |
| 38 throw MakeTypeError(kProxyHandlerNonObject, "createFunction") | 42 throw MakeTypeError(kProxyHandlerNonObject, "createFunction") |
| 39 if (!IS_CALLABLE(callTrap)) | 43 if (!IS_CALLABLE(callTrap)) |
| 40 throw MakeTypeError(kProxyTrapFunctionExpected, "call") | 44 throw MakeTypeError(kProxyTrapFunctionExpected, "call") |
| 41 if (IS_UNDEFINED(constructTrap)) { | 45 if (IS_UNDEFINED(constructTrap)) { |
| 42 constructTrap = DerivedConstructTrap(callTrap) | 46 constructTrap = DerivedConstructTrap(callTrap) |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 function ProxyEnumerate(proxy) { | 179 function ProxyEnumerate(proxy) { |
| 176 var handler = %GetHandler(proxy) | 180 var handler = %GetHandler(proxy) |
| 177 if (IS_UNDEFINED(handler.enumerate)) { | 181 if (IS_UNDEFINED(handler.enumerate)) { |
| 178 return %Apply(DerivedEnumerateTrap, handler, [], 0, 0) | 182 return %Apply(DerivedEnumerateTrap, handler, [], 0, 0) |
| 179 } else { | 183 } else { |
| 180 return ToNameArray(handler.enumerate(), "enumerate", false) | 184 return ToNameArray(handler.enumerate(), "enumerate", false) |
| 181 } | 185 } |
| 182 } | 186 } |
| 183 | 187 |
| 184 //------------------------------------------------------------------- | 188 //------------------------------------------------------------------- |
| 189 %SetCode(GlobalProxy, ProxyCreate); |
| 190 %FunctionSetPrototype(GlobalProxy, new GlobalObject()); |
| 185 | 191 |
| 186 var Proxy = new GlobalObject(); | 192 // //Set up non-enumerable properties of the Proxy object. |
| 187 %AddNamedProperty(global, "Proxy", Proxy, DONT_ENUM); | 193 utils.InstallFunctions(GlobalProxy, DONT_ENUM, [ |
| 188 | |
| 189 //Set up non-enumerable properties of the Proxy object. | |
| 190 utils.InstallFunctions(Proxy, DONT_ENUM, [ | |
| 191 "create", ProxyCreate, | 194 "create", ProxyCreate, |
| 192 "createFunction", ProxyCreateFunction | 195 "createFunction", ProxyCreateFunction |
| 193 ]) | 196 ]); |
| 194 | 197 |
| 198 %AddNamedProperty(GlobalProxy.prototype, "constructor", GlobalProxy, DONT_ENUM); |
| 195 // ------------------------------------------------------------------- | 199 // ------------------------------------------------------------------- |
| 196 // Exports | 200 // Exports |
| 197 | 201 |
| 198 utils.Export(function(to) { | 202 utils.Export(function(to) { |
| 199 to.ProxyDelegateCallAndConstruct = DelegateCallAndConstruct; | 203 to.ProxyDelegateCallAndConstruct = DelegateCallAndConstruct; |
| 200 to.ProxyDerivedHasOwnTrap = DerivedHasOwnTrap; | 204 to.ProxyDerivedHasOwnTrap = DerivedHasOwnTrap; |
| 201 to.ProxyDerivedKeysTrap = DerivedKeysTrap; | 205 to.ProxyDerivedKeysTrap = DerivedKeysTrap; |
| 202 }); | 206 }); |
| 203 | 207 |
| 204 %InstallToContext([ | 208 %InstallToContext([ |
| 205 "derived_get_trap", DerivedGetTrap, | 209 "derived_get_trap", DerivedGetTrap, |
| 206 "derived_has_trap", DerivedHasTrap, | 210 "derived_has_trap", DerivedHasTrap, |
| 207 "derived_set_trap", DerivedSetTrap, | 211 "derived_set_trap", DerivedSetTrap, |
| 208 "proxy_enumerate", ProxyEnumerate, | 212 "proxy_enumerate", ProxyEnumerate, |
| 209 ]); | 213 ]); |
| 210 | 214 |
| 211 }) | 215 }) |
| OLD | NEW |