@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 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
- throw new Error("@gjsify/webassembly: globalThis.WebAssembly is not defined; nothing to polyfill.");
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
- try {
9
- return Promise.resolve(new Module(buffer));
10
- } catch (err) {
11
- return Promise.reject(err);
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
- try {
16
- new Module(buffer);
17
- return true;
18
- } catch {
19
- return false;
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
- try {
24
- if (bytesOrModule instanceof Module) {
25
- return Promise.resolve(new Instance(bytesOrModule, importObject));
26
- }
27
- const module = new Module(bytesOrModule);
28
- const instance = new Instance(module, importObject);
29
- return Promise.resolve({ module, instance });
30
- } catch (err) {
31
- return Promise.reject(err);
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
- const response = await source;
36
- return response.arrayBuffer();
41
+ const response = await source;
42
+ return response.arrayBuffer();
37
43
  }
44
+ /** Polyfill for `WebAssembly.compileStreaming()`. */
38
45
  async function compileStreaming(source) {
39
- const buffer = await bufferFromSource(source);
40
- return compile(buffer);
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
- const buffer = await bufferFromSource(source);
44
- return instantiate(buffer, importObject);
51
+ const buffer = await bufferFromSource(source);
52
+ return instantiate(buffer, importObject);
45
53
  }
46
- var index_default = { compile, compileStreaming, instantiate, instantiateStreaming, validate };
47
- export {
48
- compile,
49
- compileStreaming,
50
- index_default as default,
51
- instantiate,
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
- compile,
3
- compileStreaming,
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
- const replace = (name, value) => {
11
- try {
12
- Object.defineProperty(wa, name, {
13
- value,
14
- writable: true,
15
- configurable: true,
16
- enumerable: true
17
- });
18
- } catch {
19
- }
20
- };
21
- replace("compile", compile);
22
- replace("compileStreaming", compileStreaming);
23
- replace("instantiate", instantiate);
24
- replace("instantiateStreaming", instantiateStreaming);
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.13",
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.13",
49
- "@gjsify/unit": "^0.3.13",
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
  }