1
- "use strict" ;
2
-
3
1
// Runtime header offsets
4
2
const ID_OFFSET = - 8 ;
5
3
const SIZE_OFFSET = - 4 ;
@@ -297,7 +295,7 @@ function isModule(src) {
297
295
}
298
296
299
297
/** Asynchronously instantiates an AssemblyScript module from anything that can be instantiated. */
300
- async function instantiate ( source , imports = { } ) {
298
+ export async function instantiate ( source , imports = { } ) {
301
299
if ( isResponse ( source = await source ) ) return instantiateStreaming ( source , imports ) ;
302
300
const module = isModule ( source ) ? source : await WebAssembly . compile ( source ) ;
303
301
const extended = preInstantiate ( imports ) ;
@@ -306,21 +304,17 @@ async function instantiate(source, imports = {}) {
306
304
return { module, instance, exports } ;
307
305
}
308
306
309
- exports . instantiate = instantiate ;
310
-
311
307
/** Synchronously instantiates an AssemblyScript module from a WebAssembly.Module or binary buffer. */
312
- function instantiateSync ( source , imports = { } ) {
308
+ export function instantiateSync ( source , imports = { } ) {
313
309
const module = isModule ( source ) ? source : new WebAssembly . Module ( source ) ;
314
310
const extended = preInstantiate ( imports ) ;
315
311
const instance = new WebAssembly . Instance ( module , imports ) ;
316
312
const exports = postInstantiate ( extended , instance ) ;
317
313
return { module, instance, exports } ;
318
314
}
319
315
320
- exports . instantiateSync = instantiateSync ;
321
-
322
316
/** Asynchronously instantiates an AssemblyScript module from a response, i.e. as obtained by `fetch`. */
323
- async function instantiateStreaming ( source , imports = { } ) {
317
+ export async function instantiateStreaming ( source , imports = { } ) {
324
318
if ( ! WebAssembly . instantiateStreaming ) {
325
319
return instantiate (
326
320
isResponse ( source = await source )
@@ -335,10 +329,8 @@ async function instantiateStreaming(source, imports = {}) {
335
329
return { ...result , exports } ;
336
330
}
337
331
338
- exports . instantiateStreaming = instantiateStreaming ;
339
-
340
332
/** Demangles an AssemblyScript module's exports to a friendly object structure. */
341
- function demangle ( exports , extendedExports = { } ) {
333
+ export function demangle ( exports , extendedExports = { } ) {
342
334
extendedExports = Object . create ( extendedExports ) ;
343
335
const setArgumentsLength = exports [ "__argumentsLength" ]
344
336
? length => { exports [ "__argumentsLength" ] . value = length ; }
@@ -420,4 +412,9 @@ function demangle(exports, extendedExports = {}) {
420
412
return extendedExports ;
421
413
}
422
414
423
- exports . demangle = demangle ;
415
+ export default {
416
+ instantiate,
417
+ instantiateSync,
418
+ instantiateStreaming,
419
+ demangle
420
+ } ;
0 commit comments