@gjsify/webassembly 0.3.13 → 0.3.14
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/lib/esm/index.js +45 -36
- package/lib/esm/register/promise.js +20 -23
- package/package.json +3 -3
package/lib/esm/index.js
CHANGED
|
@@ -1,54 +1,63 @@
|
|
|
1
|
+
//#region src/index.ts
|
|
1
2
|
const NATIVE_WEBASSEMBLY = globalThis.WebAssembly;
|
|
2
3
|
if (typeof NATIVE_WEBASSEMBLY === "undefined") {
|
|
3
|
-
|
|
4
|
+
throw new Error("@gjsify/webassembly: globalThis.WebAssembly is not defined; nothing to polyfill.");
|
|
4
5
|
}
|
|
5
6
|
const Module = NATIVE_WEBASSEMBLY.Module;
|
|
6
7
|
const Instance = NATIVE_WEBASSEMBLY.Instance;
|
|
8
|
+
/** Polyfill for `WebAssembly.compile()`. */
|
|
7
9
|
function compile(buffer) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
try {
|
|
11
|
+
return Promise.resolve(new Module(buffer));
|
|
12
|
+
} catch (err) {
|
|
13
|
+
return Promise.reject(err);
|
|
14
|
+
}
|
|
13
15
|
}
|
|
16
|
+
/** Polyfill for `WebAssembly.validate()`. */
|
|
14
17
|
function validate(buffer) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
try {
|
|
19
|
+
new Module(buffer);
|
|
20
|
+
return true;
|
|
21
|
+
} catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
21
24
|
}
|
|
22
25
|
function instantiate(bytesOrModule, importObject) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
try {
|
|
27
|
+
if (bytesOrModule instanceof Module) {
|
|
28
|
+
return Promise.resolve(new Instance(bytesOrModule, importObject));
|
|
29
|
+
}
|
|
30
|
+
const module = new Module(bytesOrModule);
|
|
31
|
+
const instance = new Instance(module, importObject);
|
|
32
|
+
return Promise.resolve({
|
|
33
|
+
module,
|
|
34
|
+
instance
|
|
35
|
+
});
|
|
36
|
+
} catch (err) {
|
|
37
|
+
return Promise.reject(err);
|
|
38
|
+
}
|
|
33
39
|
}
|
|
34
40
|
async function bufferFromSource(source) {
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
const response = await source;
|
|
42
|
+
return response.arrayBuffer();
|
|
37
43
|
}
|
|
44
|
+
/** Polyfill for `WebAssembly.compileStreaming()`. */
|
|
38
45
|
async function compileStreaming(source) {
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
const buffer = await bufferFromSource(source);
|
|
47
|
+
return compile(buffer);
|
|
41
48
|
}
|
|
49
|
+
/** Polyfill for `WebAssembly.instantiateStreaming()`. */
|
|
42
50
|
async function instantiateStreaming(source, importObject) {
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
const buffer = await bufferFromSource(source);
|
|
52
|
+
return instantiate(buffer, importObject);
|
|
45
53
|
}
|
|
46
|
-
var
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
instantiateStreaming,
|
|
53
|
-
validate
|
|
54
|
+
var src_default = {
|
|
55
|
+
compile,
|
|
56
|
+
compileStreaming,
|
|
57
|
+
instantiate,
|
|
58
|
+
instantiateStreaming,
|
|
59
|
+
validate
|
|
54
60
|
};
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { compile, compileStreaming, src_default as default, instantiate, instantiateStreaming, validate };
|
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
instantiate,
|
|
5
|
-
instantiateStreaming,
|
|
6
|
-
validate
|
|
7
|
-
} from "../index.js";
|
|
1
|
+
import { compile, compileStreaming, instantiate, instantiateStreaming, validate } from "../index.js";
|
|
2
|
+
|
|
3
|
+
//#region src/register/promise.ts
|
|
8
4
|
const wa = globalThis.WebAssembly;
|
|
9
5
|
if (typeof wa !== "undefined") {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
replace("validate", validate);
|
|
6
|
+
const replace = (name, value) => {
|
|
7
|
+
try {
|
|
8
|
+
Object.defineProperty(wa, name, {
|
|
9
|
+
value,
|
|
10
|
+
writable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
} catch {}
|
|
15
|
+
};
|
|
16
|
+
replace("compile", compile);
|
|
17
|
+
replace("compileStreaming", compileStreaming);
|
|
18
|
+
replace("instantiate", instantiate);
|
|
19
|
+
replace("instantiateStreaming", instantiateStreaming);
|
|
20
|
+
replace("validate", validate);
|
|
26
21
|
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/webassembly",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.14",
|
|
4
4
|
"description": "WebAssembly Promise-API polyfill for GJS — wraps the synchronous Module/Instance constructors that work in SpiderMonkey 128+.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"polyfill"
|
|
46
46
|
],
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@gjsify/cli": "^0.3.
|
|
49
|
-
"@gjsify/unit": "^0.3.
|
|
48
|
+
"@gjsify/cli": "^0.3.14",
|
|
49
|
+
"@gjsify/unit": "^0.3.14",
|
|
50
50
|
"@types/node": "^25.6.0",
|
|
51
51
|
"typescript": "^6.0.3"
|
|
52
52
|
}
|