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 23 matching lines...) Expand all Loading... |
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_SPEC_OBJECT(proto)) proto = null // Mozilla does this... |
36 return %CreateJSProxy(handler, proto) | 36 return %CreateJSProxy(handler, proto) |
37 } | 37 } |
38 | 38 |
39 $Proxy.createFunction = function(handler, callTrap, constructTrap) { | 39 $Proxy.createFunction = function(handler, callTrap, constructTrap) { |
40 if (!IS_SPEC_OBJECT(handler)) | 40 if (!IS_SPEC_OBJECT(handler)) |
41 throw MakeTypeError("handler_non_object", ["create"]) | 41 throw MakeTypeError("handler_non_object", ["create"]) |
42 if (!IS_SPEC_FUNCTION(callTrap)) | 42 if (!IS_SPEC_FUNCTION(callTrap)) |
43 throw MakeTypeError("trap_function_expected", ["createFunction", "call"]) | 43 throw MakeTypeError("trap_function_expected", ["createFunction", "call"]) |
| 44 var construct |
44 if (IS_UNDEFINED(constructTrap)) { | 45 if (IS_UNDEFINED(constructTrap)) { |
45 constructTrap = callTrap | 46 construct = DerivedConstructTrap(callTrap) |
46 } else if (!IS_SPEC_FUNCTION(constructTrap)) { | 47 } else if (IS_SPEC_FUNCTION(constructTrap)) { |
| 48 construct = function() { |
| 49 // Make sure the trap receives 'undefined' as this. |
| 50 return %Apply(constructTrap, void 0, arguments, 0, %_ArgumentsLength()); |
| 51 } |
| 52 } else { |
47 throw MakeTypeError("trap_function_expected", | 53 throw MakeTypeError("trap_function_expected", |
48 ["createFunction", "construct"]) | 54 ["createFunction", "construct"]) |
49 } | 55 } |
50 return %CreateJSFunctionProxy( | 56 return %CreateJSFunctionProxy( |
51 handler, callTrap, constructTrap, $Function.prototype) | 57 handler, callTrap, construct, $Function.prototype) |
52 } | 58 } |
53 | 59 |
54 | 60 |
55 | 61 |
56 //////////////////////////////////////////////////////////////////////////////// | 62 //////////////////////////////////////////////////////////////////////////////// |
57 // Builtins | 63 // Builtins |
58 //////////////////////////////////////////////////////////////////////////////// | 64 //////////////////////////////////////////////////////////////////////////////// |
59 | 65 |
| 66 function DerivedConstructTrap(callTrap) { |
| 67 return function() { |
| 68 var proto = this.prototype |
| 69 if (!IS_SPEC_OBJECT(proto)) proto = $Object.prototype |
| 70 var obj = new $Object() |
| 71 obj.__proto__ = proto |
| 72 var result = %Apply(callTrap, obj, arguments, 0, %_ArgumentsLength()); |
| 73 return IS_SPEC_OBJECT(result) ? result : obj |
| 74 } |
| 75 } |
| 76 |
60 function DelegateCallAndConstruct(callTrap, constructTrap) { | 77 function DelegateCallAndConstruct(callTrap, constructTrap) { |
61 return function() { | 78 return function() { |
62 return %Apply(%_IsConstructCall() ? constructTrap : callTrap, | 79 return %Apply(%_IsConstructCall() ? constructTrap : callTrap, |
63 this, arguments, 0, %_ArgumentsLength()) | 80 this, arguments, 0, %_ArgumentsLength()) |
64 } | 81 } |
65 } | 82 } |
66 | 83 |
67 function DerivedGetTrap(receiver, name) { | 84 function DerivedGetTrap(receiver, name) { |
68 var desc = this.getPropertyDescriptor(name) | 85 var desc = this.getPropertyDescriptor(name) |
69 if (IS_UNDEFINED(desc)) { return desc } | 86 if (IS_UNDEFINED(desc)) { return desc } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 var names = this.getOwnPropertyNames() | 152 var names = this.getOwnPropertyNames() |
136 var enumerableNames = [] | 153 var enumerableNames = [] |
137 for (var i = 0, count = 0; i < names.length; ++i) { | 154 for (var i = 0, count = 0; i < names.length; ++i) { |
138 var name = names[i] | 155 var name = names[i] |
139 if (this.getOwnPropertyDescriptor(TO_STRING_INLINE(name)).enumerable) { | 156 if (this.getOwnPropertyDescriptor(TO_STRING_INLINE(name)).enumerable) { |
140 enumerableNames[count++] = names[i] | 157 enumerableNames[count++] = names[i] |
141 } | 158 } |
142 } | 159 } |
143 return enumerableNames | 160 return enumerableNames |
144 } | 161 } |
OLD | NEW |