@tybys/wasm-util 0.6.0 → 0.8.0

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.
Files changed (41) hide show
  1. package/README.md +193 -193
  2. package/dist/tsdoc-metadata.json +1 -1
  3. package/dist/wasm-util.d.ts +13 -7
  4. package/dist/wasm-util.esm-bundler.js +2639 -2604
  5. package/dist/wasm-util.esm.js +2639 -2604
  6. package/dist/wasm-util.esm.min.js +1 -1
  7. package/dist/wasm-util.js +2639 -2603
  8. package/dist/wasm-util.min.js +1 -1
  9. package/lib/cjs/asyncify.js +157 -157
  10. package/lib/cjs/index.js +12 -12
  11. package/lib/cjs/jspi.js +45 -45
  12. package/lib/cjs/load.js +96 -85
  13. package/lib/cjs/memfs.js +2689 -0
  14. package/lib/cjs/memory.js +34 -34
  15. package/lib/cjs/wasi/error.js +102 -102
  16. package/lib/cjs/wasi/fd.js +267 -267
  17. package/lib/cjs/wasi/fs.js +2 -2
  18. package/lib/cjs/wasi/index.js +193 -168
  19. package/lib/cjs/wasi/path.js +173 -173
  20. package/lib/cjs/wasi/preview1.js +1478 -1478
  21. package/lib/cjs/wasi/rights.js +139 -139
  22. package/lib/cjs/wasi/types.js +219 -219
  23. package/lib/cjs/wasi/util.js +121 -121
  24. package/lib/cjs/webassembly.js +12 -12
  25. package/lib/mjs/asyncify.mjs +153 -153
  26. package/lib/mjs/index.mjs +9 -9
  27. package/lib/mjs/jspi.mjs +39 -39
  28. package/lib/mjs/load.mjs +89 -78
  29. package/lib/mjs/memfs.mjs +2688 -0
  30. package/lib/mjs/memory.mjs +28 -28
  31. package/lib/mjs/wasi/error.mjs +97 -97
  32. package/lib/mjs/wasi/fd.mjs +256 -256
  33. package/lib/mjs/wasi/fs.mjs +1 -1
  34. package/lib/mjs/wasi/index.mjs +188 -164
  35. package/lib/mjs/wasi/path.mjs +168 -168
  36. package/lib/mjs/wasi/preview1.mjs +1474 -1474
  37. package/lib/mjs/wasi/rights.mjs +134 -134
  38. package/lib/mjs/wasi/types.mjs +216 -216
  39. package/lib/mjs/wasi/util.mjs +108 -108
  40. package/lib/mjs/webassembly.mjs +9 -9
  41. package/package.json +58 -58
