-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3800954
commit 576fdb7
Showing
3 changed files
with
38 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,37 @@ | ||
// https://stackoverflow.com/a/47880734 | ||
const supported = (() => { | ||
try { | ||
if (typeof WebAssembly === "object" && typeof WebAssembly.instantiate === "function") { | ||
const module = new WebAssembly.Module( | ||
Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00), | ||
); | ||
if (module instanceof WebAssembly.Module) { | ||
return new WebAssembly.Instance(module) instanceof WebAssembly.Instance; | ||
} | ||
} | ||
} catch (e) {} | ||
return false; | ||
})(); | ||
|
||
import { __wbg_set_wasm } from "./bitwarden_wasm_internal_bg.js"; | ||
|
||
// In order to support a fallback strategy for web we need to conditionally load the wasm file | ||
export function init(wasm) { | ||
__wbg_set_wasm(wasm); | ||
let loaded_wasm; | ||
|
||
export async function init(wasm) { | ||
if (loaded_wasm) { | ||
return; | ||
} | ||
|
||
// If the caller provided a wasm module, use it for backwards compatibility. | ||
if (wasm) { | ||
loaded_wasm = wasm; | ||
} else if (supported) { | ||
loaded_wasm = await import("./bitwarden_wasm_internal_bg.wasm"); | ||
} else { | ||
loaded_wasm = await import("./bitwarden_wasm_internal_bg.wasm.js"); | ||
} | ||
|
||
__wbg_set_wasm(loaded_wasm); | ||
} | ||
|
||
export * from "./bitwarden_wasm_internal_bg.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from "./bitwarden_wasm_internal"; | ||
|
||
export function init(module?: any): Promise<void>; |