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 11 matching lines...) Expand all Loading... |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
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 global.Proxy = new $Object(); | 28 global.Proxy = new $Object(); |
29 | 29 |
30 var $Proxy = global.Proxy | 30 var $Proxy = global.Proxy |
31 | 31 |
32 var fundamentalTraps = [ | |
33 "getOwnPropertyDescriptor", | |
34 "getPropertyDescriptor", | |
35 "getOwnPropertyNames", | |
36 "getPropertyNames", | |
37 "defineProperty", | |
38 "delete", | |
39 "fix", | |
40 ] | |
41 | |
42 var derivedTraps = [ | |
43 "has", | |
44 "hasOwn", | |
45 "get", | |
46 "set", | |
47 "enumerate", | |
48 "keys", | |
49 ] | |
50 | |
51 var functionTraps = [ | |
52 "callTrap", | |
53 "constructTrap", | |
54 ] | |
55 | |
56 $Proxy.createFunction = function(handler, callTrap, constructTrap) { | |
57 handler.callTrap = callTrap | |
58 handler.constructTrap = constructTrap | |
59 $Proxy.create(handler) | |
60 } | |
61 | |
62 $Proxy.create = function(handler, proto) { | 32 $Proxy.create = function(handler, proto) { |
63 if (!IS_SPEC_OBJECT(handler)) | 33 if (!IS_SPEC_OBJECT(handler)) |
64 throw MakeTypeError("handler_non_object", ["create"]) | 34 throw MakeTypeError("handler_non_object", ["create"]) |
65 if (!IS_SPEC_OBJECT(proto)) proto = null // Mozilla does this... | 35 if (!IS_SPEC_OBJECT(proto)) proto = null // Mozilla does this... |
66 return %CreateJSProxy(handler, proto) | 36 return %CreateJSProxy(handler, proto) |
67 } | 37 } |
68 | 38 |
| 39 $Proxy.createFunction = function(handler, callTrap, constructTrap) { |
| 40 if (!IS_SPEC_OBJECT(handler)) |
| 41 throw MakeTypeError("handler_non_object", ["create"]) |
| 42 if (!IS_SPEC_FUNCTION(callTrap)) |
| 43 throw MakeTypeError("trap_function_expected", ["createFunction", "call"]) |
| 44 if (IS_UNDEFINED(constructTrap)) { |
| 45 constructTrap = callTrap |
| 46 } else if (!IS_SPEC_FUNCTION(constructTrap)) { |
| 47 throw MakeTypeError("trap_function_expected", |
| 48 ["createFunction", "construct"]) |
| 49 } |
| 50 return %CreateJSFunctionProxy( |
| 51 handler, callTrap, constructTrap, $Function.prototype) |
| 52 } |
| 53 |
69 | 54 |
70 | 55 |
71 | |
72 //////////////////////////////////////////////////////////////////////////////// | 56 //////////////////////////////////////////////////////////////////////////////// |
73 // Builtins | 57 // Builtins |
74 //////////////////////////////////////////////////////////////////////////////// | 58 //////////////////////////////////////////////////////////////////////////////// |
75 | 59 |
| 60 function DelegateCallAndConstruct(callTrap, constructTrap) { |
| 61 return function() { |
| 62 return %Apply(%_IsConstructCall() ? constructTrap : callTrap, |
| 63 this, arguments, 0, %_ArgumentsLength()) |
| 64 } |
| 65 } |
| 66 |
76 function DerivedGetTrap(receiver, name) { | 67 function DerivedGetTrap(receiver, name) { |
77 var desc = this.getPropertyDescriptor(name) | 68 var desc = this.getPropertyDescriptor(name) |
78 if (IS_UNDEFINED(desc)) { return desc } | 69 if (IS_UNDEFINED(desc)) { return desc } |
79 if ('value' in desc) { | 70 if ('value' in desc) { |
80 return desc.value | 71 return desc.value |
81 } else { | 72 } else { |
82 if (IS_UNDEFINED(desc.get)) { return desc.get } | 73 if (IS_UNDEFINED(desc.get)) { return desc.get } |
83 // The proposal says: desc.get.call(receiver) | 74 // The proposal says: desc.get.call(receiver) |
84 return %_CallFunction(receiver, desc.get) | 75 return %_CallFunction(receiver, desc.get) |
85 } | 76 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 var names = this.getOwnPropertyNames() | 135 var names = this.getOwnPropertyNames() |
145 var enumerableNames = [] | 136 var enumerableNames = [] |
146 for (var i = 0, count = 0; i < names.length; ++i) { | 137 for (var i = 0, count = 0; i < names.length; ++i) { |
147 var name = names[i] | 138 var name = names[i] |
148 if (this.getOwnPropertyDescriptor(TO_STRING_INLINE(name)).enumerable) { | 139 if (this.getOwnPropertyDescriptor(TO_STRING_INLINE(name)).enumerable) { |
149 enumerableNames[count++] = names[i] | 140 enumerableNames[count++] = names[i] |
150 } | 141 } |
151 } | 142 } |
152 return enumerableNames | 143 return enumerableNames |
153 } | 144 } |
OLD | NEW |