@@ -11,47 +11,40 @@ import { supplyDefaultFunction } from "../utils/index.js";
11
11
import { parseImportFunctionInfo } from "../utils/wasmparser.js" ;
12
12
const readFile = promises . readFile ;
13
13
14
- function nodeExecutor ( wasms : string [ ] , outFolder : string , imports : Imports ) {
15
- return Promise . all (
16
- wasms . map ( async ( wasm ) => {
17
- const wasi = new WASI ( {
18
- args : [ "node" , basename ( wasm ) ] ,
19
- env : process . env ,
20
- preopens : {
21
- "/" : outFolder ,
22
- } ,
23
- version : "preview1" ,
24
- } ) ;
14
+ async function nodeExecutor ( wasm : string , outFolder : string , imports : Imports ) {
15
+ const wasi = new WASI ( {
16
+ args : [ "node" , basename ( wasm ) ] ,
17
+ env : process . env ,
18
+ preopens : {
19
+ "/" : outFolder ,
20
+ } ,
21
+ version : "preview1" ,
22
+ } ) ;
25
23
26
- const importsArg = new ImportsArgument ( ) ;
27
- const userDefinedImportsObject = imports === null ? { } : imports ( importsArg ) ;
28
- const importObject : ASImports = {
29
- wasi_snapshot_preview1 : wasi . wasiImport ,
30
- mockInstrument : mockInstruFunc ,
31
- ...covInstruFunc ( wasm ) ,
32
- ...userDefinedImportsObject ,
33
- } as ASImports ;
34
- const binaryBuffer = await readFile ( wasm ) ;
35
- const binary = binaryBuffer . buffer . slice (
36
- binaryBuffer . byteOffset ,
37
- binaryBuffer . byteOffset + binaryBuffer . byteLength
38
- ) ;
39
- const importFuncList = parseImportFunctionInfo ( binary as ArrayBuffer ) ;
40
- supplyDefaultFunction ( importFuncList , importObject ) ;
41
- const ins = await instantiate ( binary , importObject ) ;
42
- importsArg . module = ins . module ;
43
- importsArg . instance = ins . instance ;
44
- importsArg . exports = ins . exports ;
45
- try {
46
- wasi . start ( ins ) ;
47
- } catch ( error ) {
48
- if ( error instanceof Error ) {
49
- console . error ( error . stack ) ;
50
- }
51
- throw new Error ( "node executor abort." ) ;
52
- }
53
- } )
54
- ) ;
24
+ const importsArg = new ImportsArgument ( ) ;
25
+ const userDefinedImportsObject = imports === null ? { } : imports ( importsArg ) ;
26
+ const importObject : ASImports = {
27
+ wasi_snapshot_preview1 : wasi . wasiImport ,
28
+ mockInstrument : mockInstruFunc ,
29
+ ...covInstruFunc ( wasm ) ,
30
+ ...userDefinedImportsObject ,
31
+ } as ASImports ;
32
+ const binaryBuffer = await readFile ( wasm ) ;
33
+ const binary = binaryBuffer . buffer . slice ( binaryBuffer . byteOffset , binaryBuffer . byteOffset + binaryBuffer . byteLength ) ;
34
+ const importFuncList = parseImportFunctionInfo ( binary as ArrayBuffer ) ;
35
+ supplyDefaultFunction ( importFuncList , importObject ) ;
36
+ const ins = await instantiate ( binary , importObject ) ;
37
+ importsArg . module = ins . module ;
38
+ importsArg . instance = ins . instance ;
39
+ importsArg . exports = ins . exports ;
40
+ try {
41
+ wasi . start ( ins ) ;
42
+ } catch ( error ) {
43
+ if ( error instanceof Error ) {
44
+ console . error ( error . stack ) ;
45
+ }
46
+ throw new Error ( "node executor abort." ) ;
47
+ }
55
48
}
56
49
57
50
export async function execWasmBinarys (
@@ -61,13 +54,9 @@ export async function execWasmBinarys(
61
54
) : Promise < AssertResult > {
62
55
const assertRes = new AssertResult ( ) ;
63
56
ensureDirSync ( outFolder ) ;
64
-
65
- const wasmPaths = instrumentResult . map ( ( res ) => res . instrumentedWasm ) ;
66
-
67
- await nodeExecutor ( wasmPaths , outFolder , imports ) ;
68
-
69
- await Promise . all (
70
- instrumentResult . map ( async ( res ) => {
57
+ await Promise . all < void > (
58
+ instrumentResult . map ( async ( res ) : Promise < void > => {
59
+ await nodeExecutor ( res . instrumentedWasm , outFolder , imports ) ;
71
60
const { instrumentedWasm, expectInfo } = res ;
72
61
const assertLogFilePath = join ( outFolder , basename ( instrumentedWasm ) . slice ( 0 , - 4 ) . concat ( "assert.log" ) ) ;
73
62
0 commit comments