5
5
ObjectDefineProperties,
6
6
ObjectDefineProperty,
7
7
ObjectGetOwnPropertyDescriptor,
8
- PromiseResolve,
9
8
SafeMap,
10
9
SafeWeakMap,
11
10
StringPrototypeStartsWith,
@@ -26,9 +25,7 @@ const {
26
25
27
26
const { Buffer } = require ( 'buffer' ) ;
28
27
const {
29
- ERR_INVALID_ARG_TYPE ,
30
28
ERR_MANIFEST_ASSERT_INTEGRITY ,
31
- ERR_WEBASSEMBLY_RESPONSE ,
32
29
} = require ( 'internal/errors' ) . codes ;
33
30
const assert = require ( 'internal/assert' ) ;
34
31
@@ -222,49 +219,8 @@ function setupFetch() {
222
219
} ) ;
223
220
224
221
// The WebAssembly Web API: https://webassembly.github.io/spec/web-api
225
- internalBinding ( 'wasm_web_api' ) . setImplementation ( ( streamState , source ) => {
226
- ( async ( ) => {
227
- const response = await PromiseResolve ( source ) ;
228
- if ( ! ( response instanceof lazyUndici ( ) . Response ) ) {
229
- throw new ERR_INVALID_ARG_TYPE (
230
- 'source' , [ 'Response' , 'Promise resolving to Response' ] , response ) ;
231
- }
232
-
233
- const contentType = response . headers . get ( 'Content-Type' ) ;
234
- if ( contentType !== 'application/wasm' ) {
235
- throw new ERR_WEBASSEMBLY_RESPONSE (
236
- `has unsupported MIME type '${ contentType } '` ) ;
237
- }
238
-
239
- if ( ! response . ok ) {
240
- throw new ERR_WEBASSEMBLY_RESPONSE (
241
- `has status code ${ response . status } ` ) ;
242
- }
243
-
244
- if ( response . bodyUsed !== false ) {
245
- throw new ERR_WEBASSEMBLY_RESPONSE ( 'body has already been used' ) ;
246
- }
247
-
248
- if ( response . url ) {
249
- streamState . setURL ( response . url ) ;
250
- }
251
-
252
- // Pass all data from the response body to the WebAssembly compiler.
253
- const { body } = response ;
254
- if ( body != null ) {
255
- for await ( const chunk of body ) {
256
- streamState . push ( chunk ) ;
257
- }
258
- }
259
- } ) ( ) . then ( ( ) => {
260
- // No error occurred. Tell the implementation that the stream has ended.
261
- streamState . finish ( ) ;
262
- } , ( err ) => {
263
- // An error occurred, either because the given object was not a valid
264
- // and usable Response or because a network error occurred.
265
- streamState . abort ( err ) ;
266
- } ) ;
267
- } ) ;
222
+ const { wasmStreamingCallback } = require ( 'internal/wasm_web_api' ) ;
223
+ internalBinding ( 'wasm_web_api' ) . setImplementation ( wasmStreamingCallback ) ;
268
224
}
269
225
270
226
// TODO(aduh95): move this to internal/bootstrap/browser when the CLI flag is
0 commit comments