Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update minimal.js to evade override mistake #1742

Merged
merged 3 commits into from Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/eslint.json
Expand Up @@ -14,7 +14,7 @@
"Promise": true
},
"parserOptions": {
"ecmaVersion": 5
"ecmaVersion": 6
},
"extends": "eslint:recommended",
"rules": {
Expand Down
31 changes: 24 additions & 7 deletions src/util/minimal.js
Expand Up @@ -280,13 +280,30 @@ function newError(name) {
merge(this, properties);
}

(CustomError.prototype = Object.create(Error.prototype)).constructor = CustomError;

Object.defineProperty(CustomError.prototype, "name", { get: function() { return name; } });

CustomError.prototype.toString = function toString() {
return this.name + ": " + this.message;
};
CustomError.prototype = Object.create(Error.prototype, {
constructor: {
value: CustomError,
writable: true,
enumerable: false,
configurable: true,
},
name: {
get() { return name; },
set: undefined,
enumerable: false,
// configurable: false would accurately preserve the behavior of
// the original, but I'm guessing that was not intentional.
// For an actual error subclass, this property would
// be configurable.
configurable: true,
},
toString: {
value() { return this.name + ": " + this.message; },
writable: true,
enumerable: false,
configurable: true,
},
});

return CustomError;
}
Expand Down