From de30695cf47850bd871f13b47f231918c33bf305 Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Fri, 10 Jun 2022 19:14:09 -0700 Subject: [PATCH 1/2] Update minimal.js See https://github.com/Agoric/agoric-sdk/blob/master/patches/%40confio%2Bics23%2B%2Bprotobufjs%2B6.11.3.patch The original code used assignment to override the `constructor` and `toString` properties inherited from Error.prototype. However, if `Error.prototype` is frozen, as it is under Hardened JS (aka SES) or under the Node frozen intrinsics flag, then this assignment fails due to the JavaScript "override mistake". `enumerable: true` would accurately preserve the behavior of the original assignment, but I'm guessing that was not intentional. For an actual error subclass, this property would not be enumerable, so my PR currently proposes that. But either would work, so let me know if you'd like me to change it. `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. But either would work, so let me know if you'd like me to change it. --- src/util/minimal.js | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/util/minimal.js b/src/util/minimal.js index 3c406dee7..35008ecc4 100644 --- a/src/util/minimal.js +++ b/src/util/minimal.js @@ -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; } From 5029a494bddc86af76bb771a5f272a88f2ddf216 Mon Sep 17 00:00:00 2001 From: Alexander Fenster Date: Thu, 7 Jul 2022 03:08:10 -0700 Subject: [PATCH 2/2] chore: use ecmaVersion=6 for eslint --- config/eslint.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/eslint.json b/config/eslint.json index 2800db370..b87a6eb4e 100644 --- a/config/eslint.json +++ b/config/eslint.json @@ -14,7 +14,7 @@ "Promise": true }, "parserOptions": { - "ecmaVersion": 5 + "ecmaVersion": 6 }, "extends": "eslint:recommended", "rules": {