package/lib/cjs/jspi.js CHANGED
@@ -1,46 +1,46 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wrapExports = exports.wrapAsyncExport = exports.wrapAsyncImport = void 0;
4
- const util_1 = require("./wasi/util");
5
- const webassembly_1 = require("./webassembly");
6
- function checkWebAssemblyFunction() {
7
- const WebAssemblyFunction = webassembly_1._WebAssembly.Function;
8
- if (typeof WebAssemblyFunction !== 'function') {
9
- throw new Error('WebAssembly.Function is not supported in this environment.' +
10
- ' If you are using V8 based browser like Chrome, try to specify' +
11
- ' --js-flag="--wasm-staging --experimental-wasm-stack-switching"');
12
- }
13
- return WebAssemblyFunction;
14
- }
15
- /** @public */
16
- function wrapAsyncImport(f, parameterType, returnType) {
17
- const WebAssemblyFunction = checkWebAssemblyFunction();
18
- if (typeof f !== 'function') {
19
- throw new TypeError('Function required');
20
- }
21
- const parameters = parameterType.slice(0);
22
- parameters.unshift('externref');
23
- return new WebAssemblyFunction({ parameters, results: returnType }, f, { suspending: 'first' });
24
- }
25
- exports.wrapAsyncImport = wrapAsyncImport;
26
- /** @public */
27
- function wrapAsyncExport(f) {
28
- const WebAssemblyFunction = checkWebAssemblyFunction();
29
- if (typeof f !== 'function') {
30
- throw new TypeError('Function required');
31
- }
32
- return new WebAssemblyFunction({ parameters: [...WebAssemblyFunction.type(f).parameters.slice(1)], results: ['externref'] }, f, { promising: 'first' });
33
- }
34
- exports.wrapAsyncExport = wrapAsyncExport;
35
- /** @public */
36
- function wrapExports(exports, needWrap) {
37
- return (0, util_1.wrapInstanceExports)(exports, (exportValue, name) => {
38
- let ignore = typeof exportValue !== 'function';
39
- if (Array.isArray(needWrap)) {
40
- ignore = ignore || (needWrap.indexOf(name) === -1);
41
- }
42
- return ignore ? exportValue : wrapAsyncExport(exportValue);
43
- });
44
- }
45
- exports.wrapExports = wrapExports;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.wrapExports = exports.wrapAsyncExport = exports.wrapAsyncImport = void 0;
4
+ const util_1 = require("./wasi/util");
5
+ const webassembly_1 = require("./webassembly");
6
+ function checkWebAssemblyFunction() {
7
+ const WebAssemblyFunction = webassembly_1._WebAssembly.Function;
8
+ if (typeof WebAssemblyFunction !== 'function') {
9
+ throw new Error('WebAssembly.Function is not supported in this environment.' +
10
+ ' If you are using V8 based browser like Chrome, try to specify' +
11
+ ' --js-flags="--wasm-staging --experimental-wasm-stack-switching"');
12
+ }
13
+ return WebAssemblyFunction;
14
+ }
15
+ /** @public */
16
+ function wrapAsyncImport(f, parameterType, returnType) {
17
+ const WebAssemblyFunction = checkWebAssemblyFunction();
18
+ if (typeof f !== 'function') {
19
+ throw new TypeError('Function required');
20
+ }
21
+ const parameters = parameterType.slice(0);
22
+ parameters.unshift('externref');
23
+ return new WebAssemblyFunction({ parameters, results: returnType }, f, { suspending: 'first' });
24
+ }
25
+ exports.wrapAsyncImport = wrapAsyncImport;
26
+ /** @public */
27
+ function wrapAsyncExport(f) {
28
+ const WebAssemblyFunction = checkWebAssemblyFunction();
29
+ if (typeof f !== 'function') {
30
+ throw new TypeError('Function required');
31
+ }
32
+ return new WebAssemblyFunction({ parameters: [...WebAssemblyFunction.type(f).parameters.slice(1)], results: ['externref'] }, f, { promising: 'first' });
33
+ }
34
+ exports.wrapAsyncExport = wrapAsyncExport;
35
+ /** @public */
36
+ function wrapExports(exports, needWrap) {
37
+ return (0, util_1.wrapInstanceExports)(exports, (exportValue, name) => {
38
+ let ignore = typeof exportValue !== 'function';
39
+ if (Array.isArray(needWrap)) {
40
+ ignore = ignore || (needWrap.indexOf(name) === -1);
41
+ }
42
+ return ignore ? exportValue : wrapAsyncExport(exportValue);
43
+ });
44
+ }
45
+ exports.wrapExports = wrapExports;
46
46
  //# sourceMappingURL=jspi.js.map
