@@ -21,25 +21,18 @@ module.exports.createActionlint = async function createActionlint(loader) {
21
21
// able to call the `runActionlint` function.
22
22
go . run ( wasm . instance ) ;
23
23
24
- if ( ! ( wasm . instance . exports . memory instanceof WebAssembly . Memory ) ) {
25
- throw new Error ( "Could not get wasm memory" ) ;
26
- }
27
- const memory = wasm . instance . exports . memory ;
28
-
29
- if ( ! ( wasm . instance . exports . WasmAlloc instanceof Function ) ) {
30
- throw new Error ( "Could not get wasm alloc function" ) ;
31
- }
32
- const wasmAlloc = wasm . instance . exports . WasmAlloc ;
24
+ const { memory, WasmAlloc, WasmFree, RunActionlint } = wasm . instance . exports ;
33
25
34
- if ( ! ( wasm . instance . exports . WasmFree instanceof Function ) ) {
35
- throw new Error ( "Could not get wasm free function" ) ;
36
- }
37
- const wasmFree = wasm . instance . exports . WasmFree ;
38
-
39
- if ( ! ( wasm . instance . exports . RunActionlint instanceof Function ) ) {
40
- throw new Error ( "Could not get wasm runActionLint function" ) ;
26
+ if (
27
+ ! ( memory instanceof WebAssembly . Memory ) ||
28
+ ! ( WasmAlloc instanceof Function ) ||
29
+ ! ( WasmFree instanceof Function ) ||
30
+ ! ( RunActionlint instanceof Function )
31
+ ) {
32
+ throw new Error (
33
+ "Invalid wasm exports. Expected memory, WasmAlloc, WasmFree, RunActionlint."
34
+ ) ;
41
35
}
42
- const runActionlint = wasm . instance . exports . RunActionlint ;
43
36
44
37
/**
45
38
* @param {string } input
@@ -50,13 +43,13 @@ module.exports.createActionlint = async function createActionlint(loader) {
50
43
const workflow = encoder . encode ( input ) ;
51
44
const filePath = encoder . encode ( path ) ;
52
45
53
- const workflowPointer = wasmAlloc ( workflow . byteLength ) ;
46
+ const workflowPointer = WasmAlloc ( workflow . byteLength ) ;
54
47
new Uint8Array ( memory . buffer ) . set ( workflow , workflowPointer ) ;
55
48
56
- const filePathPointer = wasmAlloc ( filePath . byteLength ) ;
49
+ const filePathPointer = WasmAlloc ( filePath . byteLength ) ;
57
50
new Uint8Array ( memory . buffer ) . set ( filePath , filePathPointer ) ;
58
51
59
- const resultPointer = runActionlint (
52
+ const resultPointer = RunActionlint (
60
53
workflowPointer ,
61
54
workflow . byteLength ,
62
55
workflow . byteLength ,
@@ -65,8 +58,8 @@ module.exports.createActionlint = async function createActionlint(loader) {
65
58
filePath . byteLength
66
59
) ;
67
60
68
- wasmFree ( workflowPointer ) ;
69
- wasmFree ( filePathPointer ) ;
61
+ WasmFree ( workflowPointer ) ;
62
+ WasmFree ( filePathPointer ) ;
70
63
71
64
const result = new Uint8Array ( memory . buffer ) . subarray ( resultPointer ) ;
72
65
const end = result . indexOf ( 0 ) ;
0 commit comments