@@ -52,7 +52,142 @@ describe('ESM: WASM modules', { concurrency: !process.env.TEST_PARALLEL }, () =>
5252 [
5353 'import { strictEqual } from "node:assert";' ,
5454 `import * as wasmExports from ${ JSON . stringify ( fixtures . fileURL ( 'es-modules/export-name-syntax-error.wasm' ) ) } ;` ,
55- 'assert.strictEqual(wasmExports["?f!o:o<b>a[r]"]?.value, 12682);' ,
55+ 'assert.strictEqual(wasmExports["?f!o:o<b>a[r]"], 12682);' ,
56+ ] . join ( '\n' ) ,
57+ ] ) ;
58+
59+ strictEqual ( stderr , '' ) ;
60+ strictEqual ( stdout , '' ) ;
61+ strictEqual ( code , 0 ) ;
62+ } ) ;
63+
64+ it ( 'should properly handle all WebAssembly global types' , async ( ) => {
65+ const { code, stderr, stdout } = await spawnPromisified ( execPath , [
66+ '--no-warnings' ,
67+ '--experimental-wasm-modules' ,
68+ '--input-type=module' ,
69+ '--eval' ,
70+ [
71+ 'import { strictEqual, deepStrictEqual } from "node:assert";' ,
72+ `import * as wasmExports from ${ JSON . stringify ( fixtures . fileURL ( 'es-modules/globals.wasm' ) ) } ;` ,
73+
74+ // Test imported globals using direct access
75+ 'strictEqual(wasmExports.importedI32, 42);' ,
76+ 'strictEqual(wasmExports.importedMutI32, 100);' ,
77+ 'strictEqual(wasmExports.importedI64, 9223372036854775807n);' ,
78+ 'strictEqual(wasmExports.importedMutI64, 200n);' ,
79+ 'strictEqual(Math.round(wasmExports.importedF32 * 100000) / 100000, 3.14159);' ,
80+ 'strictEqual(Math.round(wasmExports.importedMutF32 * 100000) / 100000, 2.71828);' ,
81+ 'strictEqual(wasmExports.importedF64, 3.141592653589793);' ,
82+ 'strictEqual(wasmExports.importedMutF64, 2.718281828459045);' ,
83+ 'strictEqual(wasmExports.importedExternref !== null, true);' ,
84+ 'strictEqual(wasmExports.importedMutExternref !== null, true);' ,
85+ 'strictEqual(wasmExports.importedNullExternref, null);' ,
86+
87+ // Test local globals exported directly
88+ 'strictEqual(wasmExports[\'🚀localI32\'], 42);' ,
89+ 'strictEqual(wasmExports.localMutI32, 100);' ,
90+ 'strictEqual(wasmExports.localI64, 9223372036854775807n);' ,
91+ 'strictEqual(wasmExports.localMutI64, 200n);' ,
92+ 'strictEqual(Math.round(wasmExports.localF32 * 100000) / 100000, 3.14159);' ,
93+ 'strictEqual(Math.round(wasmExports.localMutF32 * 100000) / 100000, 2.71828);' ,
94+ 'strictEqual(wasmExports.localF64, 2.718281828459045);' ,
95+ 'strictEqual(wasmExports.localMutF64, 3.141592653589793);' ,
96+
97+ // Test imported globals using getter functions
98+ 'strictEqual(wasmExports.getImportedMutI32(), 100);' ,
99+ 'strictEqual(wasmExports.getImportedMutI64(), 200n);' ,
100+ 'strictEqual(Math.round(wasmExports.getImportedMutF32() * 100000) / 100000, 2.71828);' ,
101+ 'strictEqual(wasmExports.getImportedMutF64(), 2.718281828459045);' ,
102+ 'strictEqual(wasmExports.getImportedMutExternref() !== null, true);' ,
103+
104+ // Test local globals using getter functions
105+ 'strictEqual(wasmExports.getLocalMutI32(), 100);' ,
106+ 'strictEqual(wasmExports.getLocalMutI64(), 200n);' ,
107+ 'strictEqual(Math.round(wasmExports.getLocalMutF32() * 100000) / 100000, 2.71828);' ,
108+ 'strictEqual(wasmExports.getLocalMutF64(), 3.141592653589793);' ,
109+ 'strictEqual(wasmExports.getLocalMutExternref(), null);' ,
110+
111+ 'assert.throws(wasmExports.getLocalMutV128);' ,
112+
113+ // Pending TDZ support
114+ 'strictEqual(wasmExports.depV128, undefined);' ,
115+
116+ // Test modifying mutable globals and reading the new values
117+ 'wasmExports.setImportedMutI32(999);' ,
118+ 'strictEqual(wasmExports.getImportedMutI32(), 999);' ,
119+
120+ 'wasmExports.setImportedMutI64(888n);' ,
121+ 'strictEqual(wasmExports.getImportedMutI64(), 888n);' ,
122+
123+ 'wasmExports.setImportedMutF32(7.77);' ,
124+ 'strictEqual(Math.round(wasmExports.getImportedMutF32() * 100) / 100, 7.77);' ,
125+
126+ 'wasmExports.setImportedMutF64(6.66);' ,
127+ 'strictEqual(wasmExports.getImportedMutF64(), 6.66);' ,
128+
129+ // Test modifying mutable externref
130+ 'const testObj = { test: "object" };' ,
131+ 'wasmExports.setImportedMutExternref(testObj);' ,
132+ 'strictEqual(wasmExports.getImportedMutExternref(), testObj);' ,
133+
134+ // Test modifying local mutable globals
135+ 'wasmExports.setLocalMutI32(555);' ,
136+ 'strictEqual(wasmExports.getLocalMutI32(), 555);' ,
137+
138+ 'wasmExports.setLocalMutI64(444n);' ,
139+ 'strictEqual(wasmExports.getLocalMutI64(), 444n);' ,
140+
141+ 'wasmExports.setLocalMutF32(3.33);' ,
142+ 'strictEqual(Math.round(wasmExports.getLocalMutF32() * 100) / 100, 3.33);' ,
143+
144+ 'wasmExports.setLocalMutF64(2.22);' ,
145+ 'strictEqual(wasmExports.getLocalMutF64(), 2.22);' ,
146+
147+ // These mutating pending live bindings support
148+ 'strictEqual(wasmExports.localMutI32, 100);' ,
149+ 'strictEqual(wasmExports.localMutI64, 200n);' ,
150+ 'strictEqual(Math.round(wasmExports.localMutF32 * 100) / 100, 2.72);' ,
151+ 'strictEqual(wasmExports.localMutF64, 3.141592653589793);' ,
152+
153+ // Test modifying local mutable externref
154+ 'const anotherTestObj = { another: "test object" };' ,
155+ 'wasmExports.setLocalMutExternref(anotherTestObj);' ,
156+ 'strictEqual(wasmExports.getLocalMutExternref(), anotherTestObj);' ,
157+ 'strictEqual(wasmExports.localMutExternref, null);' ,
158+
159+ // Test dep.wasm imports
160+ 'strictEqual(wasmExports.depI32, 1001);' ,
161+ 'strictEqual(wasmExports.depMutI32, 2001);' ,
162+ 'strictEqual(wasmExports.getDepMutI32(), 2001);' ,
163+ 'strictEqual(wasmExports.depI64, 10000000001n);' ,
164+ 'strictEqual(wasmExports.depMutI64, 20000000001n);' ,
165+ 'strictEqual(wasmExports.getDepMutI64(), 20000000001n);' ,
166+ 'strictEqual(Math.round(wasmExports.depF32 * 100) / 100, 10.01);' ,
167+ 'strictEqual(Math.round(wasmExports.depMutF32 * 100) / 100, 20.01);' ,
168+ 'strictEqual(Math.round(wasmExports.getDepMutF32() * 100) / 100, 20.01);' ,
169+ 'strictEqual(wasmExports.depF64, 100.0001);' ,
170+ 'strictEqual(wasmExports.depMutF64, 200.0001);' ,
171+ 'strictEqual(wasmExports.getDepMutF64(), 200.0001);' ,
172+
173+ // Test modifying dep.wasm mutable globals
174+ 'wasmExports.setDepMutI32(3001);' ,
175+ 'strictEqual(wasmExports.getDepMutI32(), 3001);' ,
176+
177+ 'wasmExports.setDepMutI64(30000000001n);' ,
178+ 'strictEqual(wasmExports.getDepMutI64(), 30000000001n);' ,
179+
180+ 'wasmExports.setDepMutF32(30.01);' ,
181+ 'strictEqual(Math.round(wasmExports.getDepMutF32() * 100) / 100, 30.01);' ,
182+
183+ 'wasmExports.setDepMutF64(300.0001);' ,
184+ 'strictEqual(wasmExports.getDepMutF64(), 300.0001);' ,
185+
186+ // These pending live bindings support
187+ 'strictEqual(wasmExports.depMutI32, 2001);' ,
188+ 'strictEqual(wasmExports.depMutI64, 20000000001n);' ,
189+ 'strictEqual(Math.round(wasmExports.depMutF32 * 100) / 100, 20.01);' ,
190+ 'strictEqual(wasmExports.depMutF64, 200.0001);' ,
56191 ] . join ( '\n' ) ,
57192 ] ) ;
58193
0 commit comments