package/lib/cjs/load.js CHANGED
@@ -1,86 +1,97 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.asyncifyLoadSync = exports.loadSync = exports.asyncifyLoad = exports.load = void 0;
4
- const webassembly_1 = require("./webassembly");
5
- const asyncify_1 = require("./asyncify");
6
- function validateImports(imports) {
7
- if (imports && typeof imports !== 'object') {
8
- throw new TypeError('imports must be an object or undefined');
9
- }
10
- }
11
- function fetchWasm(urlOrBuffer, imports) {
12
- if (typeof wx !== 'undefined' && typeof __wxConfig !== 'undefined') {
13
- return webassembly_1._WebAssembly.instantiate(urlOrBuffer, imports);
14
- }
15
- return fetch(urlOrBuffer)
16
- .then(response => response.arrayBuffer())
17
- .then(buffer => webassembly_1._WebAssembly.instantiate(buffer, imports));
18
- }
19
- /** @public */
20
- function load(urlOrBuffer, imports) {
21
- validateImports(imports);
22
- imports = imports !== null && imports !== void 0 ? imports : {};
23
- let source;
24
- if (urlOrBuffer instanceof ArrayBuffer || ArrayBuffer.isView(urlOrBuffer)) {
25
- return webassembly_1._WebAssembly.instantiate(urlOrBuffer, imports);
26
- }
27
- if (typeof urlOrBuffer !== 'string' && !(urlOrBuffer instanceof URL)) {
28
- throw new TypeError('Invalid source');
29
- }
30
- if (typeof webassembly_1._WebAssembly.instantiateStreaming === 'function') {
31
- let responsePromise;
32
- try {
33
- responsePromise = fetch(urlOrBuffer);
34
- source = webassembly_1._WebAssembly.instantiateStreaming(responsePromise, imports).catch(() => {
35
- return fetchWasm(urlOrBuffer, imports);
36
- });
37
- }
38
- catch (_) {
39
- source = fetchWasm(urlOrBuffer, imports);
40
- }
41
- }
42
- else {
43
- source = fetchWasm(urlOrBuffer, imports);
44
- }
45
- return source;
46
- }
47
- exports.load = load;
48
- /** @public */
49
- function asyncifyLoad(asyncify, urlOrBuffer, imports) {
50
- validateImports(imports);
51
- imports = imports !== null && imports !== void 0 ? imports : {};
52
- const asyncifyHelper = new asyncify_1.Asyncify();
53
- imports = asyncifyHelper.wrapImports(imports);
54
- return load(urlOrBuffer, imports).then(source => {
55
- var _a;
56
- const memory = source.instance.exports.memory || ((_a = imports.env) === null || _a === void 0 ? void 0 : _a.memory);
57
- return { module: source.module, instance: asyncifyHelper.init(memory, source.instance, asyncify) };
58
- });
59
- }
60
- exports.asyncifyLoad = asyncifyLoad;
61
- /** @public */
62
- function loadSync(buffer, imports) {
63
- if ((buffer instanceof ArrayBuffer) && !ArrayBuffer.isView(buffer)) {
64
- throw new TypeError('Invalid source');
65
- }
66
- validateImports(imports);
67
- imports = imports !== null && imports !== void 0 ? imports : {};
68
- const module = new webassembly_1._WebAssembly.Module(buffer);
69
- const instance = new webassembly_1._WebAssembly.Instance(module, imports);
70
- const source = { instance, module };
71
- return source;
72
- }
73
- exports.loadSync = loadSync;
74
- /** @public */
75
- function asyncifyLoadSync(asyncify, buffer, imports) {
76
- var _a;
77
- validateImports(imports);
78
- imports = imports !== null && imports !== void 0 ? imports : {};
79
- const asyncifyHelper = new asyncify_1.Asyncify();
80
- imports = asyncifyHelper.wrapImports(imports);
81
- const source = loadSync(buffer, imports);
82
- const memory = source.instance.exports.memory || ((_a = imports.env) === null || _a === void 0 ? void 0 : _a.memory);
83
- return { module: source.module, instance: asyncifyHelper.init(memory, source.instance, asyncify) };
84
- }
85
- exports.asyncifyLoadSync = asyncifyLoadSync;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asyncifyLoadSync = exports.loadSync = exports.asyncifyLoad = exports.load = void 0;
4
+ const webassembly_1 = require("./webassembly");
5
+ const asyncify_1 = require("./asyncify");
6
+ function validateImports(imports) {
7
+ if (imports && typeof imports !== 'object') {
8
+ throw new TypeError('imports must be an object or undefined');
9
+ }
10
+ }
11
+ function fetchWasm(urlOrBuffer, imports) {
12
+ if (typeof wx !== 'undefined' && typeof __wxConfig !== 'undefined') {
13
+ return webassembly_1._WebAssembly.instantiate(urlOrBuffer, imports);
14
+ }
15
+ return fetch(urlOrBuffer)
16
+ .then(response => response.arrayBuffer())
17
+ .then(buffer => webassembly_1._WebAssembly.instantiate(buffer, imports));
18
+ }
19
+ /** @public */
20
+ function load(wasmInput, imports) {
21
+ validateImports(imports);
22
+ imports = imports !== null && imports !== void 0 ? imports : {};
23
+ let source;
24
+ if (wasmInput instanceof ArrayBuffer || ArrayBuffer.isView(wasmInput)) {
25
+ return webassembly_1._WebAssembly.instantiate(wasmInput, imports);
26
+ }
27
+ if (wasmInput instanceof webassembly_1._WebAssembly.Module) {
28
+ return webassembly_1._WebAssembly.instantiate(wasmInput, imports).then((instance) => {
29
+ return { instance, module: wasmInput };
30
+ });
31
+ }
32
+ if (typeof wasmInput !== 'string' && !(wasmInput instanceof URL)) {
33
+ throw new TypeError('Invalid source');
34
+ }
35
+ if (typeof webassembly_1._WebAssembly.instantiateStreaming === 'function') {
36
+ let responsePromise;
37
+ try {
38
+ responsePromise = fetch(wasmInput);
39
+ source = webassembly_1._WebAssembly.instantiateStreaming(responsePromise, imports).catch(() => {
40
+ return fetchWasm(wasmInput, imports);
41
+ });
42
+ }
43
+ catch (_) {
44
+ source = fetchWasm(wasmInput, imports);
45
+ }
46
+ }
47
+ else {
48
+ source = fetchWasm(wasmInput, imports);
49
+ }
50
+ return source;
51
+ }
52
+ exports.load = load;
53
+ /** @public */
54
+ function asyncifyLoad(asyncify, urlOrBuffer, imports) {
55
+ validateImports(imports);
56
+ imports = imports !== null && imports !== void 0 ? imports : {};
57
+ const asyncifyHelper = new asyncify_1.Asyncify();
58
+ imports = asyncifyHelper.wrapImports(imports);
59
+ return load(urlOrBuffer, imports).then(source => {
60
+ var _a;
61
+ const memory = source.instance.exports.memory || ((_a = imports.env) === null || _a === void 0 ? void 0 : _a.memory);
62
+ return { module: source.module, instance: asyncifyHelper.init(memory, source.instance, asyncify) };
63
+ });
64
+ }
65
+ exports.asyncifyLoad = asyncifyLoad;
66
+ /** @public */
67
+ function loadSync(wasmInput, imports) {
68
+ validateImports(imports);
69
+ imports = imports !== null && imports !== void 0 ? imports : {};
70
+ let module;
71
+ if ((wasmInput instanceof ArrayBuffer) || ArrayBuffer.isView(wasmInput)) {
72
+ module = new webassembly_1._WebAssembly.Module(wasmInput);
73
+ }
74
+ else if (wasmInput instanceof WebAssembly.Module) {
75
+ module = wasmInput;
76
+ }
77
+ else {
78
+ throw new TypeError('Invalid source');
79
+ }
80
+ const instance = new webassembly_1._WebAssembly.Instance(module, imports);
81
+ const source = { instance, module };
82
+ return source;
83
+ }
84
+ exports.loadSync = loadSync;
85
+ /** @public */
86
+ function asyncifyLoadSync(asyncify, buffer, imports) {
87
+ var _a;
88
+ validateImports(imports);
89
+ imports = imports !== null && imports !== void 0 ? imports : {};
90
+ const asyncifyHelper = new asyncify_1.Asyncify();
91
+ imports = asyncifyHelper.wrapImports(imports);
92
+ const source = loadSync(buffer, imports);
93
+ const memory = source.instance.exports.memory || ((_a = imports.env) === null || _a === void 0 ? void 0 : _a.memory);
94
+ return { module: source.module, instance: asyncifyHelper.init(memory, source.instance, asyncify) };
95
+ }
96
+ exports.asyncifyLoadSync = asyncifyLoadSync;
86
97
  //# sourceMappingURL=load.js.map