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 24 matching lines...) Expand all Loading... |
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_FUNCTION(callTrap)) | 42 if (!IS_FUNCTION(callTrap)) |
43 throw MakeTypeError("trap_function_expected", ["createFunction", "call"]) | 43 throw MakeTypeError("trap_function_expected", ["createFunction", "call"]) |
44 if (IS_UNDEFINED(constructTrap)) { | 44 if (IS_UNDEFINED(constructTrap)) { |
45 constructTrap = callTrap | 45 var construct = DerivedConstructTrap(callTrap) |
46 } else if (!IS_FUNCTION(constructTrap)) { | 46 } else if (IS_FUNCTION(constructTrap)) { |
| 47 construct = function() { |
| 48 // Make sure the trap gets undefined as this. |
| 49 return $Function.prototype.apply.call(constructTrap, void 0, arguments) |
| 50 } |
| 51 } else { |
47 throw MakeTypeError("trap_function_expected", | 52 throw MakeTypeError("trap_function_expected", |
48 ["createFunction", "construct"]) | 53 ["createFunction", "construct"]) |
49 } | 54 } |
50 return %CreateJSFunctionProxy( | 55 return %CreateJSFunctionProxy( |
51 handler, callTrap, constructTrap, $Function.prototype) | 56 handler, callTrap, construct, $Function.prototype) |
52 } | 57 } |
53 | 58 |
54 | 59 |
55 | 60 |
56 //////////////////////////////////////////////////////////////////////////////// | 61 //////////////////////////////////////////////////////////////////////////////// |
57 // Builtins | 62 // Builtins |
58 //////////////////////////////////////////////////////////////////////////////// | 63 //////////////////////////////////////////////////////////////////////////////// |
59 | 64 |
| 65 function DerivedConstructTrap(callTrap) { |
| 66 return function() { |
| 67 var proto = this.prototype |
| 68 if (!IS_SPEC_OBJECT(proto)) proto = $Object.prototype |
| 69 var obj = new $Object() |
| 70 obj.__proto__ = proto |
| 71 var result = $Function.prototype.apply.call(callTrap, obj, arguments) |
| 72 return IS_SPEC_OBJECT(result) ? result : obj |
| 73 } |
| 74 } |
| 75 |
60 function DelegateCallAndConstruct(callTrap, constructTrap) { | 76 function DelegateCallAndConstruct(callTrap, constructTrap) { |
61 return function() { | 77 return function() { |
62 if (%_IsConstructCall()) { | 78 if (%_IsConstructCall()) { |
63 // return constructTrap.apply(this, arguments) | |
64 return $Function.prototype.apply.call(constructTrap, this, arguments) | 79 return $Function.prototype.apply.call(constructTrap, this, arguments) |
65 } else { | 80 } else { |
66 // return callTrap.apply(this, arguments) | |
67 return $Function.prototype.apply.call(callTrap, this, arguments) | 81 return $Function.prototype.apply.call(callTrap, this, arguments) |
68 } | 82 } |
69 } | 83 } |
70 } | 84 } |
71 | 85 |
72 function DerivedGetTrap(receiver, name) { | 86 function DerivedGetTrap(receiver, name) { |
73 var desc = this.getPropertyDescriptor(name) | 87 var desc = this.getPropertyDescriptor(name) |
74 if (IS_UNDEFINED(desc)) { return desc } | 88 if (IS_UNDEFINED(desc)) { return desc } |
75 if ('value' in desc) { | 89 if ('value' in desc) { |
76 return desc.value | 90 return desc.value |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 var names = this.getOwnPropertyNames() | 154 var names = this.getOwnPropertyNames() |
141 var enumerableNames = [] | 155 var enumerableNames = [] |
142 for (var i = 0, count = 0; i < names.length; ++i) { | 156 for (var i = 0, count = 0; i < names.length; ++i) { |
143 var name = names[i] | 157 var name = names[i] |
144 if (this.getOwnPropertyDescriptor(TO_STRING_INLINE(name)).enumerable) { | 158 if (this.getOwnPropertyDescriptor(TO_STRING_INLINE(name)).enumerable) { |
145 enumerableNames[count++] = names[i] | 159 enumerableNames[count++] = names[i] |
146 } | 160 } |
147 } | 161 } |
148 return enumerableNames | 162 return enumerableNames |
149 } | 163 } |
OLD | NEW |