-
Notifications
You must be signed in to change notification settings - Fork 5
/
WasmLoadUtils.ts
44 lines (39 loc) · 1.29 KB
/
WasmLoadUtils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* Copyright (c) Microblink Ltd. All rights reserved.
*/
import * as WasmFeatureDetect from "wasm-feature-detect";
import { WasmType } from "./WasmType";
export async function detectWasmType(): Promise< WasmType >
{
// determine if all features required for advanced WASM are available
// currently, advanced wasm requires bulk memory, non-trapping floating point
// and sign extension (this may change in the future).
const haveBulkMemory = await WasmFeatureDetect.bulkMemory();
const haveNonTrappingFloatingPoint = await WasmFeatureDetect.saturatedFloatToInt();
const haveSignExtension = await WasmFeatureDetect.signExtensions();
const haveThreads = await WasmFeatureDetect.threads();
if ( haveBulkMemory && haveNonTrappingFloatingPoint && haveSignExtension )
{
if ( haveThreads )
{
return WasmType.AdvancedWithThreads;
}
else
{
return WasmType.Advanced;
}
}
else
{
return WasmType.Basic;
}
}
export function wasmFolder( wasmType: WasmType ): string
{
switch( wasmType )
{
case WasmType.AdvancedWithThreads: return "advanced-threads";
case WasmType.Advanced : return "advanced";
case WasmType.Basic : return "basic";
}
}