File tree Expand file tree Collapse file tree 3 files changed +9
-24
lines changed Expand file tree Collapse file tree 3 files changed +9
-24
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,3 @@ export const __asbind_I32ArrayArray_ID = idof<Array<Array<i32>>>();
32
32
export const __asbind_I64ArrayArray_ID = idof < Array < Array < i64 > > > ( ) ;
33
33
export const __asbind_StringArrayArray_ID = idof < Array < Array < string > > > ( ) ;
34
34
export const __asbind_BoolArrayArray_ID = idof < Array < Array < bool > > > ( ) ;
35
-
36
- // As-Bind type data
37
- export const __asbind_type_data : string = "" ;
Original file line number Diff line number Diff line change @@ -20,19 +20,9 @@ function justSatisfyAllImportsLol() {
20
20
21
21
async function main ( ) {
22
22
const b = await fs . readFile ( process . argv [ 2 ] ) ;
23
- const { instance } = await WebAssembly . instantiate (
24
- b ,
25
- justSatisfyAllImportsLol ( )
26
- ) ;
27
- const ptr = instance . exports . __asbind_type_data . value ;
28
- const dv = new DataView ( instance . exports . memory . buffer ) ;
29
- const strLen = dv . getUint32 ( ptr - 4 , true ) ;
30
- const strView = new Uint16Array (
31
- instance . exports . memory . buffer ,
32
- ptr ,
33
- strLen / Uint16Array . BYTES_PER_ELEMENT
34
- ) ;
35
- const str = new TextDecoder ( "utf-16le" ) . decode ( strView ) ;
23
+ const module = await WebAssembly . compile ( b ) ;
24
+ const buffer = WebAssembly . Module . customSections ( module , "bindings" ) [ 0 ] ;
25
+ const str = new TextDecoder ( "utf8" ) . decode ( new Uint8Array ( buffer ) ) ;
36
26
console . log ( { str } ) ;
37
27
const data = JSON . parse ( str ) ;
38
28
console . log ( JSON . stringify ( data , null , 2 ) ) ;
Original file line number Diff line number Diff line change @@ -65,14 +65,12 @@ class AsBindTransform extends Transform {
65
65
] )
66
66
)
67
67
} ;
68
- const typeDataExport = [ ...program . elementsByDeclaration . values ( ) ] . find (
69
- v => v . name === MARKER
70
- ) ;
71
- if ( ! typeDataExport ) {
72
- throw Error ( "Could not find type data export" ) ;
73
- }
74
- typeDataExport . declaration . initializer = new assemblyscript . StringLiteralExpression (
75
- JSON . stringify ( typeData )
68
+ this . typeData = JSON . stringify ( typeData ) ;
69
+ }
70
+ afterCompile ( module ) {
71
+ module . addCustomSection (
72
+ "bindings" ,
73
+ new TextEncoder ( "utf8" ) . encode ( this . typeData )
76
74
) ;
77
75
}
78
76
}
You can’t perform that action at this time.
0 commit comments