| Index: src/proxy.js
|
| diff --git a/src/proxy.js b/src/proxy.js
|
| index 123e5671ac90727328b6bd5bd71d4fdbac068006..8162a3903db00e625b688b1ffb16e862634eb9b5 100644
|
| --- a/src/proxy.js
|
| +++ b/src/proxy.js
|
| @@ -42,13 +42,18 @@ $Proxy.createFunction = function(handler, callTrap, constructTrap) {
|
| if (!IS_FUNCTION(callTrap))
|
| throw MakeTypeError("trap_function_expected", ["createFunction", "call"])
|
| if (IS_UNDEFINED(constructTrap)) {
|
| - constructTrap = callTrap
|
| - } else if (!IS_FUNCTION(constructTrap)) {
|
| + var construct = DerivedConstructTrap(callTrap)
|
| + } else if (IS_FUNCTION(constructTrap)) {
|
| + construct = function() {
|
| + // Make sure the trap gets undefined as this.
|
| + return $Function.prototype.apply.call(constructTrap, void 0, arguments)
|
| + }
|
| + } else {
|
| throw MakeTypeError("trap_function_expected",
|
| ["createFunction", "construct"])
|
| }
|
| return %CreateJSFunctionProxy(
|
| - handler, callTrap, constructTrap, $Function.prototype)
|
| + handler, callTrap, construct, $Function.prototype)
|
| }
|
|
|
|
|
| @@ -57,13 +62,22 @@ $Proxy.createFunction = function(handler, callTrap, constructTrap) {
|
| // Builtins
|
| ////////////////////////////////////////////////////////////////////////////////
|
|
|
| +function DerivedConstructTrap(callTrap) {
|
| + return function() {
|
| + var proto = this.prototype
|
| + if (!IS_SPEC_OBJECT(proto)) proto = $Object.prototype
|
| + var obj = new $Object()
|
| + obj.__proto__ = proto
|
| + var result = $Function.prototype.apply.call(callTrap, obj, arguments)
|
| + return IS_SPEC_OBJECT(result) ? result : obj
|
| + }
|
| +}
|
| +
|
| function DelegateCallAndConstruct(callTrap, constructTrap) {
|
| return function() {
|
| if (%_IsConstructCall()) {
|
| - // return constructTrap.apply(this, arguments)
|
| return $Function.prototype.apply.call(constructTrap, this, arguments)
|
| } else {
|
| - // return callTrap.apply(this, arguments)
|
| return $Function.prototype.apply.call(callTrap, this, arguments)
|
| }
|
| }
|
|
|