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

Commit

Permalink
chakrashim: use proxy to patch error types
Browse files Browse the repository at this point in the history
Previous patchErrorTypes() replaces builtin error types with custom
wrapper functions. However that breaks Error.stackTraceLimit. Setting
that property would be setting on the wrapper function, not builtin
Error function, thus has no effect on runtime. Replaced with proxies.

Reviewed-by: kunalspathak
  • Loading branch information
Jianchun Xu committed Jun 29, 2015
1 parent 26ff29c commit 70f8352
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions deps/chakrashim/lib/chakra_shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
var Object_defineProperty = Object.defineProperty,
Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor,
Object_getOwnPropertyNames = Object.getOwnPropertyNames,
Object_keys = Object.keys;
Object_keys = Object.keys,
Reflect_apply = Reflect.apply,
Reflect_construct = Reflect.construct;

function StackFrame(funcName, fileName, lineNumber, columnNumber) {
this.funcName = funcName;
Expand Down Expand Up @@ -177,18 +179,27 @@
// non-enumerable when creating Error instances.
// NOTE: This doesn't work if Error is created in Chakra runtime.
function patchErrorTypes() {
function makePropertiesNonEnumerable(e) {
Object_keys(e).forEach(function (key) {
Object_defineProperty(e, key, { enumerable: false });
});
return e;
}

[Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError,
URIError
].forEach(function (builtInError) {
var name = builtInError.name;
this[name] = function () {
var e = builtInError.apply(this, arguments);
Object_keys(e).forEach(function (key) {
Object_defineProperty(e, key, { enumerable: false });
});
return e;
};
cloneObject(builtInError, this[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));
}
});
});
}

Expand Down

0 comments on commit 70f8352

Please sign in to comment.