strictjs-runtime 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +46 -40
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,53 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
// index.js
|
|
2
|
+
import initWASM, {
|
|
3
|
+
StrictNumber,
|
|
4
|
+
StrictString,
|
|
5
|
+
get_memory,
|
|
6
|
+
HeapType,
|
|
7
|
+
StrictArray,
|
|
8
|
+
StrictForLoop,
|
|
9
|
+
StrictFunction,
|
|
10
|
+
StrictObject,
|
|
11
|
+
Schema
|
|
12
|
+
} from "./pkg/strictjs_runtime.js";
|
|
8
13
|
|
|
9
14
|
let wasmInitialized = false;
|
|
10
15
|
|
|
11
|
-
|
|
12
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Initialize StrictJS Runtime.
|
|
18
|
+
* Works in both Node.js and Browser.
|
|
19
|
+
*/
|
|
20
|
+
export async function initStrict() {
|
|
21
|
+
if (wasmInitialized) return { StrictNumber, StrictString, get_memory, HeapType, StrictArray, StrictForLoop, StrictFunction, StrictObject, Schema };
|
|
22
|
+
|
|
13
23
|
// Node.js environment
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
await wasmModule.default(wasmBuffer);
|
|
24
|
-
wasmInitialized = true;
|
|
25
|
-
}
|
|
24
|
+
if (typeof window === "undefined") {
|
|
25
|
+
const fs = await import("fs");
|
|
26
|
+
const path = await import("path");
|
|
27
|
+
const url = await import("url");
|
|
28
|
+
|
|
29
|
+
const __filename = url.fileURLToPath(import.meta.url);
|
|
30
|
+
const __dirname = path.dirname(__filename);
|
|
31
|
+
const wasmPath = path.resolve(__dirname, "pkg/strictjs_runtime_bg.wasm");
|
|
32
|
+
const wasmBuffer = fs.readFileSync(wasmPath);
|
|
26
33
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
//
|
|
30
|
-
await
|
|
31
|
-
wasmInitialized = true;
|
|
34
|
+
await initWASM(wasmBuffer);
|
|
35
|
+
} else {
|
|
36
|
+
// Browser environment: fetch automatically
|
|
37
|
+
await initWASM();
|
|
32
38
|
}
|
|
33
39
|
|
|
40
|
+
wasmInitialized = true;
|
|
41
|
+
|
|
34
42
|
return {
|
|
35
|
-
StrictNumber
|
|
36
|
-
StrictString
|
|
37
|
-
get_memory
|
|
38
|
-
HeapType
|
|
39
|
-
StrictArray
|
|
40
|
-
StrictForLoop
|
|
41
|
-
StrictFunction
|
|
42
|
-
StrictObject
|
|
43
|
-
Schema
|
|
43
|
+
StrictNumber,
|
|
44
|
+
StrictString,
|
|
45
|
+
get_memory,
|
|
46
|
+
HeapType,
|
|
47
|
+
StrictArray,
|
|
48
|
+
StrictForLoop,
|
|
49
|
+
StrictFunction,
|
|
50
|
+
StrictObject,
|
|
51
|
+
Schema
|
|
44
52
|
};
|
|
45
53
|
}
|
|
46
54
|
|
|
47
|
-
//
|
|
48
|
-
export
|
|
49
|
-
StrictNumber,
|
|
50
|
-
StrictString,
|
|
55
|
+
// Re-export types for convenience
|
|
56
|
+
export {
|
|
51
57
|
get_memory,
|
|
52
58
|
HeapType,
|
|
53
59
|
StrictArray,
|
|
@@ -55,4 +61,4 @@ export const {
|
|
|
55
61
|
StrictFunction,
|
|
56
62
|
StrictObject,
|
|
57
63
|
Schema
|
|
58
|
-
}
|
|
64
|
+
};
|