Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
chakrashim: revert error types proxy change
Browse files Browse the repository at this point in the history
Using Proxy to wrap Error types run into some regressions. e.g.,
toString() call fails. Revert that change and add special handling for
toString and stackTraceLimit.

Reviewed-by: kunalspathak
  • Loading branch information
Jianchun Xu committed Jun 29, 2015
1 parent 9d2faef commit 9a1945b
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions deps/chakrashim/lib/chakra_shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor,
Object_getOwnPropertyNames = Object.getOwnPropertyNames,
Object_keys = Object.keys,
Reflect_apply = Reflect.apply,
Reflect_construct = Reflect.construct;

function StackFrame(funcName, fileName, lineNumber, columnNumber) {
Expand Down Expand Up @@ -186,20 +185,27 @@
return e;
}

var builtInError = Error;

[Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError,
URIError
].forEach(function (builtInError) {
var name = builtInError.name;
this[name] = new Proxy(builtInError, {
apply: function(target, thisArg, argumentsList) {
return makePropertiesNonEnumerable(
Reflect_apply(target, thisArg, argumentsList));
},
construct: function(target, argumentsList) {
return makePropertiesNonEnumerable(
Reflect_construct(target, argumentsList));
}
});
].forEach(function (type) {
var newType = function () {
return makePropertiesNonEnumerable(Reflect_construct(type, arguments));
};
cloneObject(type, newType);
newType.toString = function () {
return type.toString();
};
this[type.name] = newType;
});

// Delegate Error.stackTraceLimit to saved Error constructor
Object_defineProperty(this['Error'], 'stackTraceLimit', {
enumerable: false,
configurable: true,
get: function () { return builtInError.stackTraceLimit; },
set: function (value) { builtInError.stackTraceLimit = value; }
});
}

Expand Down

0 comments on commit 9a1945b

Please sign in to comment.