Skip to content

Commit

Permalink
Mark Switch and WebAssembly namespaces as non-enumerable
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Jan 9, 2024
1 parent 6c0dd23 commit 055c9f3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/sour-snails-grow.md
@@ -0,0 +1,5 @@
---
'nxjs-runtime': patch
---

Mark `Switch` and `WebAssembly` namespaces as non-enumerable
8 changes: 8 additions & 0 deletions apps/tests/src/wasm.ts
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions packages/runtime/src/utils.ts
Expand Up @@ -16,16 +16,16 @@ export const def = <T extends any>(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;
Expand Down

0 comments on commit 055c9f3

Please sign in to comment.