| 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 29 matching lines...) Expand all Loading... |
| 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 var construct |
| 45 if (IS_UNDEFINED(constructTrap)) { | 45 if (IS_UNDEFINED(constructTrap)) { |
| 46 construct = DerivedConstructTrap(callTrap) | 46 construct = DerivedConstructTrap(callTrap) |
| 47 } else if (IS_SPEC_FUNCTION(constructTrap)) { | 47 } else if (IS_SPEC_FUNCTION(constructTrap)) { |
| 48 construct = function() { | 48 construct = function() { |
| 49 // Make sure the trap receives 'undefined' as this. | 49 // Make sure the trap receives 'undefined' as this. |
| 50 return $Function.prototype.apply.call(constructTrap, void 0, arguments) | 50 return %Apply(constructTrap, void 0, arguments, 0, %_ArgumentsLength()); |
| 51 } | 51 } |
| 52 } else { | 52 } else { |
| 53 throw MakeTypeError("trap_function_expected", | 53 throw MakeTypeError("trap_function_expected", |
| 54 ["createFunction", "construct"]) | 54 ["createFunction", "construct"]) |
| 55 } | 55 } |
| 56 return %CreateJSFunctionProxy( | 56 return %CreateJSFunctionProxy( |
| 57 handler, callTrap, construct, $Function.prototype) | 57 handler, callTrap, construct, $Function.prototype) |
| 58 } | 58 } |
| 59 | 59 |
| 60 | 60 |
| 61 | 61 |
| 62 //////////////////////////////////////////////////////////////////////////////// | 62 //////////////////////////////////////////////////////////////////////////////// |
| 63 // Builtins | 63 // Builtins |
| 64 //////////////////////////////////////////////////////////////////////////////// | 64 //////////////////////////////////////////////////////////////////////////////// |
| 65 | 65 |
| 66 function DerivedConstructTrap(callTrap) { | 66 function DerivedConstructTrap(callTrap) { |
| 67 return function() { | 67 return function() { |
| 68 var proto = this.prototype | 68 var proto = this.prototype |
| 69 if (!IS_SPEC_OBJECT(proto)) proto = $Object.prototype | 69 if (!IS_SPEC_OBJECT(proto)) proto = $Object.prototype |
| 70 var obj = new $Object() | 70 var obj = new $Object() |
| 71 obj.__proto__ = proto | 71 obj.__proto__ = proto |
| 72 var result = $Function.prototype.apply.call(callTrap, obj, arguments) | 72 var result = %Apply(callTrap, obj, arguments, 0, %_ArgumentsLength()); |
| 73 return IS_SPEC_OBJECT(result) ? result : obj | 73 return IS_SPEC_OBJECT(result) ? result : obj |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 function DelegateCallAndConstruct(callTrap, constructTrap) { | 77 function DelegateCallAndConstruct(callTrap, constructTrap) { |
| 78 return function() { | 78 return function() { |
| 79 return %Apply(%_IsConstructCall() ? constructTrap : callTrap, | 79 return %Apply(%_IsConstructCall() ? constructTrap : callTrap, |
| 80 this, arguments, 0, %_ArgumentsLength()) | 80 this, arguments, 0, %_ArgumentsLength()) |
| 81 } | 81 } |
| 82 } | 82 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 var names = this.getOwnPropertyNames() | 152 var names = this.getOwnPropertyNames() |
| 153 var enumerableNames = [] | 153 var enumerableNames = [] |
| 154 for (var i = 0, count = 0; i < names.length; ++i) { | 154 for (var i = 0, count = 0; i < names.length; ++i) { |
| 155 var name = names[i] | 155 var name = names[i] |
| 156 if (this.getOwnPropertyDescriptor(TO_STRING_INLINE(name)).enumerable) { | 156 if (this.getOwnPropertyDescriptor(TO_STRING_INLINE(name)).enumerable) { |
| 157 enumerableNames[count++] = names[i] | 157 enumerableNames[count++] = names[i] |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 return enumerableNames | 160 return enumerableNames |
| 161 } | 161 } |
| OLD | NEW |