File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,3 +10,5 @@ export * as extensions from './extensions';
1010export * as tools from './tools' ;
1111
1212export * as types from './types' ;
13+
14+ export * as wasm from './wasm' ;
Original file line number Diff line number Diff line change 1+ export * from './wasm-instance' ;
Original file line number Diff line number Diff line change 1+ import { EventEmitter } from '../core' ;
2+
3+ export type WasmInstanceEvents = 'instantiated' ;
4+
5+ /**
6+ * Events:
7+ * - instantiated: Emitted when the wasm instance is instantiated
8+ */
9+ class WasmInstance extends EventEmitter < WasmInstanceEvents > {
10+ #instance: WebAssembly . Instance | null = null ;
11+ #module: WebAssembly . Module | null = null ;
12+ #imports: WebAssembly . ModuleImportDescriptor [ ] | null = null ;
13+ #exports: WebAssembly . ModuleExportDescriptor [ ] | null = null ;
14+
15+ get instance ( ) {
16+ return this . #instance;
17+ }
18+
19+ get module ( ) {
20+ return this . #module;
21+ }
22+
23+ get imports ( ) {
24+ return this . #imports;
25+ }
26+
27+ get exports ( ) {
28+ return this . #exports;
29+ }
30+
31+ constructor ( ) {
32+ super ( ) ;
33+ WebAssembly . instantiateStreaming = new Proxy ( WebAssembly . instantiateStreaming , {
34+ apply : async ( target , thisArg , args ) => {
35+ const result = ( await Reflect . apply (
36+ target ,
37+ thisArg ,
38+ args ,
39+ ) ) as WebAssembly . WebAssemblyInstantiatedSource ;
40+
41+ this . #instance = result . instance ;
42+ this . #module = result . module ;
43+
44+ this . #imports = WebAssembly . Module . imports ( this . #module) ;
45+ this . #exports = WebAssembly . Module . exports ( this . #module) ;
46+
47+ this . emit ( 'instantiated' ) ;
48+
49+ return result ;
50+ } ,
51+ } ) ;
52+ }
53+ }
54+
55+ export const wasmInstance = new WasmInstance ( ) ;
You can’t perform that action at this time.
0 commit comments