OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 13 matching lines...) Expand all Loading... | |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 "use strict"; | 28 "use strict"; |
29 | 29 |
30 global.Proxy = new $Object(); | 30 global.Proxy = new $Object(); |
31 | 31 |
32 var $Proxy = global.Proxy | 32 var $Proxy = global.Proxy |
33 | 33 |
34 $Proxy.create = function(handler, proto) { | 34 function ProxyCreate(handler, proto) { |
35 if (!IS_SPEC_OBJECT(handler)) | 35 if (!IS_SPEC_OBJECT(handler)) |
36 throw MakeTypeError("handler_non_object", ["create"]) | 36 throw MakeTypeError("handler_non_object", ["create"]) |
37 if (IS_UNDEFINED(proto)) | 37 if (IS_UNDEFINED(proto)) |
38 proto = null | 38 proto = null |
39 else if (!(IS_SPEC_OBJECT(proto) || proto === null)) | 39 else if (!(IS_SPEC_OBJECT(proto) || proto === null)) |
40 throw MakeTypeError("proto_non_object", ["create"]) | 40 throw MakeTypeError("proto_non_object", ["create"]) |
41 return %CreateJSProxy(handler, proto) | 41 return %CreateJSProxy(handler, proto) |
42 } | 42 } |
43 | 43 |
44 $Proxy.createFunction = function(handler, callTrap, constructTrap) { | 44 function ProxyCreateFunction(handler, callTrap, constructTrap) { |
45 if (!IS_SPEC_OBJECT(handler)) | 45 if (!IS_SPEC_OBJECT(handler)) |
46 throw MakeTypeError("handler_non_object", ["create"]) | 46 throw MakeTypeError("handler_non_object", ["create"]) |
47 if (!IS_SPEC_FUNCTION(callTrap)) | 47 if (!IS_SPEC_FUNCTION(callTrap)) |
48 throw MakeTypeError("trap_function_expected", ["createFunction", "call"]) | 48 throw MakeTypeError("trap_function_expected", ["createFunction", "call"]) |
49 if (IS_UNDEFINED(constructTrap)) { | 49 if (IS_UNDEFINED(constructTrap)) { |
50 constructTrap = DerivedConstructTrap(callTrap) | 50 constructTrap = DerivedConstructTrap(callTrap) |
51 } else if (IS_SPEC_FUNCTION(constructTrap)) { | 51 } else if (IS_SPEC_FUNCTION(constructTrap)) { |
52 // Make sure the trap receives 'undefined' as this. | 52 // Make sure the trap receives 'undefined' as this. |
53 var construct = constructTrap | 53 var construct = constructTrap |
54 constructTrap = function() { | 54 constructTrap = function() { |
55 return %Apply(construct, void 0, arguments, 0, %_ArgumentsLength()); | 55 return %Apply(construct, void 0, arguments, 0, %_ArgumentsLength()); |
56 } | 56 } |
57 } else { | 57 } else { |
58 throw MakeTypeError("trap_function_expected", | 58 throw MakeTypeError("trap_function_expected", |
59 ["createFunction", "construct"]) | 59 ["createFunction", "construct"]) |
60 } | 60 } |
61 return %CreateJSFunctionProxy( | 61 return %CreateJSFunctionProxy( |
62 handler, callTrap, constructTrap, $Function.prototype) | 62 handler, callTrap, constructTrap, $Function.prototype) |
63 } | 63 } |
64 | 64 |
65 %InstallFunctions($Proxy, DONT_ENUM, [ | |
Michael Starzinger
2012/10/25 15:04:16
Change this to not use a natives syntax runtime ca
| |
66 "create", ProxyCreate, | |
67 "createFunction", ProxyCreateFunction | |
68 ]) | |
65 | 69 |
66 | 70 |
67 //////////////////////////////////////////////////////////////////////////////// | 71 //////////////////////////////////////////////////////////////////////////////// |
68 // Builtins | 72 // Builtins |
69 //////////////////////////////////////////////////////////////////////////////// | 73 //////////////////////////////////////////////////////////////////////////////// |
70 | 74 |
71 function DerivedConstructTrap(callTrap) { | 75 function DerivedConstructTrap(callTrap) { |
72 return function() { | 76 return function() { |
73 var proto = this.prototype | 77 var proto = this.prototype |
74 if (!IS_SPEC_OBJECT(proto)) proto = $Object.prototype | 78 if (!IS_SPEC_OBJECT(proto)) proto = $Object.prototype |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 } | 184 } |
181 | 185 |
182 function ProxyEnumerate(proxy) { | 186 function ProxyEnumerate(proxy) { |
183 var handler = %GetHandler(proxy) | 187 var handler = %GetHandler(proxy) |
184 if (IS_UNDEFINED(handler.enumerate)) { | 188 if (IS_UNDEFINED(handler.enumerate)) { |
185 return %Apply(DerivedEnumerateTrap, handler, [], 0, 0) | 189 return %Apply(DerivedEnumerateTrap, handler, [], 0, 0) |
186 } else { | 190 } else { |
187 return ToStringArray(handler.enumerate(), "enumerate") | 191 return ToStringArray(handler.enumerate(), "enumerate") |
188 } | 192 } |
189 } | 193 } |
OLD | NEW |