From 5fee61c9e84f53dd0bba28cb6928cdde092fa995 Mon Sep 17 00:00:00 2001 From: Mathieu Hofman <86499+mhofman@users.noreply.github.com> Date: Thu, 23 Sep 2021 20:36:37 -0300 Subject: [PATCH] Add test for freezing of module namespace object (#3213) Attempting to freeze the module namespace exotic object should not affect the `writable`-ity of the properties as that exercises the same `DefineOwnProperty` operation according to [`SetIntegrityLevel`](https://tc39.es/ecma262/#sec-setintegritylevel). @erights discovered a [bug in v8](https://bugs.chromium.org/p/v8/issues/detail?id=12240) where, while the `Object.freeze` operation throws, it actually makes exported properties non-writable one by one. At the request of @syg, I'm contributing a test against this behavior. The bug in v8 actually leads to a breakage of the objects invariants, however I'm not testing for that here as the root cause is the illegal freezing of the export. --- .../internals/define-own-property.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/language/module-code/namespace/internals/define-own-property.js b/test/language/module-code/namespace/internals/define-own-property.js index 23a22c2f26..0d61cbdd08 100644 --- a/test/language/module-code/namespace/internals/define-own-property.js +++ b/test/language/module-code/namespace/internals/define-own-property.js @@ -114,3 +114,24 @@ assert.throws(TypeError, function() { {value: "module", writable: false, enumerable: false, configurable: false}); }, 'Object.defineProperty: Symbol.toStringTag'); + + +// Indirect change requested through Object.freeze + +// Try freezing more times than there are exported properties +for (let i = 1; i < exported.length + 2; i++) { + assert.throws( + TypeError, + function () { + Object.freeze(ns); + }, + "Object.freeze: " + String(i) + ); +} + +for (const key of exported) { + const desc = Object.getOwnPropertyDescriptor(ns, key); + assert.sameValue(desc.writable, true, String(key) + " writable"); +} + +assert(!Object.isFrozen(ns), "namespace object not frozen");