diff --git a/.changeset/sour-snails-grow.md b/.changeset/sour-snails-grow.md new file mode 100644 index 00000000..89ec647b --- /dev/null +++ b/.changeset/sour-snails-grow.md @@ -0,0 +1,5 @@ +--- +'nxjs-runtime': patch +--- + +Mark `Switch` and `WebAssembly` namespaces as non-enumerable diff --git a/apps/tests/src/wasm.ts b/apps/tests/src/wasm.ts index 99c9e57c..6338707c 100644 --- a/apps/tests/src/wasm.ts +++ b/apps/tests/src/wasm.ts @@ -3,6 +3,14 @@ import * as assert from 'uvu/assert'; const test = suite('WebAssembly'); +test('WebAssembly namespace', () => { + const desc = Object.getOwnPropertyDescriptor(globalThis, 'WebAssembly')!; + assert.equal(desc.writable, true); + assert.equal(desc.enumerable, false); + assert.equal(desc.configurable, true); + assert.equal(Object.prototype.toString.call(WebAssembly), '[object WebAssembly]'); +}); + test('simple.wasm', async () => { const bin = await Switch.readFile( new URL('wasm/simple.wasm', Switch.entrypoint) diff --git a/packages/runtime/src/utils.ts b/packages/runtime/src/utils.ts index 7268cea3..3fe110b9 100644 --- a/packages/runtime/src/utils.ts +++ b/packages/runtime/src/utils.ts @@ -16,16 +16,16 @@ export const def = (value: T, key?: string) => { } } const proto = (value as any).prototype; - const isClass = typeof proto === 'object'; + const isClass = key[0] === key[0].toUpperCase(); if (isClass) { - Object.defineProperty(proto, Symbol.toStringTag, { + Object.defineProperty(proto || value, Symbol.toStringTag, { value: key, }); } Object.defineProperty(globalThis, key, { value, writable: true, - enumerable: false, + enumerable: !isClass, configurable: true, }); return value;