From d5db5eeefe8a2e8596dcee321a131bd24c2a64ef Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Thu, 13 Oct 2022 16:36:40 -0700 Subject: [PATCH 1/2] Fix to be compat with the JS override mistake JavaScript has a misfeature often called the "override mistake". In an assignment such as ```js res.constructor = true; ``` if `res` does not yet have its own `constructor` property, but inherits one that this assignment would override (as is the intention here), but the property that would be overridden is a non-writable data property, then the assignment fails. Hardened JS and similar frameworks for securing JS routinely freeze all the primordial objects, which causes their data properties to become non-configurable, non-writable. Also, the TC53 JS standard for embedded devices standardizes on Hardened JS, which will also cause this problem. The XS JS engine for embedded devices use the Hardened JS configuration by default on embedded devices. Object literals and classes override inherited properties without problem because they use JS's "define" semantics rather than JS's peculiar "assign" semantics. You can also do so manually via `Object.defineProperty`, as this PR does to repair this issue. See also https://github.com/tapjs/stack-utils/issues/70 https://github.com/Agoric/agoric-sdk/pull/6451 --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index ed14bd3..ad9eeb1 100644 --- a/index.js +++ b/index.js @@ -161,7 +161,7 @@ class StackUtils { setFile(res, site.getFileName(), this._cwd); if (site.isConstructor()) { - res.constructor = true; + Object.defineProperty(res, 'constructor', { value: true }); } if (site.isEval()) { @@ -260,7 +260,7 @@ class StackUtils { setFile(res, file, this._cwd); if (ctor) { - res.constructor = true; + Object.defineProperty(res, 'constructor', { value: true }); } if (evalOrigin) { From f67064ff53ccfaf091cb40487bb7b7499c67de14 Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Sun, 6 Nov 2022 19:49:08 -0800 Subject: [PATCH 2/2] Review comments: add configurable --- index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index ad9eeb1..f567133 100644 --- a/index.js +++ b/index.js @@ -161,7 +161,10 @@ class StackUtils { setFile(res, site.getFileName(), this._cwd); if (site.isConstructor()) { - Object.defineProperty(res, 'constructor', { value: true }); + Object.defineProperty(res, 'constructor', { + value: true, + configurable: true, + }); } if (site.isEval()) { @@ -260,7 +263,10 @@ class StackUtils { setFile(res, file, this._cwd); if (ctor) { - Object.defineProperty(res, 'constructor', { value: true }); + Object.defineProperty(res, 'constructor', { + value: true, + configurable: true, + }); } if (evalOrigin) {