@@ -71,130 +71,135 @@ describe('ESM: WASM modules', { concurrency: !process.env.TEST_PARALLEL }, () =>
71
71
'import { strictEqual, deepStrictEqual, ok } from "node:assert";' ,
72
72
73
73
// SIMD is not supported on rhel8-ppc64le
74
+ 'let wasmExports;' ,
74
75
'try {' ,
75
- ` const wasmExports = await import(${ JSON . stringify ( fixtures . fileURL ( 'es-modules/globals.wasm' ) ) } );` ,
76
+ ` wasmExports = await import(${ JSON . stringify ( fixtures . fileURL ( 'es-modules/globals.wasm' ) ) } );` ,
76
77
'} catch (e) {' ,
77
78
' ok(e instanceof WebAssembly.CompileError);' ,
78
79
' ok(e.message.includes("SIMD unsupported"));' ,
79
80
'}' ,
80
81
82
+ 'if (wasmExports) {' ,
83
+
81
84
// Test imported globals using direct access
82
- 'strictEqual(wasmExports.importedI32, 42);' ,
83
- 'strictEqual(wasmExports.importedMutI32, 100);' ,
84
- 'strictEqual(wasmExports.importedI64, 9223372036854775807n);' ,
85
- 'strictEqual(wasmExports.importedMutI64, 200n);' ,
86
- 'strictEqual(Math.round(wasmExports.importedF32 * 100000) / 100000, 3.14159);' ,
87
- 'strictEqual(Math.round(wasmExports.importedMutF32 * 100000) / 100000, 2.71828);' ,
88
- 'strictEqual(wasmExports.importedF64, 3.141592653589793);' ,
89
- 'strictEqual(wasmExports.importedMutF64, 2.718281828459045);' ,
90
- 'strictEqual(wasmExports.importedExternref !== null, true);' ,
91
- 'strictEqual(wasmExports.importedMutExternref !== null, true);' ,
92
- 'strictEqual(wasmExports.importedNullExternref, null);' ,
85
+ ' strictEqual(wasmExports.importedI32, 42);' ,
86
+ ' strictEqual(wasmExports.importedMutI32, 100);' ,
87
+ ' strictEqual(wasmExports.importedI64, 9223372036854775807n);' ,
88
+ ' strictEqual(wasmExports.importedMutI64, 200n);' ,
89
+ ' strictEqual(Math.round(wasmExports.importedF32 * 100000) / 100000, 3.14159);' ,
90
+ ' strictEqual(Math.round(wasmExports.importedMutF32 * 100000) / 100000, 2.71828);' ,
91
+ ' strictEqual(wasmExports.importedF64, 3.141592653589793);' ,
92
+ ' strictEqual(wasmExports.importedMutF64, 2.718281828459045);' ,
93
+ ' strictEqual(wasmExports.importedExternref !== null, true);' ,
94
+ ' strictEqual(wasmExports.importedMutExternref !== null, true);' ,
95
+ ' strictEqual(wasmExports.importedNullExternref, null);' ,
93
96
94
97
// Test local globals exported directly
95
- 'strictEqual(wasmExports[\'🚀localI32\'], 42);' ,
96
- 'strictEqual(wasmExports.localMutI32, 100);' ,
97
- 'strictEqual(wasmExports.localI64, 9223372036854775807n);' ,
98
- 'strictEqual(wasmExports.localMutI64, 200n);' ,
99
- 'strictEqual(Math.round(wasmExports.localF32 * 100000) / 100000, 3.14159);' ,
100
- 'strictEqual(Math.round(wasmExports.localMutF32 * 100000) / 100000, 2.71828);' ,
101
- 'strictEqual(wasmExports.localF64, 2.718281828459045);' ,
102
- 'strictEqual(wasmExports.localMutF64, 3.141592653589793);' ,
98
+ ' strictEqual(wasmExports[\'🚀localI32\'], 42);' ,
99
+ ' strictEqual(wasmExports.localMutI32, 100);' ,
100
+ ' strictEqual(wasmExports.localI64, 9223372036854775807n);' ,
101
+ ' strictEqual(wasmExports.localMutI64, 200n);' ,
102
+ ' strictEqual(Math.round(wasmExports.localF32 * 100000) / 100000, 3.14159);' ,
103
+ ' strictEqual(Math.round(wasmExports.localMutF32 * 100000) / 100000, 2.71828);' ,
104
+ ' strictEqual(wasmExports.localF64, 2.718281828459045);' ,
105
+ ' strictEqual(wasmExports.localMutF64, 3.141592653589793);' ,
103
106
104
107
// Test imported globals using getter functions
105
- 'strictEqual(wasmExports.getImportedMutI32(), 100);' ,
106
- 'strictEqual(wasmExports.getImportedMutI64(), 200n);' ,
107
- 'strictEqual(Math.round(wasmExports.getImportedMutF32() * 100000) / 100000, 2.71828);' ,
108
- 'strictEqual(wasmExports.getImportedMutF64(), 2.718281828459045);' ,
109
- 'strictEqual(wasmExports.getImportedMutExternref() !== null, true);' ,
108
+ ' strictEqual(wasmExports.getImportedMutI32(), 100);' ,
109
+ ' strictEqual(wasmExports.getImportedMutI64(), 200n);' ,
110
+ ' strictEqual(Math.round(wasmExports.getImportedMutF32() * 100000) / 100000, 2.71828);' ,
111
+ ' strictEqual(wasmExports.getImportedMutF64(), 2.718281828459045);' ,
112
+ ' strictEqual(wasmExports.getImportedMutExternref() !== null, true);' ,
110
113
111
114
// Test local globals using getter functions
112
- 'strictEqual(wasmExports.getLocalMutI32(), 100);' ,
113
- 'strictEqual(wasmExports.getLocalMutI64(), 200n);' ,
114
- 'strictEqual(Math.round(wasmExports.getLocalMutF32() * 100000) / 100000, 2.71828);' ,
115
- 'strictEqual(wasmExports.getLocalMutF64(), 3.141592653589793);' ,
116
- 'strictEqual(wasmExports.getLocalMutExternref(), null);' ,
115
+ ' strictEqual(wasmExports.getLocalMutI32(), 100);' ,
116
+ ' strictEqual(wasmExports.getLocalMutI64(), 200n);' ,
117
+ ' strictEqual(Math.round(wasmExports.getLocalMutF32() * 100000) / 100000, 2.71828);' ,
118
+ ' strictEqual(wasmExports.getLocalMutF64(), 3.141592653589793);' ,
119
+ ' strictEqual(wasmExports.getLocalMutExternref(), null);' ,
117
120
118
- 'assert.throws(wasmExports.getLocalMutV128);' ,
121
+ ' assert.throws(wasmExports.getLocalMutV128);' ,
119
122
120
123
// Pending TDZ support
121
- 'strictEqual(wasmExports.depV128, undefined);' ,
124
+ ' strictEqual(wasmExports.depV128, undefined);' ,
122
125
123
126
// Test modifying mutable globals and reading the new values
124
- 'wasmExports.setImportedMutI32(999);' ,
125
- 'strictEqual(wasmExports.getImportedMutI32(), 999);' ,
127
+ ' wasmExports.setImportedMutI32(999);' ,
128
+ ' strictEqual(wasmExports.getImportedMutI32(), 999);' ,
126
129
127
- 'wasmExports.setImportedMutI64(888n);' ,
128
- 'strictEqual(wasmExports.getImportedMutI64(), 888n);' ,
130
+ ' wasmExports.setImportedMutI64(888n);' ,
131
+ ' strictEqual(wasmExports.getImportedMutI64(), 888n);' ,
129
132
130
- 'wasmExports.setImportedMutF32(7.77);' ,
131
- 'strictEqual(Math.round(wasmExports.getImportedMutF32() * 100) / 100, 7.77);' ,
133
+ ' wasmExports.setImportedMutF32(7.77);' ,
134
+ ' strictEqual(Math.round(wasmExports.getImportedMutF32() * 100) / 100, 7.77);' ,
132
135
133
- 'wasmExports.setImportedMutF64(6.66);' ,
134
- 'strictEqual(wasmExports.getImportedMutF64(), 6.66);' ,
136
+ ' wasmExports.setImportedMutF64(6.66);' ,
137
+ ' strictEqual(wasmExports.getImportedMutF64(), 6.66);' ,
135
138
136
139
// Test modifying mutable externref
137
- 'const testObj = { test: "object" };' ,
138
- 'wasmExports.setImportedMutExternref(testObj);' ,
139
- 'strictEqual(wasmExports.getImportedMutExternref(), testObj);' ,
140
+ ' const testObj = { test: "object" };' ,
141
+ ' wasmExports.setImportedMutExternref(testObj);' ,
142
+ ' strictEqual(wasmExports.getImportedMutExternref(), testObj);' ,
140
143
141
144
// Test modifying local mutable globals
142
- 'wasmExports.setLocalMutI32(555);' ,
143
- 'strictEqual(wasmExports.getLocalMutI32(), 555);' ,
145
+ ' wasmExports.setLocalMutI32(555);' ,
146
+ ' strictEqual(wasmExports.getLocalMutI32(), 555);' ,
144
147
145
- 'wasmExports.setLocalMutI64(444n);' ,
146
- 'strictEqual(wasmExports.getLocalMutI64(), 444n);' ,
148
+ ' wasmExports.setLocalMutI64(444n);' ,
149
+ ' strictEqual(wasmExports.getLocalMutI64(), 444n);' ,
147
150
148
- 'wasmExports.setLocalMutF32(3.33);' ,
149
- 'strictEqual(Math.round(wasmExports.getLocalMutF32() * 100) / 100, 3.33);' ,
151
+ ' wasmExports.setLocalMutF32(3.33);' ,
152
+ ' strictEqual(Math.round(wasmExports.getLocalMutF32() * 100) / 100, 3.33);' ,
150
153
151
- 'wasmExports.setLocalMutF64(2.22);' ,
152
- 'strictEqual(wasmExports.getLocalMutF64(), 2.22);' ,
154
+ ' wasmExports.setLocalMutF64(2.22);' ,
155
+ ' strictEqual(wasmExports.getLocalMutF64(), 2.22);' ,
153
156
154
157
// These mutating pending live bindings support
155
- 'strictEqual(wasmExports.localMutI32, 100);' ,
156
- 'strictEqual(wasmExports.localMutI64, 200n);' ,
157
- 'strictEqual(Math.round(wasmExports.localMutF32 * 100) / 100, 2.72);' ,
158
- 'strictEqual(wasmExports.localMutF64, 3.141592653589793);' ,
158
+ ' strictEqual(wasmExports.localMutI32, 100);' ,
159
+ ' strictEqual(wasmExports.localMutI64, 200n);' ,
160
+ ' strictEqual(Math.round(wasmExports.localMutF32 * 100) / 100, 2.72);' ,
161
+ ' strictEqual(wasmExports.localMutF64, 3.141592653589793);' ,
159
162
160
163
// Test modifying local mutable externref
161
- 'const anotherTestObj = { another: "test object" };' ,
162
- 'wasmExports.setLocalMutExternref(anotherTestObj);' ,
163
- 'strictEqual(wasmExports.getLocalMutExternref(), anotherTestObj);' ,
164
- 'strictEqual(wasmExports.localMutExternref, null);' ,
164
+ ' const anotherTestObj = { another: "test object" };' ,
165
+ ' wasmExports.setLocalMutExternref(anotherTestObj);' ,
166
+ ' strictEqual(wasmExports.getLocalMutExternref(), anotherTestObj);' ,
167
+ ' strictEqual(wasmExports.localMutExternref, null);' ,
165
168
166
169
// Test dep.wasm imports
167
- 'strictEqual(wasmExports.depI32, 1001);' ,
168
- 'strictEqual(wasmExports.depMutI32, 2001);' ,
169
- 'strictEqual(wasmExports.getDepMutI32(), 2001);' ,
170
- 'strictEqual(wasmExports.depI64, 10000000001n);' ,
171
- 'strictEqual(wasmExports.depMutI64, 20000000001n);' ,
172
- 'strictEqual(wasmExports.getDepMutI64(), 20000000001n);' ,
173
- 'strictEqual(Math.round(wasmExports.depF32 * 100) / 100, 10.01);' ,
174
- 'strictEqual(Math.round(wasmExports.depMutF32 * 100) / 100, 20.01);' ,
175
- 'strictEqual(Math.round(wasmExports.getDepMutF32() * 100) / 100, 20.01);' ,
176
- 'strictEqual(wasmExports.depF64, 100.0001);' ,
177
- 'strictEqual(wasmExports.depMutF64, 200.0001);' ,
178
- 'strictEqual(wasmExports.getDepMutF64(), 200.0001);' ,
170
+ ' strictEqual(wasmExports.depI32, 1001);' ,
171
+ ' strictEqual(wasmExports.depMutI32, 2001);' ,
172
+ ' strictEqual(wasmExports.getDepMutI32(), 2001);' ,
173
+ ' strictEqual(wasmExports.depI64, 10000000001n);' ,
174
+ ' strictEqual(wasmExports.depMutI64, 20000000001n);' ,
175
+ ' strictEqual(wasmExports.getDepMutI64(), 20000000001n);' ,
176
+ ' strictEqual(Math.round(wasmExports.depF32 * 100) / 100, 10.01);' ,
177
+ ' strictEqual(Math.round(wasmExports.depMutF32 * 100) / 100, 20.01);' ,
178
+ ' strictEqual(Math.round(wasmExports.getDepMutF32() * 100) / 100, 20.01);' ,
179
+ ' strictEqual(wasmExports.depF64, 100.0001);' ,
180
+ ' strictEqual(wasmExports.depMutF64, 200.0001);' ,
181
+ ' strictEqual(wasmExports.getDepMutF64(), 200.0001);' ,
179
182
180
183
// Test modifying dep.wasm mutable globals
181
- 'wasmExports.setDepMutI32(3001);' ,
182
- 'strictEqual(wasmExports.getDepMutI32(), 3001);' ,
184
+ ' wasmExports.setDepMutI32(3001);' ,
185
+ ' strictEqual(wasmExports.getDepMutI32(), 3001);' ,
183
186
184
- 'wasmExports.setDepMutI64(30000000001n);' ,
185
- 'strictEqual(wasmExports.getDepMutI64(), 30000000001n);' ,
187
+ ' wasmExports.setDepMutI64(30000000001n);' ,
188
+ ' strictEqual(wasmExports.getDepMutI64(), 30000000001n);' ,
186
189
187
- 'wasmExports.setDepMutF32(30.01);' ,
188
- 'strictEqual(Math.round(wasmExports.getDepMutF32() * 100) / 100, 30.01);' ,
190
+ ' wasmExports.setDepMutF32(30.01);' ,
191
+ ' strictEqual(Math.round(wasmExports.getDepMutF32() * 100) / 100, 30.01);' ,
189
192
190
- 'wasmExports.setDepMutF64(300.0001);' ,
191
- 'strictEqual(wasmExports.getDepMutF64(), 300.0001);' ,
193
+ ' wasmExports.setDepMutF64(300.0001);' ,
194
+ ' strictEqual(wasmExports.getDepMutF64(), 300.0001);' ,
192
195
193
196
// These pending live bindings support
194
- 'strictEqual(wasmExports.depMutI32, 2001);' ,
195
- 'strictEqual(wasmExports.depMutI64, 20000000001n);' ,
196
- 'strictEqual(Math.round(wasmExports.depMutF32 * 100) / 100, 20.01);' ,
197
- 'strictEqual(wasmExports.depMutF64, 200.0001);' ,
197
+ ' strictEqual(wasmExports.depMutI32, 2001);' ,
198
+ ' strictEqual(wasmExports.depMutI64, 20000000001n);' ,
199
+ ' strictEqual(Math.round(wasmExports.depMutF32 * 100) / 100, 20.01);' ,
200
+ ' strictEqual(wasmExports.depMutF64, 200.0001);' ,
201
+
202
+ '}' ,
198
203
] . join ( '\n' ) ,
199
204
] ) ;
200
205
0 commit comments