| 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 14 matching lines...) Expand all Loading... |
| 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 $Proxy.create = function(handler, proto) { | 32 $Proxy.create = function(handler, proto) { |
| 33 if (!IS_SPEC_OBJECT(handler)) | 33 if (!IS_SPEC_OBJECT(handler)) |
| 34 throw MakeTypeError("handler_non_object", ["create"]) | 34 throw MakeTypeError("handler_non_object", ["create"]) |
| 35 if (!IS_SPEC_OBJECT(proto)) proto = null // Mozilla does this... | 35 if (IS_UNDEFINED(proto)) |
| 36 proto = null |
| 37 else if (!(IS_SPEC_OBJECT(proto) || proto === null)) |
| 38 throw MakeTypeError("proto_non_object", ["create"]) |
| 36 return %CreateJSProxy(handler, proto) | 39 return %CreateJSProxy(handler, proto) |
| 37 } | 40 } |
| 38 | 41 |
| 39 $Proxy.createFunction = function(handler, callTrap, constructTrap) { | 42 $Proxy.createFunction = function(handler, callTrap, constructTrap) { |
| 40 if (!IS_SPEC_OBJECT(handler)) | 43 if (!IS_SPEC_OBJECT(handler)) |
| 41 throw MakeTypeError("handler_non_object", ["create"]) | 44 throw MakeTypeError("handler_non_object", ["create"]) |
| 42 if (!IS_SPEC_FUNCTION(callTrap)) | 45 if (!IS_SPEC_FUNCTION(callTrap)) |
| 43 throw MakeTypeError("trap_function_expected", ["createFunction", "call"]) | 46 throw MakeTypeError("trap_function_expected", ["createFunction", "call"]) |
| 44 var construct | |
| 45 if (IS_UNDEFINED(constructTrap)) { | 47 if (IS_UNDEFINED(constructTrap)) { |
| 46 construct = DerivedConstructTrap(callTrap) | 48 constructTrap = DerivedConstructTrap(callTrap) |
| 47 } else if (IS_SPEC_FUNCTION(constructTrap)) { | 49 } else if (IS_SPEC_FUNCTION(constructTrap)) { |
| 48 construct = function() { | 50 // Make sure the trap receives 'undefined' as this. |
| 49 // Make sure the trap receives 'undefined' as this. | 51 var construct = constructTrap |
| 50 return %Apply(constructTrap, void 0, arguments, 0, %_ArgumentsLength()); | 52 constructTrap = function() { |
| 53 return %Apply(construct, void 0, arguments, 0, %_ArgumentsLength()); |
| 51 } | 54 } |
| 52 } else { | 55 } else { |
| 53 throw MakeTypeError("trap_function_expected", | 56 throw MakeTypeError("trap_function_expected", |
| 54 ["createFunction", "construct"]) | 57 ["createFunction", "construct"]) |
| 55 } | 58 } |
| 56 return %CreateJSFunctionProxy( | 59 return %CreateJSFunctionProxy( |
| 57 handler, callTrap, construct, $Function.prototype) | 60 handler, callTrap, constructTrap, $Function.prototype) |
| 58 } | 61 } |
| 59 | 62 |
| 60 | 63 |
| 61 | 64 |
| 62 //////////////////////////////////////////////////////////////////////////////// | 65 //////////////////////////////////////////////////////////////////////////////// |
| 63 // Builtins | 66 // Builtins |
| 64 //////////////////////////////////////////////////////////////////////////////// | 67 //////////////////////////////////////////////////////////////////////////////// |
| 65 | 68 |
| 66 function DerivedConstructTrap(callTrap) { | 69 function DerivedConstructTrap(callTrap) { |
| 67 return function() { | 70 return function() { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 149 |
| 147 function DerivedHasOwnTrap(name) { | 150 function DerivedHasOwnTrap(name) { |
| 148 return !!this.getOwnPropertyDescriptor(name) | 151 return !!this.getOwnPropertyDescriptor(name) |
| 149 } | 152 } |
| 150 | 153 |
| 151 function DerivedKeysTrap() { | 154 function DerivedKeysTrap() { |
| 152 var names = this.getOwnPropertyNames() | 155 var names = this.getOwnPropertyNames() |
| 153 var enumerableNames = [] | 156 var enumerableNames = [] |
| 154 for (var i = 0, count = 0; i < names.length; ++i) { | 157 for (var i = 0, count = 0; i < names.length; ++i) { |
| 155 var name = names[i] | 158 var name = names[i] |
| 156 if (this.getOwnPropertyDescriptor(TO_STRING_INLINE(name)).enumerable) { | 159 var desc = this.getOwnPropertyDescriptor(TO_STRING_INLINE(name)) |
| 160 if (!IS_UNDEFINED(desc) && desc.enumerable) { |
| 157 enumerableNames[count++] = names[i] | 161 enumerableNames[count++] = names[i] |
| 158 } | 162 } |
| 159 } | 163 } |
| 160 return enumerableNames | 164 return enumerableNames |
| 161 } | 165 } |
| 166 |
| 167 function DerivedEnumerateTrap() { |
| 168 var names = this.getPropertyNames() |
| 169 var enumerableNames = [] |
| 170 for (var i = 0, count = 0; i < names.length; ++i) { |
| 171 var name = names[i] |
| 172 var desc = this.getPropertyDescriptor(TO_STRING_INLINE(name)) |
| 173 if (!IS_UNDEFINED(desc) && desc.enumerable) { |
| 174 enumerableNames[count++] = names[i] |
| 175 } |
| 176 } |
| 177 return enumerableNames |
| 178 } |
| 179 |
| 180 function ProxyEnumerate(proxy) { |
| 181 var handler = %GetHandler(proxy) |
| 182 if (IS_UNDEFINED(handler.enumerate)) { |
| 183 return %Apply(DerivedEnumerateTrap, handler, [], 0, 0) |
| 184 } else { |
| 185 return ToStringArray(handler.enumerate(), "enumerate") |
| 186 } |
| 187 } |
| OLD | NEW |