@tybys/wasm-util 0.5.1 → 0.5.3

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/mjs/load.mjs CHANGED
@@ -5,50 +5,53 @@ function validateImports(imports) {
5
5
  throw new TypeError('imports must be an object or undefined');
6
6
  }
7
7
  }
8
- async function fetchWasm(urlOrBuffer, imports) {
8
+ function fetchWasm(urlOrBuffer, imports) {
9
9
  if (typeof wx !== 'undefined' && typeof __wxConfig !== 'undefined') {
10
- return await _WebAssembly.instantiate(urlOrBuffer, imports);
10
+ return _WebAssembly.instantiate(urlOrBuffer, imports);
11
11
  }
12
- const response = await fetch(urlOrBuffer);
13
- const buffer = await response.arrayBuffer();
14
- const source = await _WebAssembly.instantiate(buffer, imports);
15
- return source;
12
+ return fetch(urlOrBuffer)
13
+ .then(response => response.arrayBuffer())
14
+ .then(buffer => _WebAssembly.instantiate(buffer, imports));
16
15
  }
17
16
  /** @public */
18
- export async function load(urlOrBuffer, imports) {
17
+ export function load(urlOrBuffer, imports) {
19
18
  validateImports(imports);
20
19
  imports = imports !== null && imports !== void 0 ? imports : {};
21
20
  let source;
22
21
  if (urlOrBuffer instanceof ArrayBuffer || ArrayBuffer.isView(urlOrBuffer)) {
23
- source = await _WebAssembly.instantiate(urlOrBuffer, imports);
24
- return source;
22
+ return _WebAssembly.instantiate(urlOrBuffer, imports);
25
23
  }
26
24
  if (typeof urlOrBuffer !== 'string' && !(urlOrBuffer instanceof URL)) {
27
25
  throw new TypeError('Invalid source');
28
26
  }
29
27
  if (typeof _WebAssembly.instantiateStreaming === 'function') {
28
+ let responsePromise;
30
29
  try {
31
- source = await _WebAssembly.instantiateStreaming(fetch(urlOrBuffer), imports);
30
+ responsePromise = fetch(urlOrBuffer);
31
+ source = _WebAssembly.instantiateStreaming(responsePromise, imports).catch(() => {
32
+ return fetchWasm(urlOrBuffer, imports);
33
+ });
32
34
  }
33
35
  catch (_) {
34
- source = await fetchWasm(urlOrBuffer, imports);
36
+ source = fetchWasm(urlOrBuffer, imports);
35
37
  }
36
38
  }
37
39
  else {
38
- source = await fetchWasm(urlOrBuffer, imports);
40
+ source = fetchWasm(urlOrBuffer, imports);
39
41
  }
40
42
  return source;
41
43
  }
42
44
  /** @public */
43
- export async function asyncifyLoad(asyncify, urlOrBuffer, imports) {
44
- var _a;
45
+ export function asyncifyLoad(asyncify, urlOrBuffer, imports) {
45
46
  validateImports(imports);
46
47
  imports = imports !== null && imports !== void 0 ? imports : {};
47
48
  const asyncifyHelper = new Asyncify();
48
49
  imports = asyncifyHelper.wrapImports(imports);
49
- const source = await load(urlOrBuffer, imports);
50
- const memory = source.instance.exports.memory || ((_a = imports.env) === null || _a === void 0 ? void 0 : _a.memory);
51
- return { module: source.module, instance: asyncifyHelper.init(memory, source.instance, asyncify) };
50
+ return load(urlOrBuffer, imports).then(source => {
51
+ var _a;
52
+ const memory = source.instance.exports.memory || ((_a = imports.env) === null || _a === void 0 ? void 0 : _a.memory);
53
+ return { module: source.module, instance: asyncifyHelper.init(memory, source.instance, asyncify) };
54
+ });
52
55
  }
53
56
  /** @public */
54
57
  export function loadSync(buffer, imports) {
@@ -1,6 +1,6 @@
1
1
  import { _WebAssembly } from "./webassembly.mjs";
2
2
  /** @public */
3
- export const WebAssemblyMemory = /*#__PURE__*/ _WebAssembly.Memory;
3
+ export const WebAssemblyMemory = /*#__PURE__*/ (function () { return _WebAssembly.Memory; })();
4
4
  /** @public */
5
5
  export class Memory extends WebAssemblyMemory {
6
6
  // eslint-disable-next-line @typescript-eslint/no-useless-constructor
@@ -114,8 +114,10 @@ async function resolvePathAsync(fs, fileDescriptor, path, flags) {
114
114
  }
115
115
  return resolvedPath;
116
116
  }
117
- const encoder = new TextEncoder();
118
- const decoder = new TextDecoder();
117
+ // eslint-disable-next-line spaced-comment
118
+ const encoder = /*#__PURE__*/ new TextEncoder();
119
+ // eslint-disable-next-line spaced-comment
120
+ const decoder = /*#__PURE__*/ new TextDecoder();
119
121
  function readStdin() {
120
122
  const value = window.prompt();
121
123
  if (value === null)
@@ -90,36 +90,36 @@ export var WasiFileType;
90
90
  WasiFileType[WasiFileType["SOCKET_STREAM"] = 6] = "SOCKET_STREAM";
91
91
  WasiFileType[WasiFileType["SYMBOLIC_LINK"] = 7] = "SYMBOLIC_LINK";
92
92
  })(WasiFileType || (WasiFileType = {}));
93
- const FD_DATASYNC = /*#__PURE__*/ (BigInt(1) << BigInt(0));
94
- const FD_READ = /*#__PURE__*/ (BigInt(1) << BigInt(1));
95
- const FD_SEEK = /*#__PURE__*/ (BigInt(1) << BigInt(2));
96
- const FD_FDSTAT_SET_FLAGS = /*#__PURE__*/ (BigInt(1) << BigInt(3));
97
- const FD_SYNC = /*#__PURE__*/ (BigInt(1) << BigInt(4));
98
- const FD_TELL = /*#__PURE__*/ (BigInt(1) << BigInt(5));
99
- const FD_WRITE = /*#__PURE__*/ (BigInt(1) << BigInt(6));
100
- const FD_ADVISE = /*#__PURE__*/ (BigInt(1) << BigInt(7));
101
- const FD_ALLOCATE = /*#__PURE__*/ (BigInt(1) << BigInt(8));
102
- const PATH_CREATE_DIRECTORY = /*#__PURE__*/ (BigInt(1) << BigInt(9));
103
- const PATH_CREATE_FILE = /*#__PURE__*/ (BigInt(1) << BigInt(10));
104
- const PATH_LINK_SOURCE = /*#__PURE__*/ (BigInt(1) << BigInt(11));
105
- const PATH_LINK_TARGET = /*#__PURE__*/ (BigInt(1) << BigInt(12));
106
- const PATH_OPEN = /*#__PURE__*/ (BigInt(1) << BigInt(13));
107
- const FD_READDIR = /*#__PURE__*/ (BigInt(1) << BigInt(14));
108
- const PATH_READLINK = /*#__PURE__*/ (BigInt(1) << BigInt(15));
109
- const PATH_RENAME_SOURCE = /*#__PURE__*/ (BigInt(1) << BigInt(16));
110
- const PATH_RENAME_TARGET = /*#__PURE__*/ (BigInt(1) << BigInt(17));
111
- const PATH_FILESTAT_GET = /*#__PURE__*/ (BigInt(1) << BigInt(18));
112
- const PATH_FILESTAT_SET_SIZE = /*#__PURE__*/ (BigInt(1) << BigInt(19));
113
- const PATH_FILESTAT_SET_TIMES = /*#__PURE__*/ (BigInt(1) << BigInt(20));
114
- const FD_FILESTAT_GET = /*#__PURE__*/ (BigInt(1) << BigInt(21));
115
- const FD_FILESTAT_SET_SIZE = /*#__PURE__*/ (BigInt(1) << BigInt(22));
116
- const FD_FILESTAT_SET_TIMES = /*#__PURE__*/ (BigInt(1) << BigInt(23));
117
- const PATH_SYMLINK = /*#__PURE__*/ (BigInt(1) << BigInt(24));
118
- const PATH_REMOVE_DIRECTORY = /*#__PURE__*/ (BigInt(1) << BigInt(25));
119
- const PATH_UNLINK_FILE = /*#__PURE__*/ (BigInt(1) << BigInt(26));
120
- const POLL_FD_READWRITE = /*#__PURE__*/ (BigInt(1) << BigInt(27));
121
- const SOCK_SHUTDOWN = /*#__PURE__*/ (BigInt(1) << BigInt(28));
122
- const SOCK_ACCEPT = /*#__PURE__*/ (BigInt(1) << BigInt(29));
93
+ const FD_DATASYNC = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(0));
94
+ const FD_READ = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(1));
95
+ const FD_SEEK = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(2));
96
+ const FD_FDSTAT_SET_FLAGS = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(3));
97
+ const FD_SYNC = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(4));
98
+ const FD_TELL = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(5));
99
+ const FD_WRITE = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(6));
100
+ const FD_ADVISE = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(7));
101
+ const FD_ALLOCATE = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(8));
102
+ const PATH_CREATE_DIRECTORY = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(9));
103
+ const PATH_CREATE_FILE = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(10));
104
+ const PATH_LINK_SOURCE = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(11));
105
+ const PATH_LINK_TARGET = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(12));
106
+ const PATH_OPEN = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(13));
107
+ const FD_READDIR = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(14));
108
+ const PATH_READLINK = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(15));
109
+ const PATH_RENAME_SOURCE = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(16));
110
+ const PATH_RENAME_TARGET = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(17));
111
+ const PATH_FILESTAT_GET = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(18));
112
+ const PATH_FILESTAT_SET_SIZE = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(19));
113
+ const PATH_FILESTAT_SET_TIMES = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(20));
114
+ const FD_FILESTAT_GET = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(21));
115
+ const FD_FILESTAT_SET_SIZE = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(22));
116
+ const FD_FILESTAT_SET_TIMES = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(23));
117
+ const PATH_SYMLINK = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(24));
118
+ const PATH_REMOVE_DIRECTORY = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(25));
119
+ const PATH_UNLINK_FILE = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(26));
120
+ const POLL_FD_READWRITE = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(27));
121
+ const SOCK_SHUTDOWN = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(28));
122
+ const SOCK_ACCEPT = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(29));
123
123
  export const WasiRights = {
124
124
  FD_DATASYNC,
125
125
  FD_READ,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tybys/wasm-util",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "description": "WASI polyfill for browser and some wasm util",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./dist/wasm-util.esm-bundler.js",
@@ -35,6 +35,9 @@
35
35
  },
36
36
  "author": "toyobayashi",
37
37
  "license": "MIT",
38
+ "dependencies": {
39
+ "tslib": "^2.4.0"
40
+ },
38
41
  "devDependencies": {
39
42
  "@tybys/ts-transform-module-specifier": "^0.0.2",
40
43
  "@tybys/ts-transform-pure-class": "^0.1.1",