Skip to content

Commit f02f0a5

Browse files
committed
lnc: extract wasm functions from LNC into WasmManager class
1 parent 63535a2 commit f02f0a5

File tree

6 files changed

+506
-387
lines changed

6 files changed

+506
-387
lines changed

lib/index.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,26 @@ describe('Index Module', () => {
4242
expect(typeof globalThis.WebAssembly?.instantiateStreaming).toBe(
4343
'function'
4444
);
45+
46+
// Call the polyfilled function and ensure it delegates to WebAssembly.instantiate
47+
const arrayBufferMock = vi.fn().mockResolvedValue(new ArrayBuffer(8));
48+
const response = Promise.resolve({
49+
arrayBuffer: arrayBufferMock
50+
} as unknown as Response);
51+
52+
const instantiateSpy = vi
53+
.spyOn(globalThis.WebAssembly, 'instantiate')
54+
.mockResolvedValue({
55+
exports: {}
56+
});
57+
58+
await globalThis.WebAssembly.instantiateStreaming?.(
59+
response as any,
60+
{ imports: true } as any
61+
);
62+
63+
expect(arrayBufferMock).toHaveBeenCalledTimes(1);
64+
expect(instantiateSpy).toHaveBeenCalledTimes(1);
4565
});
4666

4767
it('should use existing WebAssembly.instantiateStreaming when available', async () => {

lib/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require('./wasm_exec');
33

44
import LNC from './lnc';
5+
import { WasmManager } from './wasmManager';
56

67
// polyfill
78
if (!WebAssembly.instantiateStreaming) {
@@ -14,3 +15,4 @@ if (!WebAssembly.instantiateStreaming) {
1415
export type { LncConfig, CredentialStore } from './types/lnc';
1516
export * from '@lightninglabs/lnc-core';
1617
export default LNC;
18+
export { WasmManager };

0 commit comments

Comments
 (0)