@tailwindcss/oxide-wasm32-wasi 0.0.0-insiders.d801d8d
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/README.md +3 -0
- package/node_modules/@emnapi/core/LICENSE +21 -0
- package/node_modules/@emnapi/core/README.md +1 -0
- package/node_modules/@emnapi/core/dist/emnapi-core.cjs.js +6661 -0
- package/node_modules/@emnapi/core/dist/emnapi-core.cjs.min.d.ts +363 -0
- package/node_modules/@emnapi/core/dist/emnapi-core.cjs.min.js +1 -0
- package/node_modules/@emnapi/core/dist/emnapi-core.d.mts +363 -0
- package/node_modules/@emnapi/core/dist/emnapi-core.d.ts +365 -0
- package/node_modules/@emnapi/core/dist/emnapi-core.esm-bundler.js +7411 -0
- package/node_modules/@emnapi/core/dist/emnapi-core.js +8390 -0
- package/node_modules/@emnapi/core/dist/emnapi-core.min.d.mts +363 -0
- package/node_modules/@emnapi/core/dist/emnapi-core.min.js +1 -0
- package/node_modules/@emnapi/core/dist/emnapi-core.min.mjs +1 -0
- package/node_modules/@emnapi/core/dist/emnapi-core.mjs +6650 -0
- package/node_modules/@emnapi/core/index.js +5 -0
- package/node_modules/@emnapi/core/package.json +49 -0
- package/node_modules/@emnapi/runtime/LICENSE +21 -0
- package/node_modules/@emnapi/runtime/README.md +1 -0
- package/node_modules/@emnapi/runtime/dist/emnapi.cjs.js +1347 -0
- package/node_modules/@emnapi/runtime/dist/emnapi.cjs.min.d.ts +663 -0
- package/node_modules/@emnapi/runtime/dist/emnapi.cjs.min.js +1 -0
- package/node_modules/@emnapi/runtime/dist/emnapi.d.mts +663 -0
- package/node_modules/@emnapi/runtime/dist/emnapi.d.ts +665 -0
- package/node_modules/@emnapi/runtime/dist/emnapi.esm-bundler.js +1403 -0
- package/node_modules/@emnapi/runtime/dist/emnapi.iife.d.ts +420 -0
- package/node_modules/@emnapi/runtime/dist/emnapi.iife.js +1474 -0
- package/node_modules/@emnapi/runtime/dist/emnapi.js +1475 -0
- package/node_modules/@emnapi/runtime/dist/emnapi.min.d.mts +663 -0
- package/node_modules/@emnapi/runtime/dist/emnapi.min.js +1 -0
- package/node_modules/@emnapi/runtime/dist/emnapi.min.mjs +1 -0
- package/node_modules/@emnapi/runtime/dist/emnapi.mjs +1316 -0
- package/node_modules/@emnapi/runtime/index.js +5 -0
- package/node_modules/@emnapi/runtime/package.json +48 -0
- package/node_modules/@emnapi/wasi-threads/LICENSE +21 -0
- package/node_modules/@emnapi/wasi-threads/README.md +203 -0
- package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.js +881 -0
- package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.min.d.ts +214 -0
- package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.min.js +1 -0
- package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.mts +214 -0
- package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +216 -0
- package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.esm-bundler.js +929 -0
- package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +941 -0
- package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.d.mts +214 -0
- package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.js +1 -0
- package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.mjs +1 -0
- package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.mjs +876 -0
- package/node_modules/@emnapi/wasi-threads/index.js +5 -0
- package/node_modules/@emnapi/wasi-threads/package.json +50 -0
- package/node_modules/@napi-rs/wasm-runtime/LICENSE +43 -0
- package/node_modules/@napi-rs/wasm-runtime/dist/fs.js +23712 -0
- package/node_modules/@napi-rs/wasm-runtime/dist/runtime.js +12269 -0
- package/node_modules/@napi-rs/wasm-runtime/fs-proxy.cjs +193 -0
- package/node_modules/@napi-rs/wasm-runtime/package.json +60 -0
- package/node_modules/@napi-rs/wasm-runtime/runtime.cjs +15 -0
- package/node_modules/@tybys/wasm-util/README.md +193 -0
- package/node_modules/@tybys/wasm-util/dist/tsdoc-metadata.json +11 -0
- package/node_modules/@tybys/wasm-util/dist/wasm-util.d.ts +417 -0
- package/node_modules/@tybys/wasm-util/dist/wasm-util.esm-bundler.js +2738 -0
- package/node_modules/@tybys/wasm-util/dist/wasm-util.esm.js +2738 -0
- package/node_modules/@tybys/wasm-util/dist/wasm-util.esm.min.js +1 -0
- package/node_modules/@tybys/wasm-util/dist/wasm-util.js +2760 -0
- package/node_modules/@tybys/wasm-util/dist/wasm-util.min.js +1 -0
- package/node_modules/@tybys/wasm-util/lib/cjs/asyncify.js +158 -0
- package/node_modules/@tybys/wasm-util/lib/cjs/index.js +13 -0
- package/node_modules/@tybys/wasm-util/lib/cjs/jspi.js +46 -0
- package/node_modules/@tybys/wasm-util/lib/cjs/load.js +97 -0
- package/node_modules/@tybys/wasm-util/lib/cjs/memory.js +35 -0
- package/node_modules/@tybys/wasm-util/lib/cjs/wasi/error.js +103 -0
- package/node_modules/@tybys/wasm-util/lib/cjs/wasi/fd.js +268 -0
- package/node_modules/@tybys/wasm-util/lib/cjs/wasi/fs.js +3 -0
- package/node_modules/@tybys/wasm-util/lib/cjs/wasi/index.js +194 -0
- package/node_modules/@tybys/wasm-util/lib/cjs/wasi/path.js +174 -0
- package/node_modules/@tybys/wasm-util/lib/cjs/wasi/preview1.js +1544 -0
- package/node_modules/@tybys/wasm-util/lib/cjs/wasi/rights.js +141 -0
- package/node_modules/@tybys/wasm-util/lib/cjs/wasi/types.js +220 -0
- package/node_modules/@tybys/wasm-util/lib/cjs/wasi/util.js +128 -0
- package/node_modules/@tybys/wasm-util/lib/cjs/webassembly.js +13 -0
- package/node_modules/@tybys/wasm-util/lib/mjs/asyncify.mjs +153 -0
- package/node_modules/@tybys/wasm-util/lib/mjs/index.mjs +9 -0
- package/node_modules/@tybys/wasm-util/lib/mjs/jspi.mjs +39 -0
- package/node_modules/@tybys/wasm-util/lib/mjs/load.mjs +89 -0
- package/node_modules/@tybys/wasm-util/lib/mjs/memory.mjs +28 -0
- package/node_modules/@tybys/wasm-util/lib/mjs/wasi/error.mjs +97 -0
- package/node_modules/@tybys/wasm-util/lib/mjs/wasi/fd.mjs +256 -0
- package/node_modules/@tybys/wasm-util/lib/mjs/wasi/fs.mjs +1 -0
- package/node_modules/@tybys/wasm-util/lib/mjs/wasi/index.mjs +188 -0
- package/node_modules/@tybys/wasm-util/lib/mjs/wasi/path.mjs +168 -0
- package/node_modules/@tybys/wasm-util/lib/mjs/wasi/preview1.mjs +1539 -0
- package/node_modules/@tybys/wasm-util/lib/mjs/wasi/rights.mjs +135 -0
- package/node_modules/@tybys/wasm-util/lib/mjs/wasi/types.mjs +216 -0
- package/node_modules/@tybys/wasm-util/lib/mjs/wasi/util.mjs +113 -0
- package/node_modules/@tybys/wasm-util/lib/mjs/webassembly.mjs +9 -0
- package/node_modules/@tybys/wasm-util/package.json +58 -0
- package/node_modules/tslib/CopyrightNotice.txt +15 -0
- package/node_modules/tslib/LICENSE.txt +12 -0
- package/node_modules/tslib/README.md +164 -0
- package/node_modules/tslib/SECURITY.md +41 -0
- package/node_modules/tslib/modules/index.d.ts +38 -0
- package/node_modules/tslib/modules/index.js +70 -0
- package/node_modules/tslib/modules/package.json +3 -0
- package/node_modules/tslib/package.json +47 -0
- package/node_modules/tslib/tslib.d.ts +460 -0
- package/node_modules/tslib/tslib.es6.html +1 -0
- package/node_modules/tslib/tslib.es6.js +393 -0
- package/node_modules/tslib/tslib.es6.mjs +392 -0
- package/node_modules/tslib/tslib.html +1 -0
- package/node_modules/tslib/tslib.js +475 -0
- package/package.json +45 -0
- package/tailwindcss-oxide.wasi-browser.js +63 -0
- package/tailwindcss-oxide.wasi.cjs +88 -0
- package/tailwindcss-oxide.wasm32-wasi.wasm +0 -0
- package/wasi-worker-browser.mjs +39 -0
- package/wasi-worker.mjs +63 -0
|
@@ -0,0 +1,2738 @@
|
|
|
1
|
+
const _WebAssembly = typeof WebAssembly !== 'undefined'
|
|
2
|
+
? WebAssembly
|
|
3
|
+
: typeof WXWebAssembly !== 'undefined'
|
|
4
|
+
? WXWebAssembly
|
|
5
|
+
: undefined;
|
|
6
|
+
if (!_WebAssembly) {
|
|
7
|
+
throw new Error('WebAssembly is not supported in this environment');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/* eslint-disable spaced-comment */
|
|
11
|
+
|
|
12
|
+
function validateObject(value, name) {
|
|
13
|
+
if (value === null || typeof value !== 'object') {
|
|
14
|
+
throw new TypeError(`${name} must be an object. Received ${value === null ? 'null' : typeof value}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function validateArray(value, name) {
|
|
18
|
+
if (!Array.isArray(value)) {
|
|
19
|
+
throw new TypeError(`${name} must be an array. Received ${value === null ? 'null' : typeof value}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function validateBoolean(value, name) {
|
|
23
|
+
if (typeof value !== 'boolean') {
|
|
24
|
+
throw new TypeError(`${name} must be a boolean. Received ${value === null ? 'null' : typeof value}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function validateString(value, name) {
|
|
28
|
+
if (typeof value !== 'string') {
|
|
29
|
+
throw new TypeError(`${name} must be a string. Received ${value === null ? 'null' : typeof value}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function validateFunction(value, name) {
|
|
33
|
+
if (typeof value !== 'function') {
|
|
34
|
+
throw new TypeError(`${name} must be a function. Received ${value === null ? 'null' : typeof value}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function validateUndefined(value, name) {
|
|
38
|
+
if (value !== undefined) {
|
|
39
|
+
throw new TypeError(`${name} must be undefined. Received ${value === null ? 'null' : typeof value}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function isPromiseLike(obj) {
|
|
43
|
+
return !!(obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function');
|
|
44
|
+
}
|
|
45
|
+
function wrapInstanceExports(exports, mapFn) {
|
|
46
|
+
const newExports = Object.create(null);
|
|
47
|
+
Object.keys(exports).forEach(name => {
|
|
48
|
+
const exportValue = exports[name];
|
|
49
|
+
Object.defineProperty(newExports, name, {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
value: mapFn(exportValue, name)
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
return newExports;
|
|
55
|
+
}
|
|
56
|
+
function sleepBreakIf(delay, breakIf) {
|
|
57
|
+
const start = Date.now();
|
|
58
|
+
const end = start + delay;
|
|
59
|
+
let ret = false;
|
|
60
|
+
while (Date.now() < end) {
|
|
61
|
+
if (breakIf()) {
|
|
62
|
+
ret = true;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return ret;
|
|
67
|
+
}
|
|
68
|
+
function unsharedSlice(view, start, end) {
|
|
69
|
+
return ((typeof SharedArrayBuffer === 'function' && view.buffer instanceof SharedArrayBuffer) || (Object.prototype.toString.call(view.buffer.constructor) === '[object SharedArrayBuffer]'))
|
|
70
|
+
? view.slice(start, end)
|
|
71
|
+
: view.subarray(start, end);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const ignoreNames = [
|
|
75
|
+
'asyncify_get_state',
|
|
76
|
+
'asyncify_start_rewind',
|
|
77
|
+
'asyncify_start_unwind',
|
|
78
|
+
'asyncify_stop_rewind',
|
|
79
|
+
'asyncify_stop_unwind'
|
|
80
|
+
];
|
|
81
|
+
function tryAllocate(instance, wasm64, size, mallocName) {
|
|
82
|
+
if (typeof instance.exports[mallocName] !== 'function' || size <= 0) {
|
|
83
|
+
return {
|
|
84
|
+
wasm64,
|
|
85
|
+
dataPtr: 16,
|
|
86
|
+
start: wasm64 ? 32 : 24,
|
|
87
|
+
end: 1024
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const malloc = instance.exports[mallocName];
|
|
91
|
+
const dataPtr = wasm64 ? Number(malloc(BigInt(16) + BigInt(size))) : malloc(8 + size);
|
|
92
|
+
if (dataPtr === 0) {
|
|
93
|
+
throw new Error('Allocate asyncify data failed');
|
|
94
|
+
}
|
|
95
|
+
return wasm64
|
|
96
|
+
? { wasm64, dataPtr, start: dataPtr + 16, end: dataPtr + 16 + size }
|
|
97
|
+
: { wasm64, dataPtr, start: dataPtr + 8, end: dataPtr + 8 + size };
|
|
98
|
+
}
|
|
99
|
+
/** @public */
|
|
100
|
+
class Asyncify {
|
|
101
|
+
constructor() {
|
|
102
|
+
this.value = undefined;
|
|
103
|
+
this.exports = undefined;
|
|
104
|
+
this.dataPtr = 0;
|
|
105
|
+
}
|
|
106
|
+
init(memory, instance, options) {
|
|
107
|
+
var _a, _b;
|
|
108
|
+
if (this.exports) {
|
|
109
|
+
throw new Error('Asyncify has been initialized');
|
|
110
|
+
}
|
|
111
|
+
if (!(memory instanceof _WebAssembly.Memory)) {
|
|
112
|
+
throw new TypeError('Require WebAssembly.Memory object');
|
|
113
|
+
}
|
|
114
|
+
const exports = instance.exports;
|
|
115
|
+
for (let i = 0; i < ignoreNames.length; ++i) {
|
|
116
|
+
if (typeof exports[ignoreNames[i]] !== 'function') {
|
|
117
|
+
throw new TypeError('Invalid asyncify wasm');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
let address;
|
|
121
|
+
const wasm64 = Boolean(options.wasm64);
|
|
122
|
+
if (!options.tryAllocate) {
|
|
123
|
+
address = {
|
|
124
|
+
wasm64,
|
|
125
|
+
dataPtr: 16,
|
|
126
|
+
start: wasm64 ? 32 : 24,
|
|
127
|
+
end: 1024
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
if (options.tryAllocate === true) {
|
|
132
|
+
address = tryAllocate(instance, wasm64, 4096, 'malloc');
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
address = tryAllocate(instance, wasm64, (_a = options.tryAllocate.size) !== null && _a !== void 0 ? _a : 4096, (_b = options.tryAllocate.name) !== null && _b !== void 0 ? _b : 'malloc');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
this.dataPtr = address.dataPtr;
|
|
139
|
+
if (wasm64) {
|
|
140
|
+
new BigInt64Array(memory.buffer, this.dataPtr).set([BigInt(address.start), BigInt(address.end)]);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
new Int32Array(memory.buffer, this.dataPtr).set([address.start, address.end]);
|
|
144
|
+
}
|
|
145
|
+
this.exports = this.wrapExports(exports, options.wrapExports);
|
|
146
|
+
const asyncifiedInstance = Object.create(_WebAssembly.Instance.prototype);
|
|
147
|
+
Object.defineProperty(asyncifiedInstance, 'exports', { value: this.exports });
|
|
148
|
+
// Object.setPrototypeOf(instance, Instance.prototype)
|
|
149
|
+
return asyncifiedInstance;
|
|
150
|
+
}
|
|
151
|
+
assertState() {
|
|
152
|
+
if (this.exports.asyncify_get_state() !== 0 /* AsyncifyState.NONE */) {
|
|
153
|
+
throw new Error('Asyncify state error');
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
wrapImportFunction(f) {
|
|
157
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
158
|
+
const _this = this;
|
|
159
|
+
return (function () {
|
|
160
|
+
// eslint-disable-next-line no-unreachable-loop
|
|
161
|
+
while (_this.exports.asyncify_get_state() === 2 /* AsyncifyState.REWINDING */) {
|
|
162
|
+
_this.exports.asyncify_stop_rewind();
|
|
163
|
+
return _this.value;
|
|
164
|
+
}
|
|
165
|
+
_this.assertState();
|
|
166
|
+
const v = f.apply(this, arguments);
|
|
167
|
+
if (!isPromiseLike(v))
|
|
168
|
+
return v;
|
|
169
|
+
_this.exports.asyncify_start_unwind(_this.dataPtr);
|
|
170
|
+
_this.value = v;
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
wrapImports(imports) {
|
|
174
|
+
const importObject = {};
|
|
175
|
+
Object.keys(imports).forEach(k => {
|
|
176
|
+
const mod = imports[k];
|
|
177
|
+
const newModule = {};
|
|
178
|
+
Object.keys(mod).forEach(name => {
|
|
179
|
+
const importValue = mod[name];
|
|
180
|
+
if (typeof importValue === 'function') {
|
|
181
|
+
newModule[name] = this.wrapImportFunction(importValue);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
newModule[name] = importValue;
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
importObject[k] = newModule;
|
|
188
|
+
});
|
|
189
|
+
return importObject;
|
|
190
|
+
}
|
|
191
|
+
wrapExportFunction(f) {
|
|
192
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
193
|
+
const _this = this;
|
|
194
|
+
return (async function () {
|
|
195
|
+
_this.assertState();
|
|
196
|
+
let ret = f.apply(this, arguments);
|
|
197
|
+
while (_this.exports.asyncify_get_state() === 1 /* AsyncifyState.UNWINDING */) {
|
|
198
|
+
_this.exports.asyncify_stop_unwind();
|
|
199
|
+
_this.value = await _this.value;
|
|
200
|
+
_this.assertState();
|
|
201
|
+
_this.exports.asyncify_start_rewind(_this.dataPtr);
|
|
202
|
+
ret = f.call(this);
|
|
203
|
+
}
|
|
204
|
+
_this.assertState();
|
|
205
|
+
return ret;
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
wrapExports(exports, needWrap) {
|
|
209
|
+
return wrapInstanceExports(exports, (exportValue, name) => {
|
|
210
|
+
let ignore = ignoreNames.indexOf(name) !== -1 || typeof exportValue !== 'function';
|
|
211
|
+
if (Array.isArray(needWrap)) {
|
|
212
|
+
ignore = ignore || (needWrap.indexOf(name) === -1);
|
|
213
|
+
}
|
|
214
|
+
return ignore ? exportValue : this.wrapExportFunction(exportValue);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function validateImports(imports) {
|
|
220
|
+
if (imports && typeof imports !== 'object') {
|
|
221
|
+
throw new TypeError('imports must be an object or undefined');
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function fetchWasm(urlOrBuffer, imports) {
|
|
225
|
+
if (typeof wx !== 'undefined' && typeof __wxConfig !== 'undefined') {
|
|
226
|
+
return _WebAssembly.instantiate(urlOrBuffer, imports);
|
|
227
|
+
}
|
|
228
|
+
return fetch(urlOrBuffer)
|
|
229
|
+
.then(response => response.arrayBuffer())
|
|
230
|
+
.then(buffer => _WebAssembly.instantiate(buffer, imports));
|
|
231
|
+
}
|
|
232
|
+
/** @public */
|
|
233
|
+
function load(wasmInput, imports) {
|
|
234
|
+
validateImports(imports);
|
|
235
|
+
imports = imports !== null && imports !== void 0 ? imports : {};
|
|
236
|
+
let source;
|
|
237
|
+
if (wasmInput instanceof ArrayBuffer || ArrayBuffer.isView(wasmInput)) {
|
|
238
|
+
return _WebAssembly.instantiate(wasmInput, imports);
|
|
239
|
+
}
|
|
240
|
+
if (wasmInput instanceof _WebAssembly.Module) {
|
|
241
|
+
return _WebAssembly.instantiate(wasmInput, imports).then((instance) => {
|
|
242
|
+
return { instance, module: wasmInput };
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
if (typeof wasmInput !== 'string' && !(wasmInput instanceof URL)) {
|
|
246
|
+
throw new TypeError('Invalid source');
|
|
247
|
+
}
|
|
248
|
+
if (typeof _WebAssembly.instantiateStreaming === 'function') {
|
|
249
|
+
let responsePromise;
|
|
250
|
+
try {
|
|
251
|
+
responsePromise = fetch(wasmInput);
|
|
252
|
+
source = _WebAssembly.instantiateStreaming(responsePromise, imports).catch(() => {
|
|
253
|
+
return fetchWasm(wasmInput, imports);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
catch (_) {
|
|
257
|
+
source = fetchWasm(wasmInput, imports);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
source = fetchWasm(wasmInput, imports);
|
|
262
|
+
}
|
|
263
|
+
return source;
|
|
264
|
+
}
|
|
265
|
+
/** @public */
|
|
266
|
+
function asyncifyLoad(asyncify, urlOrBuffer, imports) {
|
|
267
|
+
validateImports(imports);
|
|
268
|
+
imports = imports !== null && imports !== void 0 ? imports : {};
|
|
269
|
+
const asyncifyHelper = new Asyncify();
|
|
270
|
+
imports = asyncifyHelper.wrapImports(imports);
|
|
271
|
+
return load(urlOrBuffer, imports).then(source => {
|
|
272
|
+
var _a;
|
|
273
|
+
const memory = source.instance.exports.memory || ((_a = imports.env) === null || _a === void 0 ? void 0 : _a.memory);
|
|
274
|
+
return { module: source.module, instance: asyncifyHelper.init(memory, source.instance, asyncify) };
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
/** @public */
|
|
278
|
+
function loadSync(wasmInput, imports) {
|
|
279
|
+
validateImports(imports);
|
|
280
|
+
imports = imports !== null && imports !== void 0 ? imports : {};
|
|
281
|
+
let module;
|
|
282
|
+
if ((wasmInput instanceof ArrayBuffer) || ArrayBuffer.isView(wasmInput)) {
|
|
283
|
+
module = new _WebAssembly.Module(wasmInput);
|
|
284
|
+
}
|
|
285
|
+
else if (wasmInput instanceof WebAssembly.Module) {
|
|
286
|
+
module = wasmInput;
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
throw new TypeError('Invalid source');
|
|
290
|
+
}
|
|
291
|
+
const instance = new _WebAssembly.Instance(module, imports);
|
|
292
|
+
const source = { instance, module };
|
|
293
|
+
return source;
|
|
294
|
+
}
|
|
295
|
+
/** @public */
|
|
296
|
+
function asyncifyLoadSync(asyncify, buffer, imports) {
|
|
297
|
+
var _a;
|
|
298
|
+
validateImports(imports);
|
|
299
|
+
imports = imports !== null && imports !== void 0 ? imports : {};
|
|
300
|
+
const asyncifyHelper = new Asyncify();
|
|
301
|
+
imports = asyncifyHelper.wrapImports(imports);
|
|
302
|
+
const source = loadSync(buffer, imports);
|
|
303
|
+
const memory = source.instance.exports.memory || ((_a = imports.env) === null || _a === void 0 ? void 0 : _a.memory);
|
|
304
|
+
return { module: source.module, instance: asyncifyHelper.init(memory, source.instance, asyncify) };
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const CHAR_DOT = 46; /* . */
|
|
308
|
+
const CHAR_FORWARD_SLASH = 47; /* / */
|
|
309
|
+
function isPosixPathSeparator(code) {
|
|
310
|
+
return code === CHAR_FORWARD_SLASH;
|
|
311
|
+
}
|
|
312
|
+
function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
|
|
313
|
+
let res = '';
|
|
314
|
+
let lastSegmentLength = 0;
|
|
315
|
+
let lastSlash = -1;
|
|
316
|
+
let dots = 0;
|
|
317
|
+
let code = 0;
|
|
318
|
+
for (let i = 0; i <= path.length; ++i) {
|
|
319
|
+
if (i < path.length) {
|
|
320
|
+
code = path.charCodeAt(i);
|
|
321
|
+
}
|
|
322
|
+
else if (isPathSeparator(code)) {
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
code = CHAR_FORWARD_SLASH;
|
|
327
|
+
}
|
|
328
|
+
if (isPathSeparator(code)) {
|
|
329
|
+
if (lastSlash === i - 1 || dots === 1) ;
|
|
330
|
+
else if (dots === 2) {
|
|
331
|
+
if (res.length < 2 || lastSegmentLength !== 2 ||
|
|
332
|
+
res.charCodeAt(res.length - 1) !== CHAR_DOT ||
|
|
333
|
+
res.charCodeAt(res.length - 2) !== CHAR_DOT) {
|
|
334
|
+
if (res.length > 2) {
|
|
335
|
+
const lastSlashIndex = res.indexOf(separator);
|
|
336
|
+
if (lastSlashIndex === -1) {
|
|
337
|
+
res = '';
|
|
338
|
+
lastSegmentLength = 0;
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
res = res.slice(0, lastSlashIndex);
|
|
342
|
+
lastSegmentLength =
|
|
343
|
+
res.length - 1 - res.indexOf(separator);
|
|
344
|
+
}
|
|
345
|
+
lastSlash = i;
|
|
346
|
+
dots = 0;
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
else if (res.length !== 0) {
|
|
350
|
+
res = '';
|
|
351
|
+
lastSegmentLength = 0;
|
|
352
|
+
lastSlash = i;
|
|
353
|
+
dots = 0;
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
if (allowAboveRoot) {
|
|
358
|
+
res += res.length > 0 ? `${separator}..` : '..';
|
|
359
|
+
lastSegmentLength = 2;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
if (res.length > 0) {
|
|
364
|
+
res += `${separator}${path.slice(lastSlash + 1, i)}`;
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
res = path.slice(lastSlash + 1, i);
|
|
368
|
+
}
|
|
369
|
+
lastSegmentLength = i - lastSlash - 1;
|
|
370
|
+
}
|
|
371
|
+
lastSlash = i;
|
|
372
|
+
dots = 0;
|
|
373
|
+
}
|
|
374
|
+
else if (code === CHAR_DOT && dots !== -1) {
|
|
375
|
+
++dots;
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
dots = -1;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return res;
|
|
382
|
+
}
|
|
383
|
+
function resolve(...args) {
|
|
384
|
+
let resolvedPath = '';
|
|
385
|
+
let resolvedAbsolute = false;
|
|
386
|
+
for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
387
|
+
const path = i >= 0 ? args[i] : '/';
|
|
388
|
+
validateString(path, 'path');
|
|
389
|
+
// Skip empty entries
|
|
390
|
+
if (path.length === 0) {
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
resolvedPath = `${path}/${resolvedPath}`;
|
|
394
|
+
resolvedAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
|
|
395
|
+
}
|
|
396
|
+
// At this point the path should be resolved to a full absolute path, but
|
|
397
|
+
// handle relative paths to be safe (might happen when process.cwd() fails)
|
|
398
|
+
// Normalize the path
|
|
399
|
+
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, '/', isPosixPathSeparator);
|
|
400
|
+
if (resolvedAbsolute) {
|
|
401
|
+
return `/${resolvedPath}`;
|
|
402
|
+
}
|
|
403
|
+
return resolvedPath.length > 0 ? resolvedPath : '.';
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const FD_DATASYNC = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(0));
|
|
407
|
+
const FD_READ = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(1));
|
|
408
|
+
const FD_SEEK = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(2));
|
|
409
|
+
const FD_FDSTAT_SET_FLAGS = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(3));
|
|
410
|
+
const FD_SYNC = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(4));
|
|
411
|
+
const FD_TELL = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(5));
|
|
412
|
+
const FD_WRITE = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(6));
|
|
413
|
+
const FD_ADVISE = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(7));
|
|
414
|
+
const FD_ALLOCATE = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(8));
|
|
415
|
+
const PATH_CREATE_DIRECTORY = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(9));
|
|
416
|
+
const PATH_CREATE_FILE = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(10));
|
|
417
|
+
const PATH_LINK_SOURCE = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(11));
|
|
418
|
+
const PATH_LINK_TARGET = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(12));
|
|
419
|
+
const PATH_OPEN = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(13));
|
|
420
|
+
const FD_READDIR = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(14));
|
|
421
|
+
const PATH_READLINK = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(15));
|
|
422
|
+
const PATH_RENAME_SOURCE = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(16));
|
|
423
|
+
const PATH_RENAME_TARGET = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(17));
|
|
424
|
+
const PATH_FILESTAT_GET = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(18));
|
|
425
|
+
const PATH_FILESTAT_SET_SIZE = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(19));
|
|
426
|
+
const PATH_FILESTAT_SET_TIMES = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(20));
|
|
427
|
+
const FD_FILESTAT_GET = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(21));
|
|
428
|
+
const FD_FILESTAT_SET_SIZE = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(22));
|
|
429
|
+
const FD_FILESTAT_SET_TIMES = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(23));
|
|
430
|
+
const PATH_SYMLINK = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(24));
|
|
431
|
+
const PATH_REMOVE_DIRECTORY = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(25));
|
|
432
|
+
const PATH_UNLINK_FILE = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(26));
|
|
433
|
+
const POLL_FD_READWRITE = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(27));
|
|
434
|
+
const SOCK_SHUTDOWN = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(28));
|
|
435
|
+
const SOCK_ACCEPT = ( /*#__PURE__*/BigInt(1) << /*#__PURE__*/ BigInt(29));
|
|
436
|
+
const WasiRights = {
|
|
437
|
+
FD_DATASYNC,
|
|
438
|
+
FD_READ,
|
|
439
|
+
FD_SEEK,
|
|
440
|
+
FD_FDSTAT_SET_FLAGS,
|
|
441
|
+
FD_SYNC,
|
|
442
|
+
FD_TELL,
|
|
443
|
+
FD_WRITE,
|
|
444
|
+
FD_ADVISE,
|
|
445
|
+
FD_ALLOCATE,
|
|
446
|
+
PATH_CREATE_DIRECTORY,
|
|
447
|
+
PATH_CREATE_FILE,
|
|
448
|
+
PATH_LINK_SOURCE,
|
|
449
|
+
PATH_LINK_TARGET,
|
|
450
|
+
PATH_OPEN,
|
|
451
|
+
FD_READDIR,
|
|
452
|
+
PATH_READLINK,
|
|
453
|
+
PATH_RENAME_SOURCE,
|
|
454
|
+
PATH_RENAME_TARGET,
|
|
455
|
+
PATH_FILESTAT_GET,
|
|
456
|
+
PATH_FILESTAT_SET_SIZE,
|
|
457
|
+
PATH_FILESTAT_SET_TIMES,
|
|
458
|
+
FD_FILESTAT_GET,
|
|
459
|
+
FD_FILESTAT_SET_SIZE,
|
|
460
|
+
FD_FILESTAT_SET_TIMES,
|
|
461
|
+
PATH_SYMLINK,
|
|
462
|
+
PATH_REMOVE_DIRECTORY,
|
|
463
|
+
PATH_UNLINK_FILE,
|
|
464
|
+
POLL_FD_READWRITE,
|
|
465
|
+
SOCK_SHUTDOWN,
|
|
466
|
+
SOCK_ACCEPT
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
function strerror(errno) {
|
|
470
|
+
switch (errno) {
|
|
471
|
+
case 0 /* WasiErrno.ESUCCESS */: return 'Success';
|
|
472
|
+
case 1 /* WasiErrno.E2BIG */: return 'Argument list too long';
|
|
473
|
+
case 2 /* WasiErrno.EACCES */: return 'Permission denied';
|
|
474
|
+
case 3 /* WasiErrno.EADDRINUSE */: return 'Address in use';
|
|
475
|
+
case 4 /* WasiErrno.EADDRNOTAVAIL */: return 'Address not available';
|
|
476
|
+
case 5 /* WasiErrno.EAFNOSUPPORT */: return 'Address family not supported by protocol';
|
|
477
|
+
case 6 /* WasiErrno.EAGAIN */: return 'Resource temporarily unavailable';
|
|
478
|
+
case 7 /* WasiErrno.EALREADY */: return 'Operation already in progress';
|
|
479
|
+
case 8 /* WasiErrno.EBADF */: return 'Bad file descriptor';
|
|
480
|
+
case 9 /* WasiErrno.EBADMSG */: return 'Bad message';
|
|
481
|
+
case 10 /* WasiErrno.EBUSY */: return 'Resource busy';
|
|
482
|
+
case 11 /* WasiErrno.ECANCELED */: return 'Operation canceled';
|
|
483
|
+
case 12 /* WasiErrno.ECHILD */: return 'No child process';
|
|
484
|
+
case 13 /* WasiErrno.ECONNABORTED */: return 'Connection aborted';
|
|
485
|
+
case 14 /* WasiErrno.ECONNREFUSED */: return 'Connection refused';
|
|
486
|
+
case 15 /* WasiErrno.ECONNRESET */: return 'Connection reset by peer';
|
|
487
|
+
case 16 /* WasiErrno.EDEADLK */: return 'Resource deadlock would occur';
|
|
488
|
+
case 17 /* WasiErrno.EDESTADDRREQ */: return 'Destination address required';
|
|
489
|
+
case 18 /* WasiErrno.EDOM */: return 'Domain error';
|
|
490
|
+
case 19 /* WasiErrno.EDQUOT */: return 'Quota exceeded';
|
|
491
|
+
case 20 /* WasiErrno.EEXIST */: return 'File exists';
|
|
492
|
+
case 21 /* WasiErrno.EFAULT */: return 'Bad address';
|
|
493
|
+
case 22 /* WasiErrno.EFBIG */: return 'File too large';
|
|
494
|
+
case 23 /* WasiErrno.EHOSTUNREACH */: return 'Host is unreachable';
|
|
495
|
+
case 24 /* WasiErrno.EIDRM */: return 'Identifier removed';
|
|
496
|
+
case 25 /* WasiErrno.EILSEQ */: return 'Illegal byte sequence';
|
|
497
|
+
case 26 /* WasiErrno.EINPROGRESS */: return 'Operation in progress';
|
|
498
|
+
case 27 /* WasiErrno.EINTR */: return 'Interrupted system call';
|
|
499
|
+
case 28 /* WasiErrno.EINVAL */: return 'Invalid argument';
|
|
500
|
+
case 29 /* WasiErrno.EIO */: return 'I/O error';
|
|
501
|
+
case 30 /* WasiErrno.EISCONN */: return 'Socket is connected';
|
|
502
|
+
case 31 /* WasiErrno.EISDIR */: return 'Is a directory';
|
|
503
|
+
case 32 /* WasiErrno.ELOOP */: return 'Symbolic link loop';
|
|
504
|
+
case 33 /* WasiErrno.EMFILE */: return 'No file descriptors available';
|
|
505
|
+
case 34 /* WasiErrno.EMLINK */: return 'Too many links';
|
|
506
|
+
case 35 /* WasiErrno.EMSGSIZE */: return 'Message too large';
|
|
507
|
+
case 36 /* WasiErrno.EMULTIHOP */: return 'Multihop attempted';
|
|
508
|
+
case 37 /* WasiErrno.ENAMETOOLONG */: return 'Filename too long';
|
|
509
|
+
case 38 /* WasiErrno.ENETDOWN */: return 'Network is down';
|
|
510
|
+
case 39 /* WasiErrno.ENETRESET */: return 'Connection reset by network';
|
|
511
|
+
case 40 /* WasiErrno.ENETUNREACH */: return 'Network unreachable';
|
|
512
|
+
case 41 /* WasiErrno.ENFILE */: return 'Too many files open in system';
|
|
513
|
+
case 42 /* WasiErrno.ENOBUFS */: return 'No buffer space available';
|
|
514
|
+
case 43 /* WasiErrno.ENODEV */: return 'No such device';
|
|
515
|
+
case 44 /* WasiErrno.ENOENT */: return 'No such file or directory';
|
|
516
|
+
case 45 /* WasiErrno.ENOEXEC */: return 'Exec format error';
|
|
517
|
+
case 46 /* WasiErrno.ENOLCK */: return 'No locks available';
|
|
518
|
+
case 47 /* WasiErrno.ENOLINK */: return 'Link has been severed';
|
|
519
|
+
case 48 /* WasiErrno.ENOMEM */: return 'Out of memory';
|
|
520
|
+
case 49 /* WasiErrno.ENOMSG */: return 'No message of the desired type';
|
|
521
|
+
case 50 /* WasiErrno.ENOPROTOOPT */: return 'Protocol not available';
|
|
522
|
+
case 51 /* WasiErrno.ENOSPC */: return 'No space left on device';
|
|
523
|
+
case 52 /* WasiErrno.ENOSYS */: return 'Function not implemented';
|
|
524
|
+
case 53 /* WasiErrno.ENOTCONN */: return 'Socket not connected';
|
|
525
|
+
case 54 /* WasiErrno.ENOTDIR */: return 'Not a directory';
|
|
526
|
+
case 55 /* WasiErrno.ENOTEMPTY */: return 'Directory not empty';
|
|
527
|
+
case 56 /* WasiErrno.ENOTRECOVERABLE */: return 'State not recoverable';
|
|
528
|
+
case 57 /* WasiErrno.ENOTSOCK */: return 'Not a socket';
|
|
529
|
+
case 58 /* WasiErrno.ENOTSUP */: return 'Not supported';
|
|
530
|
+
case 59 /* WasiErrno.ENOTTY */: return 'Not a tty';
|
|
531
|
+
case 60 /* WasiErrno.ENXIO */: return 'No such device or address';
|
|
532
|
+
case 61 /* WasiErrno.EOVERFLOW */: return 'Value too large for data type';
|
|
533
|
+
case 62 /* WasiErrno.EOWNERDEAD */: return 'Previous owner died';
|
|
534
|
+
case 63 /* WasiErrno.EPERM */: return 'Operation not permitted';
|
|
535
|
+
case 64 /* WasiErrno.EPIPE */: return 'Broken pipe';
|
|
536
|
+
case 65 /* WasiErrno.EPROTO */: return 'Protocol error';
|
|
537
|
+
case 66 /* WasiErrno.EPROTONOSUPPORT */: return 'Protocol not supported';
|
|
538
|
+
case 67 /* WasiErrno.EPROTOTYPE */: return 'Protocol wrong type for socket';
|
|
539
|
+
case 68 /* WasiErrno.ERANGE */: return 'Result not representable';
|
|
540
|
+
case 69 /* WasiErrno.EROFS */: return 'Read-only file system';
|
|
541
|
+
case 70 /* WasiErrno.ESPIPE */: return 'Invalid seek';
|
|
542
|
+
case 71 /* WasiErrno.ESRCH */: return 'No such process';
|
|
543
|
+
case 72 /* WasiErrno.ESTALE */: return 'Stale file handle';
|
|
544
|
+
case 73 /* WasiErrno.ETIMEDOUT */: return 'Operation timed out';
|
|
545
|
+
case 74 /* WasiErrno.ETXTBSY */: return 'Text file busy';
|
|
546
|
+
case 75 /* WasiErrno.EXDEV */: return 'Cross-device link';
|
|
547
|
+
case 76 /* WasiErrno.ENOTCAPABLE */: return 'Capabilities insufficient';
|
|
548
|
+
default: return 'Unknown error';
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
class WasiError extends Error {
|
|
552
|
+
constructor(message, errno) {
|
|
553
|
+
super(message);
|
|
554
|
+
this.errno = errno;
|
|
555
|
+
}
|
|
556
|
+
getErrorMessage() {
|
|
557
|
+
return strerror(this.errno);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
Object.defineProperty(WasiError.prototype, 'name', {
|
|
561
|
+
configurable: true,
|
|
562
|
+
writable: true,
|
|
563
|
+
value: 'WasiError'
|
|
564
|
+
});
|
|
565
|
+
|
|
566
|
+
const RIGHTS_ALL = WasiRights.FD_DATASYNC |
|
|
567
|
+
WasiRights.FD_READ |
|
|
568
|
+
WasiRights.FD_SEEK |
|
|
569
|
+
WasiRights.FD_FDSTAT_SET_FLAGS |
|
|
570
|
+
WasiRights.FD_SYNC |
|
|
571
|
+
WasiRights.FD_TELL |
|
|
572
|
+
WasiRights.FD_WRITE |
|
|
573
|
+
WasiRights.FD_ADVISE |
|
|
574
|
+
WasiRights.FD_ALLOCATE |
|
|
575
|
+
WasiRights.PATH_CREATE_DIRECTORY |
|
|
576
|
+
WasiRights.PATH_CREATE_FILE |
|
|
577
|
+
WasiRights.PATH_LINK_SOURCE |
|
|
578
|
+
WasiRights.PATH_LINK_TARGET |
|
|
579
|
+
WasiRights.PATH_OPEN |
|
|
580
|
+
WasiRights.FD_READDIR |
|
|
581
|
+
WasiRights.PATH_READLINK |
|
|
582
|
+
WasiRights.PATH_RENAME_SOURCE |
|
|
583
|
+
WasiRights.PATH_RENAME_TARGET |
|
|
584
|
+
WasiRights.PATH_FILESTAT_GET |
|
|
585
|
+
WasiRights.PATH_FILESTAT_SET_SIZE |
|
|
586
|
+
WasiRights.PATH_FILESTAT_SET_TIMES |
|
|
587
|
+
WasiRights.FD_FILESTAT_GET |
|
|
588
|
+
WasiRights.FD_FILESTAT_SET_TIMES |
|
|
589
|
+
WasiRights.FD_FILESTAT_SET_SIZE |
|
|
590
|
+
WasiRights.PATH_SYMLINK |
|
|
591
|
+
WasiRights.PATH_UNLINK_FILE |
|
|
592
|
+
WasiRights.PATH_REMOVE_DIRECTORY |
|
|
593
|
+
WasiRights.POLL_FD_READWRITE |
|
|
594
|
+
WasiRights.SOCK_SHUTDOWN |
|
|
595
|
+
WasiRights.SOCK_ACCEPT;
|
|
596
|
+
const BLOCK_DEVICE_BASE = RIGHTS_ALL;
|
|
597
|
+
const BLOCK_DEVICE_INHERITING = RIGHTS_ALL;
|
|
598
|
+
const CHARACTER_DEVICE_BASE = RIGHTS_ALL;
|
|
599
|
+
const CHARACTER_DEVICE_INHERITING = RIGHTS_ALL;
|
|
600
|
+
const REGULAR_FILE_BASE = WasiRights.FD_DATASYNC |
|
|
601
|
+
WasiRights.FD_READ |
|
|
602
|
+
WasiRights.FD_SEEK |
|
|
603
|
+
WasiRights.FD_FDSTAT_SET_FLAGS |
|
|
604
|
+
WasiRights.FD_SYNC |
|
|
605
|
+
WasiRights.FD_TELL |
|
|
606
|
+
WasiRights.FD_WRITE |
|
|
607
|
+
WasiRights.FD_ADVISE |
|
|
608
|
+
WasiRights.FD_ALLOCATE |
|
|
609
|
+
WasiRights.FD_FILESTAT_GET |
|
|
610
|
+
WasiRights.FD_FILESTAT_SET_SIZE |
|
|
611
|
+
WasiRights.FD_FILESTAT_SET_TIMES |
|
|
612
|
+
WasiRights.POLL_FD_READWRITE;
|
|
613
|
+
const REGULAR_FILE_INHERITING = /*#__PURE__*/ BigInt(0);
|
|
614
|
+
const DIRECTORY_BASE = WasiRights.FD_FDSTAT_SET_FLAGS |
|
|
615
|
+
WasiRights.FD_SYNC |
|
|
616
|
+
WasiRights.FD_ADVISE |
|
|
617
|
+
WasiRights.PATH_CREATE_DIRECTORY |
|
|
618
|
+
WasiRights.PATH_CREATE_FILE |
|
|
619
|
+
WasiRights.PATH_LINK_SOURCE |
|
|
620
|
+
WasiRights.PATH_LINK_TARGET |
|
|
621
|
+
WasiRights.PATH_OPEN |
|
|
622
|
+
WasiRights.FD_READDIR |
|
|
623
|
+
WasiRights.PATH_READLINK |
|
|
624
|
+
WasiRights.PATH_RENAME_SOURCE |
|
|
625
|
+
WasiRights.PATH_RENAME_TARGET |
|
|
626
|
+
WasiRights.PATH_FILESTAT_GET |
|
|
627
|
+
WasiRights.PATH_FILESTAT_SET_SIZE |
|
|
628
|
+
WasiRights.PATH_FILESTAT_SET_TIMES |
|
|
629
|
+
WasiRights.FD_FILESTAT_GET |
|
|
630
|
+
WasiRights.FD_FILESTAT_SET_TIMES |
|
|
631
|
+
WasiRights.PATH_SYMLINK |
|
|
632
|
+
WasiRights.PATH_UNLINK_FILE |
|
|
633
|
+
WasiRights.PATH_REMOVE_DIRECTORY |
|
|
634
|
+
WasiRights.POLL_FD_READWRITE;
|
|
635
|
+
const DIRECTORY_INHERITING = DIRECTORY_BASE | REGULAR_FILE_BASE;
|
|
636
|
+
const SOCKET_BASE = (WasiRights.FD_READ |
|
|
637
|
+
WasiRights.FD_FDSTAT_SET_FLAGS |
|
|
638
|
+
WasiRights.FD_WRITE |
|
|
639
|
+
WasiRights.FD_FILESTAT_GET |
|
|
640
|
+
WasiRights.POLL_FD_READWRITE |
|
|
641
|
+
WasiRights.SOCK_SHUTDOWN);
|
|
642
|
+
const SOCKET_INHERITING = RIGHTS_ALL;
|
|
643
|
+
const TTY_BASE = WasiRights.FD_READ |
|
|
644
|
+
WasiRights.FD_FDSTAT_SET_FLAGS |
|
|
645
|
+
WasiRights.FD_WRITE |
|
|
646
|
+
WasiRights.FD_FILESTAT_GET |
|
|
647
|
+
WasiRights.POLL_FD_READWRITE;
|
|
648
|
+
const TTY_INHERITING = /*#__PURE__*/ BigInt(0);
|
|
649
|
+
function getRights(stdio, fd, flags, type) {
|
|
650
|
+
const ret = {
|
|
651
|
+
base: BigInt(0),
|
|
652
|
+
inheriting: BigInt(0)
|
|
653
|
+
};
|
|
654
|
+
if (type === 0 /* WasiFileType.UNKNOWN */) {
|
|
655
|
+
throw new WasiError('Unknown file type', 28 /* WasiErrno.EINVAL */);
|
|
656
|
+
}
|
|
657
|
+
switch (type) {
|
|
658
|
+
case 4 /* WasiFileType.REGULAR_FILE */:
|
|
659
|
+
ret.base = REGULAR_FILE_BASE;
|
|
660
|
+
ret.inheriting = REGULAR_FILE_INHERITING;
|
|
661
|
+
break;
|
|
662
|
+
case 3 /* WasiFileType.DIRECTORY */:
|
|
663
|
+
ret.base = DIRECTORY_BASE;
|
|
664
|
+
ret.inheriting = DIRECTORY_INHERITING;
|
|
665
|
+
break;
|
|
666
|
+
case 6 /* WasiFileType.SOCKET_STREAM */:
|
|
667
|
+
case 5 /* WasiFileType.SOCKET_DGRAM */:
|
|
668
|
+
ret.base = SOCKET_BASE;
|
|
669
|
+
ret.inheriting = SOCKET_INHERITING;
|
|
670
|
+
break;
|
|
671
|
+
case 2 /* WasiFileType.CHARACTER_DEVICE */:
|
|
672
|
+
if (stdio.indexOf(fd) !== -1) {
|
|
673
|
+
ret.base = TTY_BASE;
|
|
674
|
+
ret.inheriting = TTY_INHERITING;
|
|
675
|
+
}
|
|
676
|
+
else {
|
|
677
|
+
ret.base = CHARACTER_DEVICE_BASE;
|
|
678
|
+
ret.inheriting = CHARACTER_DEVICE_INHERITING;
|
|
679
|
+
}
|
|
680
|
+
break;
|
|
681
|
+
case 1 /* WasiFileType.BLOCK_DEVICE */:
|
|
682
|
+
ret.base = BLOCK_DEVICE_BASE;
|
|
683
|
+
ret.inheriting = BLOCK_DEVICE_INHERITING;
|
|
684
|
+
break;
|
|
685
|
+
default:
|
|
686
|
+
ret.base = BigInt(0);
|
|
687
|
+
ret.inheriting = BigInt(0);
|
|
688
|
+
}
|
|
689
|
+
/* Disable read/write bits depending on access mode. */
|
|
690
|
+
const read_or_write_only = flags & (0 | 1 | 2);
|
|
691
|
+
if (read_or_write_only === 0) {
|
|
692
|
+
ret.base &= ~WasiRights.FD_WRITE;
|
|
693
|
+
}
|
|
694
|
+
else if (read_or_write_only === 1) {
|
|
695
|
+
ret.base &= ~WasiRights.FD_READ;
|
|
696
|
+
}
|
|
697
|
+
return ret;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
function concatBuffer(buffers, size) {
|
|
701
|
+
let total = 0;
|
|
702
|
+
if (typeof size === 'number' && size >= 0) {
|
|
703
|
+
total = size;
|
|
704
|
+
}
|
|
705
|
+
else {
|
|
706
|
+
for (let i = 0; i < buffers.length; i++) {
|
|
707
|
+
const buffer = buffers[i];
|
|
708
|
+
total += buffer.length;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
let pos = 0;
|
|
712
|
+
const ret = new Uint8Array(total);
|
|
713
|
+
for (let i = 0; i < buffers.length; i++) {
|
|
714
|
+
const buffer = buffers[i];
|
|
715
|
+
ret.set(buffer, pos);
|
|
716
|
+
pos += buffer.length;
|
|
717
|
+
}
|
|
718
|
+
return ret;
|
|
719
|
+
}
|
|
720
|
+
class FileDescriptor {
|
|
721
|
+
constructor(id, fd, path, realPath, type, rightsBase, rightsInheriting, preopen) {
|
|
722
|
+
this.id = id;
|
|
723
|
+
this.fd = fd;
|
|
724
|
+
this.path = path;
|
|
725
|
+
this.realPath = realPath;
|
|
726
|
+
this.type = type;
|
|
727
|
+
this.rightsBase = rightsBase;
|
|
728
|
+
this.rightsInheriting = rightsInheriting;
|
|
729
|
+
this.preopen = preopen;
|
|
730
|
+
this.pos = BigInt(0);
|
|
731
|
+
this.size = BigInt(0);
|
|
732
|
+
}
|
|
733
|
+
seek(offset, whence) {
|
|
734
|
+
if (whence === 0 /* WasiWhence.SET */) {
|
|
735
|
+
this.pos = BigInt(offset);
|
|
736
|
+
}
|
|
737
|
+
else if (whence === 1 /* WasiWhence.CUR */) {
|
|
738
|
+
this.pos += BigInt(offset);
|
|
739
|
+
}
|
|
740
|
+
else if (whence === 2 /* WasiWhence.END */) {
|
|
741
|
+
this.pos = BigInt(this.size) - BigInt(offset);
|
|
742
|
+
}
|
|
743
|
+
else {
|
|
744
|
+
throw new WasiError('Unknown whence', 29 /* WasiErrno.EIO */);
|
|
745
|
+
}
|
|
746
|
+
return this.pos;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
class StandardOutput extends FileDescriptor {
|
|
750
|
+
constructor(log, id, fd, path, realPath, type, rightsBase, rightsInheriting, preopen) {
|
|
751
|
+
super(id, fd, path, realPath, type, rightsBase, rightsInheriting, preopen);
|
|
752
|
+
this._log = log;
|
|
753
|
+
this._buf = null;
|
|
754
|
+
}
|
|
755
|
+
write(buffer) {
|
|
756
|
+
const originalBuffer = buffer;
|
|
757
|
+
if (this._buf) {
|
|
758
|
+
buffer = concatBuffer([this._buf, buffer]);
|
|
759
|
+
this._buf = null;
|
|
760
|
+
}
|
|
761
|
+
if (buffer.indexOf(10) === -1) {
|
|
762
|
+
this._buf = buffer;
|
|
763
|
+
return originalBuffer.byteLength;
|
|
764
|
+
}
|
|
765
|
+
let written = 0;
|
|
766
|
+
let lastBegin = 0;
|
|
767
|
+
let index;
|
|
768
|
+
while ((index = buffer.indexOf(10, written)) !== -1) {
|
|
769
|
+
const str = new TextDecoder().decode(buffer.subarray(lastBegin, index));
|
|
770
|
+
this._log(str);
|
|
771
|
+
written += index - lastBegin + 1;
|
|
772
|
+
lastBegin = index + 1;
|
|
773
|
+
}
|
|
774
|
+
if (written < buffer.length) {
|
|
775
|
+
this._buf = buffer.slice(written);
|
|
776
|
+
}
|
|
777
|
+
return originalBuffer.byteLength;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
function toFileType(stat) {
|
|
781
|
+
if (stat.isBlockDevice())
|
|
782
|
+
return 1 /* WasiFileType.BLOCK_DEVICE */;
|
|
783
|
+
if (stat.isCharacterDevice())
|
|
784
|
+
return 2 /* WasiFileType.CHARACTER_DEVICE */;
|
|
785
|
+
if (stat.isDirectory())
|
|
786
|
+
return 3 /* WasiFileType.DIRECTORY */;
|
|
787
|
+
if (stat.isSocket())
|
|
788
|
+
return 6 /* WasiFileType.SOCKET_STREAM */;
|
|
789
|
+
if (stat.isFile())
|
|
790
|
+
return 4 /* WasiFileType.REGULAR_FILE */;
|
|
791
|
+
if (stat.isSymbolicLink())
|
|
792
|
+
return 7 /* WasiFileType.SYMBOLIC_LINK */;
|
|
793
|
+
return 0 /* WasiFileType.UNKNOWN */;
|
|
794
|
+
}
|
|
795
|
+
function toFileStat(view, buf, stat) {
|
|
796
|
+
view.setBigUint64(buf, stat.dev, true);
|
|
797
|
+
view.setBigUint64(buf + 8, stat.ino, true);
|
|
798
|
+
view.setBigUint64(buf + 16, BigInt(toFileType(stat)), true);
|
|
799
|
+
view.setBigUint64(buf + 24, stat.nlink, true);
|
|
800
|
+
view.setBigUint64(buf + 32, stat.size, true);
|
|
801
|
+
view.setBigUint64(buf + 40, stat.atimeMs * BigInt(1000000), true);
|
|
802
|
+
view.setBigUint64(buf + 48, stat.mtimeMs * BigInt(1000000), true);
|
|
803
|
+
view.setBigUint64(buf + 56, stat.ctimeMs * BigInt(1000000), true);
|
|
804
|
+
}
|
|
805
|
+
class FileDescriptorTable {
|
|
806
|
+
constructor(options) {
|
|
807
|
+
this.used = 0;
|
|
808
|
+
this.size = options.size;
|
|
809
|
+
this.fds = Array(options.size);
|
|
810
|
+
this.stdio = [options.in, options.out, options.err];
|
|
811
|
+
this.print = options.print;
|
|
812
|
+
this.printErr = options.printErr;
|
|
813
|
+
this.insertStdio(options.in, 0, '<stdin>');
|
|
814
|
+
this.insertStdio(options.out, 1, '<stdout>');
|
|
815
|
+
this.insertStdio(options.err, 2, '<stderr>');
|
|
816
|
+
}
|
|
817
|
+
insertStdio(fd, expected, name) {
|
|
818
|
+
const type = 2 /* WasiFileType.CHARACTER_DEVICE */;
|
|
819
|
+
const { base, inheriting } = getRights(this.stdio, fd, 2 /* FileControlFlag.O_RDWR */, type);
|
|
820
|
+
const wrap = this.insert(fd, name, name, type, base, inheriting, 0);
|
|
821
|
+
if (wrap.id !== expected) {
|
|
822
|
+
throw new WasiError(`id: ${wrap.id} !== expected: ${expected}`, 8 /* WasiErrno.EBADF */);
|
|
823
|
+
}
|
|
824
|
+
return wrap;
|
|
825
|
+
}
|
|
826
|
+
insert(fd, mappedPath, realPath, type, rightsBase, rightsInheriting, preopen) {
|
|
827
|
+
var _a, _b;
|
|
828
|
+
let index = -1;
|
|
829
|
+
if (this.used >= this.size) {
|
|
830
|
+
const newSize = this.size * 2;
|
|
831
|
+
this.fds.length = newSize;
|
|
832
|
+
index = this.size;
|
|
833
|
+
this.size = newSize;
|
|
834
|
+
}
|
|
835
|
+
else {
|
|
836
|
+
for (let i = 0; i < this.size; ++i) {
|
|
837
|
+
if (this.fds[i] == null) {
|
|
838
|
+
index = i;
|
|
839
|
+
break;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
let entry;
|
|
844
|
+
if (mappedPath === '<stdout>') {
|
|
845
|
+
entry = new StandardOutput((_a = this.print) !== null && _a !== void 0 ? _a : console.log, index, fd, mappedPath, realPath, type, rightsBase, rightsInheriting, preopen);
|
|
846
|
+
}
|
|
847
|
+
else if (mappedPath === '<stderr>') {
|
|
848
|
+
entry = new StandardOutput((_b = this.printErr) !== null && _b !== void 0 ? _b : console.error, index, fd, mappedPath, realPath, type, rightsBase, rightsInheriting, preopen);
|
|
849
|
+
}
|
|
850
|
+
else {
|
|
851
|
+
entry = new FileDescriptor(index, fd, mappedPath, realPath, type, rightsBase, rightsInheriting, preopen);
|
|
852
|
+
}
|
|
853
|
+
this.fds[index] = entry;
|
|
854
|
+
this.used++;
|
|
855
|
+
return entry;
|
|
856
|
+
}
|
|
857
|
+
get(id, base, inheriting) {
|
|
858
|
+
if (id >= this.size) {
|
|
859
|
+
throw new WasiError('Invalid fd', 8 /* WasiErrno.EBADF */);
|
|
860
|
+
}
|
|
861
|
+
const entry = this.fds[id];
|
|
862
|
+
if (!entry || entry.id !== id) {
|
|
863
|
+
throw new WasiError('Bad file descriptor', 8 /* WasiErrno.EBADF */);
|
|
864
|
+
}
|
|
865
|
+
/* Validate that the fd has the necessary rights. */
|
|
866
|
+
if ((~entry.rightsBase & base) !== BigInt(0) || (~entry.rightsInheriting & inheriting) !== BigInt(0)) {
|
|
867
|
+
throw new WasiError('Capabilities insufficient', 76 /* WasiErrno.ENOTCAPABLE */);
|
|
868
|
+
}
|
|
869
|
+
return entry;
|
|
870
|
+
}
|
|
871
|
+
remove(id) {
|
|
872
|
+
if (id >= this.size) {
|
|
873
|
+
throw new WasiError('Invalid fd', 8 /* WasiErrno.EBADF */);
|
|
874
|
+
}
|
|
875
|
+
const entry = this.fds[id];
|
|
876
|
+
if (!entry || entry.id !== id) {
|
|
877
|
+
throw new WasiError('Bad file descriptor', 8 /* WasiErrno.EBADF */);
|
|
878
|
+
}
|
|
879
|
+
this.fds[id] = undefined;
|
|
880
|
+
this.used--;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
class SyncTable extends FileDescriptorTable {
|
|
884
|
+
constructor(options) {
|
|
885
|
+
super(options);
|
|
886
|
+
this.fs = options.fs;
|
|
887
|
+
}
|
|
888
|
+
getFileTypeByFd(fd) {
|
|
889
|
+
const stats = this.fs.fstatSync(fd, { bigint: true });
|
|
890
|
+
return toFileType(stats);
|
|
891
|
+
}
|
|
892
|
+
insertPreopen(fd, mappedPath, realPath) {
|
|
893
|
+
const type = this.getFileTypeByFd(fd);
|
|
894
|
+
if (type !== 3 /* WasiFileType.DIRECTORY */) {
|
|
895
|
+
throw new WasiError(`Preopen not dir: ["${mappedPath}", "${realPath}"]`, 54 /* WasiErrno.ENOTDIR */);
|
|
896
|
+
}
|
|
897
|
+
const result = getRights(this.stdio, fd, 0, type);
|
|
898
|
+
return this.insert(fd, mappedPath, realPath, type, result.base, result.inheriting, 1);
|
|
899
|
+
}
|
|
900
|
+
renumber(dst, src) {
|
|
901
|
+
if (dst === src)
|
|
902
|
+
return;
|
|
903
|
+
if (dst >= this.size || src >= this.size) {
|
|
904
|
+
throw new WasiError('Invalid fd', 8 /* WasiErrno.EBADF */);
|
|
905
|
+
}
|
|
906
|
+
const dstEntry = this.fds[dst];
|
|
907
|
+
const srcEntry = this.fds[src];
|
|
908
|
+
if (!dstEntry || !srcEntry || dstEntry.id !== dst || srcEntry.id !== src) {
|
|
909
|
+
throw new WasiError('Invalid fd', 8 /* WasiErrno.EBADF */);
|
|
910
|
+
}
|
|
911
|
+
this.fs.closeSync(dstEntry.fd);
|
|
912
|
+
this.fds[dst] = this.fds[src];
|
|
913
|
+
this.fds[dst].id = dst;
|
|
914
|
+
this.fds[src] = undefined;
|
|
915
|
+
this.used--;
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
class AsyncTable extends FileDescriptorTable {
|
|
919
|
+
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
|
|
920
|
+
constructor(options) {
|
|
921
|
+
super(options);
|
|
922
|
+
}
|
|
923
|
+
async getFileTypeByFd(fd) {
|
|
924
|
+
const stats = await fd.stat({ bigint: true });
|
|
925
|
+
return toFileType(stats);
|
|
926
|
+
}
|
|
927
|
+
async insertPreopen(fd, mappedPath, realPath) {
|
|
928
|
+
const type = await this.getFileTypeByFd(fd);
|
|
929
|
+
if (type !== 3 /* WasiFileType.DIRECTORY */) {
|
|
930
|
+
throw new WasiError(`Preopen not dir: ["${mappedPath}", "${realPath}"]`, 54 /* WasiErrno.ENOTDIR */);
|
|
931
|
+
}
|
|
932
|
+
const result = getRights(this.stdio, fd.fd, 0, type);
|
|
933
|
+
return this.insert(fd, mappedPath, realPath, type, result.base, result.inheriting, 1);
|
|
934
|
+
}
|
|
935
|
+
async renumber(dst, src) {
|
|
936
|
+
if (dst === src)
|
|
937
|
+
return;
|
|
938
|
+
if (dst >= this.size || src >= this.size) {
|
|
939
|
+
throw new WasiError('Invalid fd', 8 /* WasiErrno.EBADF */);
|
|
940
|
+
}
|
|
941
|
+
const dstEntry = this.fds[dst];
|
|
942
|
+
const srcEntry = this.fds[src];
|
|
943
|
+
if (!dstEntry || !srcEntry || dstEntry.id !== dst || srcEntry.id !== src) {
|
|
944
|
+
throw new WasiError('Invalid fd', 8 /* WasiErrno.EBADF */);
|
|
945
|
+
}
|
|
946
|
+
await dstEntry.fd.close();
|
|
947
|
+
this.fds[dst] = this.fds[src];
|
|
948
|
+
this.fds[dst].id = dst;
|
|
949
|
+
this.fds[src] = undefined;
|
|
950
|
+
this.used--;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
/** @public */
|
|
955
|
+
const WebAssemblyMemory = /*#__PURE__*/ (function () { return _WebAssembly.Memory; })();
|
|
956
|
+
/** @public */
|
|
957
|
+
class Memory extends WebAssemblyMemory {
|
|
958
|
+
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
|
|
959
|
+
constructor(descriptor) {
|
|
960
|
+
super(descriptor);
|
|
961
|
+
}
|
|
962
|
+
get HEAP8() { return new Int8Array(super.buffer); }
|
|
963
|
+
get HEAPU8() { return new Uint8Array(super.buffer); }
|
|
964
|
+
get HEAP16() { return new Int16Array(super.buffer); }
|
|
965
|
+
get HEAPU16() { return new Uint16Array(super.buffer); }
|
|
966
|
+
get HEAP32() { return new Int32Array(super.buffer); }
|
|
967
|
+
get HEAPU32() { return new Uint32Array(super.buffer); }
|
|
968
|
+
get HEAP64() { return new BigInt64Array(super.buffer); }
|
|
969
|
+
get HEAPU64() { return new BigUint64Array(super.buffer); }
|
|
970
|
+
get HEAPF32() { return new Float32Array(super.buffer); }
|
|
971
|
+
get HEAPF64() { return new Float64Array(super.buffer); }
|
|
972
|
+
get view() { return new DataView(super.buffer); }
|
|
973
|
+
}
|
|
974
|
+
/** @public */
|
|
975
|
+
function extendMemory(memory) {
|
|
976
|
+
if (Object.getPrototypeOf(memory) === _WebAssembly.Memory.prototype) {
|
|
977
|
+
Object.setPrototypeOf(memory, Memory.prototype);
|
|
978
|
+
}
|
|
979
|
+
return memory;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
function checkWebAssemblyFunction() {
|
|
983
|
+
const WebAssemblyFunction = _WebAssembly.Function;
|
|
984
|
+
if (typeof WebAssemblyFunction !== 'function') {
|
|
985
|
+
throw new Error('WebAssembly.Function is not supported in this environment.' +
|
|
986
|
+
' If you are using V8 based browser like Chrome, try to specify' +
|
|
987
|
+
' --js-flags="--wasm-staging --experimental-wasm-stack-switching"');
|
|
988
|
+
}
|
|
989
|
+
return WebAssemblyFunction;
|
|
990
|
+
}
|
|
991
|
+
/** @public */
|
|
992
|
+
function wrapAsyncImport(f, parameterType, returnType) {
|
|
993
|
+
const WebAssemblyFunction = checkWebAssemblyFunction();
|
|
994
|
+
if (typeof f !== 'function') {
|
|
995
|
+
throw new TypeError('Function required');
|
|
996
|
+
}
|
|
997
|
+
const parameters = parameterType.slice(0);
|
|
998
|
+
parameters.unshift('externref');
|
|
999
|
+
return new WebAssemblyFunction({ parameters, results: returnType }, f, { suspending: 'first' });
|
|
1000
|
+
}
|
|
1001
|
+
/** @public */
|
|
1002
|
+
function wrapAsyncExport(f) {
|
|
1003
|
+
const WebAssemblyFunction = checkWebAssemblyFunction();
|
|
1004
|
+
if (typeof f !== 'function') {
|
|
1005
|
+
throw new TypeError('Function required');
|
|
1006
|
+
}
|
|
1007
|
+
return new WebAssemblyFunction({ parameters: [...WebAssemblyFunction.type(f).parameters.slice(1)], results: ['externref'] }, f, { promising: 'first' });
|
|
1008
|
+
}
|
|
1009
|
+
/** @public */
|
|
1010
|
+
function wrapExports(exports, needWrap) {
|
|
1011
|
+
return wrapInstanceExports(exports, (exportValue, name) => {
|
|
1012
|
+
let ignore = typeof exportValue !== 'function';
|
|
1013
|
+
if (Array.isArray(needWrap)) {
|
|
1014
|
+
ignore = ignore || (needWrap.indexOf(name) === -1);
|
|
1015
|
+
}
|
|
1016
|
+
return ignore ? exportValue : wrapAsyncExport(exportValue);
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
function copyMemory(targets, src) {
|
|
1021
|
+
if (targets.length === 0 || src.length === 0)
|
|
1022
|
+
return 0;
|
|
1023
|
+
let copied = 0;
|
|
1024
|
+
let left = src.length - copied;
|
|
1025
|
+
for (let i = 0; i < targets.length; ++i) {
|
|
1026
|
+
const target = targets[i];
|
|
1027
|
+
if (left < target.length) {
|
|
1028
|
+
target.set(src.subarray(copied, copied + left), 0);
|
|
1029
|
+
copied += left;
|
|
1030
|
+
left = 0;
|
|
1031
|
+
return copied;
|
|
1032
|
+
}
|
|
1033
|
+
target.set(src.subarray(copied, copied + target.length), 0);
|
|
1034
|
+
copied += target.length;
|
|
1035
|
+
left -= target.length;
|
|
1036
|
+
}
|
|
1037
|
+
return copied;
|
|
1038
|
+
}
|
|
1039
|
+
const _memory = new WeakMap();
|
|
1040
|
+
const _wasi = new WeakMap();
|
|
1041
|
+
const _fs = new WeakMap();
|
|
1042
|
+
function getMemory(wasi) {
|
|
1043
|
+
return _memory.get(wasi);
|
|
1044
|
+
}
|
|
1045
|
+
function getFs(wasi) {
|
|
1046
|
+
const fs = _fs.get(wasi);
|
|
1047
|
+
if (!fs)
|
|
1048
|
+
throw new Error('filesystem is unavailable');
|
|
1049
|
+
return fs;
|
|
1050
|
+
}
|
|
1051
|
+
function handleError(err) {
|
|
1052
|
+
if (err instanceof WasiError) {
|
|
1053
|
+
{
|
|
1054
|
+
console.warn(err);
|
|
1055
|
+
}
|
|
1056
|
+
return err.errno;
|
|
1057
|
+
}
|
|
1058
|
+
switch (err.code) {
|
|
1059
|
+
case 'ENOENT': return 44 /* WasiErrno.ENOENT */;
|
|
1060
|
+
case 'EBADF': return 8 /* WasiErrno.EBADF */;
|
|
1061
|
+
case 'EINVAL': return 28 /* WasiErrno.EINVAL */;
|
|
1062
|
+
case 'EPERM': return 63 /* WasiErrno.EPERM */;
|
|
1063
|
+
case 'EPROTO': return 65 /* WasiErrno.EPROTO */;
|
|
1064
|
+
case 'EEXIST': return 20 /* WasiErrno.EEXIST */;
|
|
1065
|
+
case 'ENOTDIR': return 54 /* WasiErrno.ENOTDIR */;
|
|
1066
|
+
case 'EMFILE': return 33 /* WasiErrno.EMFILE */;
|
|
1067
|
+
case 'EACCES': return 2 /* WasiErrno.EACCES */;
|
|
1068
|
+
case 'EISDIR': return 31 /* WasiErrno.EISDIR */;
|
|
1069
|
+
case 'ENOTEMPTY': return 55 /* WasiErrno.ENOTEMPTY */;
|
|
1070
|
+
case 'ENOSYS': return 52 /* WasiErrno.ENOSYS */;
|
|
1071
|
+
}
|
|
1072
|
+
throw err;
|
|
1073
|
+
}
|
|
1074
|
+
function defineName(name, f) {
|
|
1075
|
+
Object.defineProperty(f, 'name', { value: name });
|
|
1076
|
+
return f;
|
|
1077
|
+
}
|
|
1078
|
+
function syscallWrap(self, name, f) {
|
|
1079
|
+
return defineName(name, function () {
|
|
1080
|
+
{
|
|
1081
|
+
const args = Array.prototype.slice.call(arguments);
|
|
1082
|
+
let debugArgs = [`${name}(${Array.from({ length: arguments.length }).map(() => '%d').join(', ')})`];
|
|
1083
|
+
debugArgs = debugArgs.concat(args);
|
|
1084
|
+
console.debug.apply(console, debugArgs);
|
|
1085
|
+
}
|
|
1086
|
+
let r;
|
|
1087
|
+
try {
|
|
1088
|
+
r = f.apply(self, arguments);
|
|
1089
|
+
}
|
|
1090
|
+
catch (err) {
|
|
1091
|
+
return handleError(err);
|
|
1092
|
+
}
|
|
1093
|
+
if (isPromiseLike(r)) {
|
|
1094
|
+
return r.then(_ => _, handleError);
|
|
1095
|
+
}
|
|
1096
|
+
return r;
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1099
|
+
function resolvePathSync(fs, fileDescriptor, path, flags) {
|
|
1100
|
+
let resolvedPath = resolve(fileDescriptor.realPath, path);
|
|
1101
|
+
if ((flags & 1) === 1) {
|
|
1102
|
+
try {
|
|
1103
|
+
resolvedPath = fs.readlinkSync(resolvedPath);
|
|
1104
|
+
}
|
|
1105
|
+
catch (err) {
|
|
1106
|
+
if (err.code !== 'EINVAL' && err.code !== 'ENOENT') {
|
|
1107
|
+
throw err;
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
return resolvedPath;
|
|
1112
|
+
}
|
|
1113
|
+
async function resolvePathAsync(fs, fileDescriptor, path, flags) {
|
|
1114
|
+
let resolvedPath = resolve(fileDescriptor.realPath, path);
|
|
1115
|
+
if ((flags & 1) === 1) {
|
|
1116
|
+
try {
|
|
1117
|
+
resolvedPath = await fs.promises.readlink(resolvedPath);
|
|
1118
|
+
}
|
|
1119
|
+
catch (err) {
|
|
1120
|
+
if (err.code !== 'EINVAL' && err.code !== 'ENOENT') {
|
|
1121
|
+
throw err;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
return resolvedPath;
|
|
1126
|
+
}
|
|
1127
|
+
// eslint-disable-next-line spaced-comment
|
|
1128
|
+
const encoder = /*#__PURE__*/ new TextEncoder();
|
|
1129
|
+
// eslint-disable-next-line spaced-comment
|
|
1130
|
+
const decoder = /*#__PURE__*/ new TextDecoder();
|
|
1131
|
+
const INT64_MAX = (BigInt(1) << BigInt(63)) - BigInt(1);
|
|
1132
|
+
function readStdin() {
|
|
1133
|
+
const value = window.prompt();
|
|
1134
|
+
if (value === null)
|
|
1135
|
+
return new Uint8Array();
|
|
1136
|
+
const buffer = new TextEncoder().encode(value + '\n');
|
|
1137
|
+
return buffer;
|
|
1138
|
+
}
|
|
1139
|
+
function validateFstFlagsOrReturn(flags) {
|
|
1140
|
+
return (Boolean((flags) & ~(1 /* WasiFstFlag.SET_ATIM */ | 2 /* WasiFstFlag.SET_ATIM_NOW */ |
|
|
1141
|
+
4 /* WasiFstFlag.SET_MTIM */ | 8 /* WasiFstFlag.SET_MTIM_NOW */)) ||
|
|
1142
|
+
((flags) & (1 /* WasiFstFlag.SET_ATIM */ | 2 /* WasiFstFlag.SET_ATIM_NOW */)) ===
|
|
1143
|
+
(1 /* WasiFstFlag.SET_ATIM */ | 2 /* WasiFstFlag.SET_ATIM_NOW */) ||
|
|
1144
|
+
((flags) & (4 /* WasiFstFlag.SET_MTIM */ | 8 /* WasiFstFlag.SET_MTIM_NOW */)) ===
|
|
1145
|
+
(4 /* WasiFstFlag.SET_MTIM */ | 8 /* WasiFstFlag.SET_MTIM_NOW */));
|
|
1146
|
+
}
|
|
1147
|
+
class WASI$1 {
|
|
1148
|
+
constructor(args, env, fds, asyncFs, fs, asyncify) {
|
|
1149
|
+
this.args_get = syscallWrap(this, 'args_get', function (argv, argv_buf) {
|
|
1150
|
+
argv = Number(argv);
|
|
1151
|
+
argv_buf = Number(argv_buf);
|
|
1152
|
+
if (argv === 0 || argv_buf === 0) {
|
|
1153
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1154
|
+
}
|
|
1155
|
+
const { HEAPU8, view } = getMemory(this);
|
|
1156
|
+
const wasi = _wasi.get(this);
|
|
1157
|
+
const args = wasi.args;
|
|
1158
|
+
for (let i = 0; i < args.length; ++i) {
|
|
1159
|
+
const arg = args[i];
|
|
1160
|
+
view.setInt32(argv, argv_buf, true);
|
|
1161
|
+
argv += 4;
|
|
1162
|
+
const data = encoder.encode(arg + '\0');
|
|
1163
|
+
HEAPU8.set(data, argv_buf);
|
|
1164
|
+
argv_buf += data.length;
|
|
1165
|
+
}
|
|
1166
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1167
|
+
});
|
|
1168
|
+
this.args_sizes_get = syscallWrap(this, 'args_sizes_get', function (argc, argv_buf_size) {
|
|
1169
|
+
argc = Number(argc);
|
|
1170
|
+
argv_buf_size = Number(argv_buf_size);
|
|
1171
|
+
if (argc === 0 || argv_buf_size === 0) {
|
|
1172
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1173
|
+
}
|
|
1174
|
+
const { view } = getMemory(this);
|
|
1175
|
+
const wasi = _wasi.get(this);
|
|
1176
|
+
const args = wasi.args;
|
|
1177
|
+
view.setUint32(argc, args.length, true);
|
|
1178
|
+
view.setUint32(argv_buf_size, encoder.encode(args.join('\0') + '\0').length, true);
|
|
1179
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1180
|
+
});
|
|
1181
|
+
this.environ_get = syscallWrap(this, 'environ_get', function (environ, environ_buf) {
|
|
1182
|
+
environ = Number(environ);
|
|
1183
|
+
environ_buf = Number(environ_buf);
|
|
1184
|
+
if (environ === 0 || environ_buf === 0) {
|
|
1185
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1186
|
+
}
|
|
1187
|
+
const { HEAPU8, view } = getMemory(this);
|
|
1188
|
+
const wasi = _wasi.get(this);
|
|
1189
|
+
const env = wasi.env;
|
|
1190
|
+
for (let i = 0; i < env.length; ++i) {
|
|
1191
|
+
const pair = env[i];
|
|
1192
|
+
view.setInt32(environ, environ_buf, true);
|
|
1193
|
+
environ += 4;
|
|
1194
|
+
const data = encoder.encode(pair + '\0');
|
|
1195
|
+
HEAPU8.set(data, environ_buf);
|
|
1196
|
+
environ_buf += data.length;
|
|
1197
|
+
}
|
|
1198
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1199
|
+
});
|
|
1200
|
+
this.environ_sizes_get = syscallWrap(this, 'environ_sizes_get', function (len, buflen) {
|
|
1201
|
+
len = Number(len);
|
|
1202
|
+
buflen = Number(buflen);
|
|
1203
|
+
if (len === 0 || buflen === 0) {
|
|
1204
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1205
|
+
}
|
|
1206
|
+
const { view } = getMemory(this);
|
|
1207
|
+
const wasi = _wasi.get(this);
|
|
1208
|
+
view.setUint32(len, wasi.env.length, true);
|
|
1209
|
+
view.setUint32(buflen, encoder.encode(wasi.env.join('\0') + '\0').length, true);
|
|
1210
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1211
|
+
});
|
|
1212
|
+
this.clock_res_get = syscallWrap(this, 'clock_res_get', function (id, resolution) {
|
|
1213
|
+
resolution = Number(resolution);
|
|
1214
|
+
if (resolution === 0) {
|
|
1215
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1216
|
+
}
|
|
1217
|
+
const { view } = getMemory(this);
|
|
1218
|
+
switch (id) {
|
|
1219
|
+
case 0 /* WasiClockid.REALTIME */:
|
|
1220
|
+
view.setBigUint64(resolution, BigInt(1000000), true);
|
|
1221
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1222
|
+
case 1 /* WasiClockid.MONOTONIC */:
|
|
1223
|
+
case 2 /* WasiClockid.PROCESS_CPUTIME_ID */:
|
|
1224
|
+
case 3 /* WasiClockid.THREAD_CPUTIME_ID */:
|
|
1225
|
+
view.setBigUint64(resolution, BigInt(1000), true);
|
|
1226
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1227
|
+
default: return 28 /* WasiErrno.EINVAL */;
|
|
1228
|
+
}
|
|
1229
|
+
});
|
|
1230
|
+
this.clock_time_get = syscallWrap(this, 'clock_time_get', function (id, _percision, time) {
|
|
1231
|
+
time = Number(time);
|
|
1232
|
+
if (time === 0) {
|
|
1233
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1234
|
+
}
|
|
1235
|
+
const { view } = getMemory(this);
|
|
1236
|
+
switch (id) {
|
|
1237
|
+
case 0 /* WasiClockid.REALTIME */:
|
|
1238
|
+
view.setBigUint64(time, BigInt(Date.now()) * BigInt(1000000), true);
|
|
1239
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1240
|
+
case 1 /* WasiClockid.MONOTONIC */:
|
|
1241
|
+
case 2 /* WasiClockid.PROCESS_CPUTIME_ID */:
|
|
1242
|
+
case 3 /* WasiClockid.THREAD_CPUTIME_ID */: {
|
|
1243
|
+
const t = performance.now();
|
|
1244
|
+
const s = Math.trunc(t);
|
|
1245
|
+
const ms = Math.floor((t - s) * 1000);
|
|
1246
|
+
const result = BigInt(s) * BigInt(1000000000) + BigInt(ms) * BigInt(1000000);
|
|
1247
|
+
view.setBigUint64(time, result, true);
|
|
1248
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1249
|
+
}
|
|
1250
|
+
default: return 28 /* WasiErrno.EINVAL */;
|
|
1251
|
+
}
|
|
1252
|
+
});
|
|
1253
|
+
this.fd_advise = syscallWrap(this, 'fd_advise', function (_fd, _offset, _len, _advice) {
|
|
1254
|
+
return 52 /* WasiErrno.ENOSYS */;
|
|
1255
|
+
});
|
|
1256
|
+
this.fd_fdstat_get = syscallWrap(this, 'fd_fdstat_get', function (fd, fdstat) {
|
|
1257
|
+
fdstat = Number(fdstat);
|
|
1258
|
+
if (fdstat === 0) {
|
|
1259
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1260
|
+
}
|
|
1261
|
+
const wasi = _wasi.get(this);
|
|
1262
|
+
const fileDescriptor = wasi.fds.get(fd, BigInt(0), BigInt(0));
|
|
1263
|
+
const { view } = getMemory(this);
|
|
1264
|
+
view.setUint16(fdstat, fileDescriptor.type, true);
|
|
1265
|
+
view.setUint16(fdstat + 2, 0, true);
|
|
1266
|
+
view.setBigUint64(fdstat + 8, fileDescriptor.rightsBase, true);
|
|
1267
|
+
view.setBigUint64(fdstat + 16, fileDescriptor.rightsInheriting, true);
|
|
1268
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1269
|
+
});
|
|
1270
|
+
this.fd_fdstat_set_flags = syscallWrap(this, 'fd_fdstat_set_flags', function (_fd, _flags) {
|
|
1271
|
+
return 52 /* WasiErrno.ENOSYS */;
|
|
1272
|
+
});
|
|
1273
|
+
this.fd_fdstat_set_rights = syscallWrap(this, 'fd_fdstat_set_rights', function (fd, rightsBase, rightsInheriting) {
|
|
1274
|
+
const wasi = _wasi.get(this);
|
|
1275
|
+
const fileDescriptor = wasi.fds.get(fd, BigInt(0), BigInt(0));
|
|
1276
|
+
if ((rightsBase | fileDescriptor.rightsBase) > fileDescriptor.rightsBase) {
|
|
1277
|
+
return 76 /* WasiErrno.ENOTCAPABLE */;
|
|
1278
|
+
}
|
|
1279
|
+
if ((rightsInheriting | fileDescriptor.rightsInheriting) >
|
|
1280
|
+
fileDescriptor.rightsInheriting) {
|
|
1281
|
+
return 76 /* WasiErrno.ENOTCAPABLE */;
|
|
1282
|
+
}
|
|
1283
|
+
fileDescriptor.rightsBase = rightsBase;
|
|
1284
|
+
fileDescriptor.rightsInheriting = rightsInheriting;
|
|
1285
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1286
|
+
});
|
|
1287
|
+
this.fd_prestat_get = syscallWrap(this, 'fd_prestat_get', function (fd, prestat) {
|
|
1288
|
+
prestat = Number(prestat);
|
|
1289
|
+
if (prestat === 0) {
|
|
1290
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1291
|
+
}
|
|
1292
|
+
const wasi = _wasi.get(this);
|
|
1293
|
+
let fileDescriptor;
|
|
1294
|
+
try {
|
|
1295
|
+
fileDescriptor = wasi.fds.get(fd, BigInt(0), BigInt(0));
|
|
1296
|
+
}
|
|
1297
|
+
catch (err) {
|
|
1298
|
+
if (err instanceof WasiError)
|
|
1299
|
+
return err.errno;
|
|
1300
|
+
throw err;
|
|
1301
|
+
}
|
|
1302
|
+
if (fileDescriptor.preopen !== 1)
|
|
1303
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1304
|
+
const { view } = getMemory(this);
|
|
1305
|
+
// preopen type is dir(0)
|
|
1306
|
+
view.setUint32(prestat, 0, true);
|
|
1307
|
+
view.setUint32(prestat + 4, encoder.encode(fileDescriptor.path).length, true);
|
|
1308
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1309
|
+
});
|
|
1310
|
+
this.fd_prestat_dir_name = syscallWrap(this, 'fd_prestat_dir_name', function (fd, path, path_len) {
|
|
1311
|
+
path = Number(path);
|
|
1312
|
+
path_len = Number(path_len);
|
|
1313
|
+
if (path === 0) {
|
|
1314
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1315
|
+
}
|
|
1316
|
+
const wasi = _wasi.get(this);
|
|
1317
|
+
const fileDescriptor = wasi.fds.get(fd, BigInt(0), BigInt(0));
|
|
1318
|
+
if (fileDescriptor.preopen !== 1)
|
|
1319
|
+
return 8 /* WasiErrno.EBADF */;
|
|
1320
|
+
const buffer = encoder.encode(fileDescriptor.path);
|
|
1321
|
+
const size = buffer.length;
|
|
1322
|
+
if (size > path_len)
|
|
1323
|
+
return 42 /* WasiErrno.ENOBUFS */;
|
|
1324
|
+
const { HEAPU8 } = getMemory(this);
|
|
1325
|
+
HEAPU8.set(buffer, path);
|
|
1326
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1327
|
+
});
|
|
1328
|
+
this.fd_seek = syscallWrap(this, 'fd_seek', function (fd, offset, whence, newOffset) {
|
|
1329
|
+
newOffset = Number(newOffset);
|
|
1330
|
+
if (newOffset === 0) {
|
|
1331
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1332
|
+
}
|
|
1333
|
+
if (fd === 0 || fd === 1 || fd === 2)
|
|
1334
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1335
|
+
const wasi = _wasi.get(this);
|
|
1336
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_SEEK, BigInt(0));
|
|
1337
|
+
const r = fileDescriptor.seek(offset, whence);
|
|
1338
|
+
const { view } = getMemory(this);
|
|
1339
|
+
view.setBigUint64(newOffset, r, true);
|
|
1340
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1341
|
+
});
|
|
1342
|
+
this.fd_tell = syscallWrap(this, 'fd_tell', function (fd, offset) {
|
|
1343
|
+
const wasi = _wasi.get(this);
|
|
1344
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_TELL, BigInt(0));
|
|
1345
|
+
const pos = BigInt(fileDescriptor.pos);
|
|
1346
|
+
const { view } = getMemory(this);
|
|
1347
|
+
view.setBigUint64(Number(offset), pos, true);
|
|
1348
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1349
|
+
});
|
|
1350
|
+
this.poll_oneoff = syscallWrap(this, 'poll_oneoff', function (in_ptr, out_ptr, nsubscriptions, nevents) {
|
|
1351
|
+
in_ptr = Number(in_ptr);
|
|
1352
|
+
out_ptr = Number(out_ptr);
|
|
1353
|
+
nevents = Number(nevents);
|
|
1354
|
+
nsubscriptions = Number(nsubscriptions);
|
|
1355
|
+
nsubscriptions = nsubscriptions >>> 0;
|
|
1356
|
+
if (in_ptr === 0 || out_ptr === 0 || nsubscriptions === 0 || nevents === 0) {
|
|
1357
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1358
|
+
}
|
|
1359
|
+
const { view } = getMemory(this);
|
|
1360
|
+
view.setUint32(nevents, 0, true);
|
|
1361
|
+
let i = 0;
|
|
1362
|
+
let timer_userdata = BigInt(0);
|
|
1363
|
+
let cur_timeout = BigInt(0);
|
|
1364
|
+
let has_timeout = 0;
|
|
1365
|
+
let min_timeout = BigInt(0);
|
|
1366
|
+
let sub;
|
|
1367
|
+
const subscriptions = Array(nsubscriptions);
|
|
1368
|
+
for (i = 0; i < nsubscriptions; i++) {
|
|
1369
|
+
sub = in_ptr + i * 48;
|
|
1370
|
+
const userdata = view.getBigUint64(sub, true);
|
|
1371
|
+
const type = view.getUint8(sub + 8);
|
|
1372
|
+
const clockIdOrFd = view.getUint32(sub + 16, true);
|
|
1373
|
+
const timeout = view.getBigUint64(sub + 24, true);
|
|
1374
|
+
const precision = view.getBigUint64(sub + 32, true);
|
|
1375
|
+
const flags = view.getUint16(sub + 40, true);
|
|
1376
|
+
subscriptions[i] = {
|
|
1377
|
+
userdata,
|
|
1378
|
+
type,
|
|
1379
|
+
u: {
|
|
1380
|
+
clock: {
|
|
1381
|
+
clock_id: clockIdOrFd,
|
|
1382
|
+
timeout,
|
|
1383
|
+
precision,
|
|
1384
|
+
flags
|
|
1385
|
+
},
|
|
1386
|
+
fd_readwrite: {
|
|
1387
|
+
fd: clockIdOrFd
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
};
|
|
1391
|
+
}
|
|
1392
|
+
const fdevents = [];
|
|
1393
|
+
for (i = 0; i < nsubscriptions; i++) {
|
|
1394
|
+
sub = subscriptions[i];
|
|
1395
|
+
switch (sub.type) {
|
|
1396
|
+
case 0 /* WasiEventType.CLOCK */: {
|
|
1397
|
+
if (sub.u.clock.flags === 1 /* WasiSubclockflags.ABSTIME */) {
|
|
1398
|
+
/* Convert absolute time to relative delay. */
|
|
1399
|
+
const now = BigInt(Date.now()) * BigInt(1000000);
|
|
1400
|
+
cur_timeout = sub.u.clock.timeout - now;
|
|
1401
|
+
}
|
|
1402
|
+
else {
|
|
1403
|
+
cur_timeout = sub.u.clock.timeout;
|
|
1404
|
+
}
|
|
1405
|
+
if (has_timeout === 0 || cur_timeout < min_timeout) {
|
|
1406
|
+
min_timeout = cur_timeout;
|
|
1407
|
+
timer_userdata = sub.userdata;
|
|
1408
|
+
has_timeout = 1;
|
|
1409
|
+
}
|
|
1410
|
+
break;
|
|
1411
|
+
}
|
|
1412
|
+
case 1 /* WasiEventType.FD_READ */:
|
|
1413
|
+
case 2 /* WasiEventType.FD_WRITE */:
|
|
1414
|
+
fdevents.push(sub);
|
|
1415
|
+
break;
|
|
1416
|
+
default: return 28 /* WasiErrno.EINVAL */;
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
if (fdevents.length > 0) {
|
|
1420
|
+
for (i = 0; i < fdevents.length; i++) {
|
|
1421
|
+
const fdevent = fdevents[i];
|
|
1422
|
+
const event = out_ptr + 32 * i;
|
|
1423
|
+
view.setBigUint64(event, fdevent.userdata, true);
|
|
1424
|
+
view.setUint32(event + 8, 52 /* WasiErrno.ENOSYS */, true);
|
|
1425
|
+
view.setUint32(event + 12, fdevent.type, true);
|
|
1426
|
+
view.setBigUint64(event + 16, BigInt(0), true);
|
|
1427
|
+
view.setUint16(event + 24, 0, true);
|
|
1428
|
+
view.setUint32(nevents, 1, true);
|
|
1429
|
+
}
|
|
1430
|
+
view.setUint32(nevents, fdevents.length, true);
|
|
1431
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1432
|
+
}
|
|
1433
|
+
if (has_timeout) {
|
|
1434
|
+
const delay = Number(min_timeout / BigInt(1000000));
|
|
1435
|
+
// if (isMainThread || typeof SharedArrayBuffer !== 'function') {
|
|
1436
|
+
sleepBreakIf(delay, () => false);
|
|
1437
|
+
// } else {
|
|
1438
|
+
// const buf = new SharedArrayBuffer(4)
|
|
1439
|
+
// const arr = new Int32Array(buf)
|
|
1440
|
+
// postMsg({
|
|
1441
|
+
// __tybys_wasm_util_wasi__: {
|
|
1442
|
+
// type: 'set-timeout',
|
|
1443
|
+
// payload: {
|
|
1444
|
+
// buffer: buf,
|
|
1445
|
+
// delay
|
|
1446
|
+
// }
|
|
1447
|
+
// }
|
|
1448
|
+
// })
|
|
1449
|
+
// Atomics.wait(arr, 0, 0)
|
|
1450
|
+
// }
|
|
1451
|
+
const event = out_ptr;
|
|
1452
|
+
view.setBigUint64(event, timer_userdata, true);
|
|
1453
|
+
view.setUint32(event + 8, 0 /* WasiErrno.ESUCCESS */, true);
|
|
1454
|
+
view.setUint32(event + 12, 0 /* WasiEventType.CLOCK */, true);
|
|
1455
|
+
view.setUint32(nevents, 1, true);
|
|
1456
|
+
}
|
|
1457
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1458
|
+
});
|
|
1459
|
+
this.proc_exit = syscallWrap(this, 'proc_exit', function (rval) {
|
|
1460
|
+
if ((typeof process === 'object') && (process !== null) && (typeof process.exit === 'function')) {
|
|
1461
|
+
process.exit(rval);
|
|
1462
|
+
}
|
|
1463
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1464
|
+
});
|
|
1465
|
+
this.proc_raise = syscallWrap(this, 'proc_raise', function (_sig) {
|
|
1466
|
+
return 52 /* WasiErrno.ENOSYS */;
|
|
1467
|
+
});
|
|
1468
|
+
this.sched_yield = syscallWrap(this, 'sched_yield', function () {
|
|
1469
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1470
|
+
});
|
|
1471
|
+
this.random_get = typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function'
|
|
1472
|
+
? syscallWrap(this, 'random_get', function (buf, buf_len) {
|
|
1473
|
+
buf = Number(buf);
|
|
1474
|
+
if (buf === 0) {
|
|
1475
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1476
|
+
}
|
|
1477
|
+
buf_len = Number(buf_len);
|
|
1478
|
+
const { HEAPU8, view } = getMemory(this);
|
|
1479
|
+
if ((typeof SharedArrayBuffer === 'function' && HEAPU8.buffer instanceof SharedArrayBuffer) ||
|
|
1480
|
+
(Object.prototype.toString.call(HEAPU8.buffer) === '[object SharedArrayBuffer]')) {
|
|
1481
|
+
for (let i = buf; i < buf + buf_len; ++i) {
|
|
1482
|
+
view.setUint8(i, Math.floor(Math.random() * 256));
|
|
1483
|
+
}
|
|
1484
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1485
|
+
}
|
|
1486
|
+
let pos;
|
|
1487
|
+
const stride = 65536;
|
|
1488
|
+
for (pos = 0; pos + stride < buf_len; pos += stride) {
|
|
1489
|
+
crypto.getRandomValues(HEAPU8.subarray(buf + pos, buf + pos + stride));
|
|
1490
|
+
}
|
|
1491
|
+
crypto.getRandomValues(HEAPU8.subarray(buf + pos, buf + buf_len));
|
|
1492
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1493
|
+
})
|
|
1494
|
+
: syscallWrap(this, 'random_get', function (buf, buf_len) {
|
|
1495
|
+
buf = Number(buf);
|
|
1496
|
+
if (buf === 0) {
|
|
1497
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1498
|
+
}
|
|
1499
|
+
buf_len = Number(buf_len);
|
|
1500
|
+
const { view } = getMemory(this);
|
|
1501
|
+
for (let i = buf; i < buf + buf_len; ++i) {
|
|
1502
|
+
view.setUint8(i, Math.floor(Math.random() * 256));
|
|
1503
|
+
}
|
|
1504
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1505
|
+
});
|
|
1506
|
+
this.sock_recv = syscallWrap(this, 'sock_recv', function () {
|
|
1507
|
+
return 58 /* WasiErrno.ENOTSUP */;
|
|
1508
|
+
});
|
|
1509
|
+
this.sock_send = syscallWrap(this, 'sock_send', function () {
|
|
1510
|
+
return 58 /* WasiErrno.ENOTSUP */;
|
|
1511
|
+
});
|
|
1512
|
+
this.sock_shutdown = syscallWrap(this, 'sock_shutdown', function () {
|
|
1513
|
+
return 58 /* WasiErrno.ENOTSUP */;
|
|
1514
|
+
});
|
|
1515
|
+
this.sock_accept = syscallWrap(this, 'sock_accept', function () {
|
|
1516
|
+
return 58 /* WasiErrno.ENOTSUP */;
|
|
1517
|
+
});
|
|
1518
|
+
_wasi.set(this, {
|
|
1519
|
+
fds,
|
|
1520
|
+
args,
|
|
1521
|
+
env
|
|
1522
|
+
});
|
|
1523
|
+
if (fs)
|
|
1524
|
+
_fs.set(this, fs);
|
|
1525
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
1526
|
+
const _this = this;
|
|
1527
|
+
function defineImport(name, syncVersion, asyncVersion, parameterType, returnType) {
|
|
1528
|
+
if (asyncFs) {
|
|
1529
|
+
if (asyncify) {
|
|
1530
|
+
_this[name] = asyncify.wrapImportFunction(syscallWrap(_this, name, asyncVersion));
|
|
1531
|
+
}
|
|
1532
|
+
else {
|
|
1533
|
+
_this[name] = wrapAsyncImport(syscallWrap(_this, name, asyncVersion), parameterType, returnType);
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
else {
|
|
1537
|
+
_this[name] = syscallWrap(_this, name, syncVersion);
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
defineImport('fd_allocate', function fd_allocate(fd, offset, len) {
|
|
1541
|
+
const wasi = _wasi.get(this);
|
|
1542
|
+
const fs = getFs(this);
|
|
1543
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_ALLOCATE, BigInt(0));
|
|
1544
|
+
const stat = fs.fstatSync(fileDescriptor.fd, { bigint: true });
|
|
1545
|
+
if (stat.size < offset + len) {
|
|
1546
|
+
fs.ftruncateSync(fileDescriptor.fd, Number(offset + len));
|
|
1547
|
+
}
|
|
1548
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1549
|
+
}, async function fd_allocate(fd, offset, len) {
|
|
1550
|
+
const wasi = _wasi.get(this);
|
|
1551
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_ALLOCATE, BigInt(0));
|
|
1552
|
+
const h = fileDescriptor.fd;
|
|
1553
|
+
const stat = await h.stat({ bigint: true });
|
|
1554
|
+
if (stat.size < offset + len) {
|
|
1555
|
+
await h.truncate(Number(offset + len));
|
|
1556
|
+
}
|
|
1557
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1558
|
+
}, ['i32', 'i64', 'f64'], ['i32']);
|
|
1559
|
+
defineImport('fd_close', function fd_close(fd) {
|
|
1560
|
+
const wasi = _wasi.get(this);
|
|
1561
|
+
const fileDescriptor = wasi.fds.get(fd, BigInt(0), BigInt(0));
|
|
1562
|
+
const fs = getFs(this);
|
|
1563
|
+
fs.closeSync(fileDescriptor.fd);
|
|
1564
|
+
wasi.fds.remove(fd);
|
|
1565
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1566
|
+
}, async function fd_close(fd) {
|
|
1567
|
+
const wasi = _wasi.get(this);
|
|
1568
|
+
const fileDescriptor = wasi.fds.get(fd, BigInt(0), BigInt(0));
|
|
1569
|
+
await fileDescriptor.fd.close();
|
|
1570
|
+
wasi.fds.remove(fd);
|
|
1571
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1572
|
+
}, ['i32'], ['i32']);
|
|
1573
|
+
defineImport('fd_datasync', function fd_datasync(fd) {
|
|
1574
|
+
const wasi = _wasi.get(this);
|
|
1575
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_DATASYNC, BigInt(0));
|
|
1576
|
+
const fs = getFs(this);
|
|
1577
|
+
fs.fdatasyncSync(fileDescriptor.fd);
|
|
1578
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1579
|
+
}, async function fd_datasync(fd) {
|
|
1580
|
+
const wasi = _wasi.get(this);
|
|
1581
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_DATASYNC, BigInt(0));
|
|
1582
|
+
await fileDescriptor.fd.datasync();
|
|
1583
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1584
|
+
}, ['i32'], ['i32']);
|
|
1585
|
+
defineImport('fd_filestat_get', function fd_filestat_get(fd, buf) {
|
|
1586
|
+
buf = Number(buf);
|
|
1587
|
+
if (buf === 0)
|
|
1588
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1589
|
+
const wasi = _wasi.get(this);
|
|
1590
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_FILESTAT_GET, BigInt(0));
|
|
1591
|
+
const fs = getFs(this);
|
|
1592
|
+
const stat = fs.fstatSync(fileDescriptor.fd, { bigint: true });
|
|
1593
|
+
const { view } = getMemory(this);
|
|
1594
|
+
toFileStat(view, buf, stat);
|
|
1595
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1596
|
+
}, async function fd_filestat_get(fd, buf) {
|
|
1597
|
+
buf = Number(buf);
|
|
1598
|
+
if (buf === 0)
|
|
1599
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1600
|
+
const wasi = _wasi.get(this);
|
|
1601
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_FILESTAT_GET, BigInt(0));
|
|
1602
|
+
const h = fileDescriptor.fd;
|
|
1603
|
+
const stat = await h.stat({ bigint: true });
|
|
1604
|
+
const { view } = getMemory(this);
|
|
1605
|
+
toFileStat(view, buf, stat);
|
|
1606
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1607
|
+
}, ['i32', 'i32'], ['i32']);
|
|
1608
|
+
defineImport('fd_filestat_set_size', function fd_filestat_set_size(fd, size) {
|
|
1609
|
+
const wasi = _wasi.get(this);
|
|
1610
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_FILESTAT_SET_SIZE, BigInt(0));
|
|
1611
|
+
const fs = getFs(this);
|
|
1612
|
+
fs.ftruncateSync(fileDescriptor.fd, Number(size));
|
|
1613
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1614
|
+
}, async function fd_filestat_set_size(fd, size) {
|
|
1615
|
+
const wasi = _wasi.get(this);
|
|
1616
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_FILESTAT_SET_SIZE, BigInt(0));
|
|
1617
|
+
const h = fileDescriptor.fd;
|
|
1618
|
+
await h.truncate(Number(size));
|
|
1619
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1620
|
+
}, ['i32', 'i64'], ['i32']);
|
|
1621
|
+
function fdFilestatGetTimes(fd, atim, mtim, flags) {
|
|
1622
|
+
const wasi = _wasi.get(this);
|
|
1623
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_FILESTAT_SET_TIMES, BigInt(0));
|
|
1624
|
+
if ((flags & 2 /* WasiFstFlag.SET_ATIM_NOW */) === 2 /* WasiFstFlag.SET_ATIM_NOW */) {
|
|
1625
|
+
atim = BigInt(Date.now() * 1000000);
|
|
1626
|
+
}
|
|
1627
|
+
if ((flags & 8 /* WasiFstFlag.SET_MTIM_NOW */) === 8 /* WasiFstFlag.SET_MTIM_NOW */) {
|
|
1628
|
+
mtim = BigInt(Date.now() * 1000000);
|
|
1629
|
+
}
|
|
1630
|
+
return { fileDescriptor, atim, mtim };
|
|
1631
|
+
}
|
|
1632
|
+
defineImport('fd_filestat_set_times', function fd_filestat_set_times(fd, atim, mtim, flags) {
|
|
1633
|
+
if (validateFstFlagsOrReturn(flags)) {
|
|
1634
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1635
|
+
}
|
|
1636
|
+
const { fileDescriptor, atim: atimRes, mtim: mtimRes } = fdFilestatGetTimes.call(this, fd, atim, mtim, flags);
|
|
1637
|
+
const fs = getFs(this);
|
|
1638
|
+
fs.futimesSync(fileDescriptor.fd, Number(atimRes), Number(mtimRes));
|
|
1639
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1640
|
+
}, async function fd_filestat_set_times(fd, atim, mtim, flags) {
|
|
1641
|
+
if (validateFstFlagsOrReturn(flags)) {
|
|
1642
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1643
|
+
}
|
|
1644
|
+
const { fileDescriptor, atim: atimRes, mtim: mtimRes } = fdFilestatGetTimes.call(this, fd, atim, mtim, flags);
|
|
1645
|
+
const h = fileDescriptor.fd;
|
|
1646
|
+
await h.utimes(Number(atimRes), Number(mtimRes));
|
|
1647
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1648
|
+
}, ['i32', 'i64', 'i64', 'i32'], ['i32']);
|
|
1649
|
+
defineImport('fd_pread', function fd_pread(fd, iovs, iovslen, offset, size) {
|
|
1650
|
+
iovs = Number(iovs);
|
|
1651
|
+
size = Number(size);
|
|
1652
|
+
if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
|
|
1653
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1654
|
+
}
|
|
1655
|
+
const { HEAPU8, view } = getMemory(this);
|
|
1656
|
+
const wasi = _wasi.get(this);
|
|
1657
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READ | WasiRights.FD_SEEK, BigInt(0));
|
|
1658
|
+
if (!iovslen) {
|
|
1659
|
+
view.setUint32(size, 0, true);
|
|
1660
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1661
|
+
}
|
|
1662
|
+
let totalSize = 0;
|
|
1663
|
+
const ioVecs = Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
1664
|
+
const offset = iovs + (i * 8);
|
|
1665
|
+
const buf = view.getInt32(offset, true);
|
|
1666
|
+
const bufLen = view.getUint32(offset + 4, true);
|
|
1667
|
+
totalSize += bufLen;
|
|
1668
|
+
return HEAPU8.subarray(buf, buf + bufLen);
|
|
1669
|
+
});
|
|
1670
|
+
let nread = 0;
|
|
1671
|
+
const buffer = (() => {
|
|
1672
|
+
try {
|
|
1673
|
+
return new Uint8Array(new SharedArrayBuffer(totalSize));
|
|
1674
|
+
}
|
|
1675
|
+
catch (_) {
|
|
1676
|
+
return new Uint8Array(totalSize);
|
|
1677
|
+
}
|
|
1678
|
+
})();
|
|
1679
|
+
buffer._isBuffer = true;
|
|
1680
|
+
const fs = getFs(this);
|
|
1681
|
+
const bytesRead = fs.readSync(fileDescriptor.fd, buffer, 0, buffer.length, Number(offset));
|
|
1682
|
+
nread = buffer ? copyMemory(ioVecs, buffer.subarray(0, bytesRead)) : 0;
|
|
1683
|
+
view.setUint32(size, nread, true);
|
|
1684
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1685
|
+
}, async function (fd, iovs, iovslen, offset, size) {
|
|
1686
|
+
iovs = Number(iovs);
|
|
1687
|
+
size = Number(size);
|
|
1688
|
+
if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
|
|
1689
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1690
|
+
}
|
|
1691
|
+
const { HEAPU8, view } = getMemory(this);
|
|
1692
|
+
const wasi = _wasi.get(this);
|
|
1693
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READ | WasiRights.FD_SEEK, BigInt(0));
|
|
1694
|
+
if (!iovslen) {
|
|
1695
|
+
view.setUint32(size, 0, true);
|
|
1696
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1697
|
+
}
|
|
1698
|
+
let totalSize = 0;
|
|
1699
|
+
const ioVecs = Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
1700
|
+
const offset = iovs + (i * 8);
|
|
1701
|
+
const buf = view.getInt32(offset, true);
|
|
1702
|
+
const bufLen = view.getUint32(offset + 4, true);
|
|
1703
|
+
totalSize += bufLen;
|
|
1704
|
+
return HEAPU8.subarray(buf, buf + bufLen);
|
|
1705
|
+
});
|
|
1706
|
+
let nread = 0;
|
|
1707
|
+
const buffer = new Uint8Array(totalSize);
|
|
1708
|
+
buffer._isBuffer = true;
|
|
1709
|
+
const { bytesRead } = await fileDescriptor.fd.read(buffer, 0, buffer.length, Number(offset));
|
|
1710
|
+
nread = buffer ? copyMemory(ioVecs, buffer.subarray(0, bytesRead)) : 0;
|
|
1711
|
+
view.setUint32(size, nread, true);
|
|
1712
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1713
|
+
}, ['i32', 'i32', 'i32', 'i64', 'i32'], ['i32']);
|
|
1714
|
+
defineImport('fd_pwrite', function fd_pwrite(fd, iovs, iovslen, offset, size) {
|
|
1715
|
+
iovs = Number(iovs);
|
|
1716
|
+
size = Number(size);
|
|
1717
|
+
if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
|
|
1718
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1719
|
+
}
|
|
1720
|
+
const { HEAPU8, view } = getMemory(this);
|
|
1721
|
+
const wasi = _wasi.get(this);
|
|
1722
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_WRITE | WasiRights.FD_SEEK, BigInt(0));
|
|
1723
|
+
if (!iovslen) {
|
|
1724
|
+
view.setUint32(size, 0, true);
|
|
1725
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1726
|
+
}
|
|
1727
|
+
const buffer = concatBuffer(Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
1728
|
+
const offset = iovs + (i * 8);
|
|
1729
|
+
const buf = view.getInt32(offset, true);
|
|
1730
|
+
const bufLen = view.getUint32(offset + 4, true);
|
|
1731
|
+
return HEAPU8.subarray(buf, buf + bufLen);
|
|
1732
|
+
}));
|
|
1733
|
+
const fs = getFs(this);
|
|
1734
|
+
const nwritten = fs.writeSync(fileDescriptor.fd, buffer, 0, buffer.length, Number(offset));
|
|
1735
|
+
view.setUint32(size, nwritten, true);
|
|
1736
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1737
|
+
}, async function fd_pwrite(fd, iovs, iovslen, offset, size) {
|
|
1738
|
+
iovs = Number(iovs);
|
|
1739
|
+
size = Number(size);
|
|
1740
|
+
if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
|
|
1741
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1742
|
+
}
|
|
1743
|
+
const { HEAPU8, view } = getMemory(this);
|
|
1744
|
+
const wasi = _wasi.get(this);
|
|
1745
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_WRITE | WasiRights.FD_SEEK, BigInt(0));
|
|
1746
|
+
if (!iovslen) {
|
|
1747
|
+
view.setUint32(size, 0, true);
|
|
1748
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1749
|
+
}
|
|
1750
|
+
const buffer = concatBuffer(Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
1751
|
+
const offset = iovs + (i * 8);
|
|
1752
|
+
const buf = view.getInt32(offset, true);
|
|
1753
|
+
const bufLen = view.getUint32(offset + 4, true);
|
|
1754
|
+
return HEAPU8.subarray(buf, buf + bufLen);
|
|
1755
|
+
}));
|
|
1756
|
+
const { bytesWritten } = await fileDescriptor.fd.write(buffer, 0, buffer.length, Number(offset));
|
|
1757
|
+
view.setUint32(size, bytesWritten, true);
|
|
1758
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1759
|
+
}, ['i32', 'i32', 'i32', 'i64', 'i32'], ['i32']);
|
|
1760
|
+
defineImport('fd_read', function fd_read(fd, iovs, iovslen, size) {
|
|
1761
|
+
iovs = Number(iovs);
|
|
1762
|
+
size = Number(size);
|
|
1763
|
+
if ((iovs === 0 && iovslen) || size === 0) {
|
|
1764
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1765
|
+
}
|
|
1766
|
+
const { HEAPU8, view } = getMemory(this);
|
|
1767
|
+
const wasi = _wasi.get(this);
|
|
1768
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READ, BigInt(0));
|
|
1769
|
+
if (!iovslen) {
|
|
1770
|
+
view.setUint32(size, 0, true);
|
|
1771
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1772
|
+
}
|
|
1773
|
+
let totalSize = 0;
|
|
1774
|
+
const ioVecs = Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
1775
|
+
const offset = iovs + (i * 8);
|
|
1776
|
+
const buf = view.getInt32(offset, true);
|
|
1777
|
+
const bufLen = view.getUint32(offset + 4, true);
|
|
1778
|
+
totalSize += bufLen;
|
|
1779
|
+
return HEAPU8.subarray(buf, buf + bufLen);
|
|
1780
|
+
});
|
|
1781
|
+
let buffer;
|
|
1782
|
+
let nread = 0;
|
|
1783
|
+
if (fd === 0) {
|
|
1784
|
+
if (typeof window === 'undefined' || typeof window.prompt !== 'function') {
|
|
1785
|
+
return 58 /* WasiErrno.ENOTSUP */;
|
|
1786
|
+
}
|
|
1787
|
+
buffer = readStdin();
|
|
1788
|
+
nread = buffer ? copyMemory(ioVecs, buffer) : 0;
|
|
1789
|
+
}
|
|
1790
|
+
else {
|
|
1791
|
+
buffer = (() => {
|
|
1792
|
+
try {
|
|
1793
|
+
return new Uint8Array(new SharedArrayBuffer(totalSize));
|
|
1794
|
+
}
|
|
1795
|
+
catch (_) {
|
|
1796
|
+
return new Uint8Array(totalSize);
|
|
1797
|
+
}
|
|
1798
|
+
})();
|
|
1799
|
+
buffer._isBuffer = true;
|
|
1800
|
+
const fs = getFs(this);
|
|
1801
|
+
const bytesRead = fs.readSync(fileDescriptor.fd, buffer, 0, buffer.length, Number(fileDescriptor.pos));
|
|
1802
|
+
nread = buffer ? copyMemory(ioVecs, buffer.subarray(0, bytesRead)) : 0;
|
|
1803
|
+
fileDescriptor.pos += BigInt(nread);
|
|
1804
|
+
}
|
|
1805
|
+
view.setUint32(size, nread, true);
|
|
1806
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1807
|
+
}, async function fd_read(fd, iovs, iovslen, size) {
|
|
1808
|
+
iovs = Number(iovs);
|
|
1809
|
+
size = Number(size);
|
|
1810
|
+
if ((iovs === 0 && iovslen) || size === 0) {
|
|
1811
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1812
|
+
}
|
|
1813
|
+
const { HEAPU8, view } = getMemory(this);
|
|
1814
|
+
const wasi = _wasi.get(this);
|
|
1815
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READ, BigInt(0));
|
|
1816
|
+
if (!iovslen) {
|
|
1817
|
+
view.setUint32(size, 0, true);
|
|
1818
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1819
|
+
}
|
|
1820
|
+
let totalSize = 0;
|
|
1821
|
+
const ioVecs = Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
1822
|
+
const offset = iovs + (i * 8);
|
|
1823
|
+
const buf = view.getInt32(offset, true);
|
|
1824
|
+
const bufLen = view.getUint32(offset + 4, true);
|
|
1825
|
+
totalSize += bufLen;
|
|
1826
|
+
return HEAPU8.subarray(buf, buf + bufLen);
|
|
1827
|
+
});
|
|
1828
|
+
let buffer;
|
|
1829
|
+
let nread = 0;
|
|
1830
|
+
if (fd === 0) {
|
|
1831
|
+
if (typeof window === 'undefined' || typeof window.prompt !== 'function') {
|
|
1832
|
+
return 58 /* WasiErrno.ENOTSUP */;
|
|
1833
|
+
}
|
|
1834
|
+
buffer = readStdin();
|
|
1835
|
+
nread = buffer ? copyMemory(ioVecs, buffer) : 0;
|
|
1836
|
+
}
|
|
1837
|
+
else {
|
|
1838
|
+
buffer = new Uint8Array(totalSize);
|
|
1839
|
+
buffer._isBuffer = true;
|
|
1840
|
+
const { bytesRead } = await fileDescriptor.fd.read(buffer, 0, buffer.length, Number(fileDescriptor.pos));
|
|
1841
|
+
nread = buffer ? copyMemory(ioVecs, buffer.subarray(0, bytesRead)) : 0;
|
|
1842
|
+
fileDescriptor.pos += BigInt(nread);
|
|
1843
|
+
}
|
|
1844
|
+
view.setUint32(size, nread, true);
|
|
1845
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1846
|
+
}, ['i32', 'i32', 'i32', 'i32'], ['i32']);
|
|
1847
|
+
defineImport('fd_readdir', function fd_readdir(fd, buf, buf_len, cookie, bufused) {
|
|
1848
|
+
buf = Number(buf);
|
|
1849
|
+
buf_len = Number(buf_len);
|
|
1850
|
+
bufused = Number(bufused);
|
|
1851
|
+
if (buf === 0 || bufused === 0)
|
|
1852
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1853
|
+
const wasi = _wasi.get(this);
|
|
1854
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READDIR, BigInt(0));
|
|
1855
|
+
const fs = getFs(this);
|
|
1856
|
+
const entries = fs.readdirSync(fileDescriptor.realPath, { withFileTypes: true });
|
|
1857
|
+
const { HEAPU8, view } = getMemory(this);
|
|
1858
|
+
let bufferUsed = 0;
|
|
1859
|
+
for (let i = Number(cookie); i < entries.length; i++) {
|
|
1860
|
+
const nameData = encoder.encode(entries[i].name);
|
|
1861
|
+
const entryInfo = fs.statSync(resolve(fileDescriptor.realPath, entries[i].name), { bigint: true });
|
|
1862
|
+
const entryData = new Uint8Array(24 + nameData.byteLength);
|
|
1863
|
+
const entryView = new DataView(entryData.buffer);
|
|
1864
|
+
entryView.setBigUint64(0, BigInt(i + 1), true);
|
|
1865
|
+
entryView.setBigUint64(8, BigInt(entryInfo.ino ? entryInfo.ino : 0), true);
|
|
1866
|
+
entryView.setUint32(16, nameData.byteLength, true);
|
|
1867
|
+
let type;
|
|
1868
|
+
if (entries[i].isFile()) {
|
|
1869
|
+
type = 4 /* WasiFileType.REGULAR_FILE */;
|
|
1870
|
+
}
|
|
1871
|
+
else if (entries[i].isDirectory()) {
|
|
1872
|
+
type = 3 /* WasiFileType.DIRECTORY */;
|
|
1873
|
+
}
|
|
1874
|
+
else if (entries[i].isSymbolicLink()) {
|
|
1875
|
+
type = 7 /* WasiFileType.SYMBOLIC_LINK */;
|
|
1876
|
+
}
|
|
1877
|
+
else if (entries[i].isCharacterDevice()) {
|
|
1878
|
+
type = 2 /* WasiFileType.CHARACTER_DEVICE */;
|
|
1879
|
+
}
|
|
1880
|
+
else if (entries[i].isBlockDevice()) {
|
|
1881
|
+
type = 1 /* WasiFileType.BLOCK_DEVICE */;
|
|
1882
|
+
}
|
|
1883
|
+
else if (entries[i].isSocket()) {
|
|
1884
|
+
type = 6 /* WasiFileType.SOCKET_STREAM */;
|
|
1885
|
+
}
|
|
1886
|
+
else {
|
|
1887
|
+
type = 0 /* WasiFileType.UNKNOWN */;
|
|
1888
|
+
}
|
|
1889
|
+
entryView.setUint8(20, type);
|
|
1890
|
+
entryData.set(nameData, 24);
|
|
1891
|
+
const data = entryData.slice(0, Math.min(entryData.length, buf_len - bufferUsed));
|
|
1892
|
+
HEAPU8.set(data, buf + bufferUsed);
|
|
1893
|
+
bufferUsed += data.byteLength;
|
|
1894
|
+
}
|
|
1895
|
+
view.setUint32(bufused, bufferUsed, true);
|
|
1896
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1897
|
+
}, async function fd_readdir(fd, buf, buf_len, cookie, bufused) {
|
|
1898
|
+
buf = Number(buf);
|
|
1899
|
+
buf_len = Number(buf_len);
|
|
1900
|
+
bufused = Number(bufused);
|
|
1901
|
+
if (buf === 0 || bufused === 0)
|
|
1902
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1903
|
+
const wasi = _wasi.get(this);
|
|
1904
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READDIR, BigInt(0));
|
|
1905
|
+
const fs = getFs(this);
|
|
1906
|
+
const entries = await fs.promises.readdir(fileDescriptor.realPath, { withFileTypes: true });
|
|
1907
|
+
const { HEAPU8, view } = getMemory(this);
|
|
1908
|
+
let bufferUsed = 0;
|
|
1909
|
+
for (let i = Number(cookie); i < entries.length; i++) {
|
|
1910
|
+
const nameData = encoder.encode(entries[i].name);
|
|
1911
|
+
const entryInfo = await fs.promises.stat(resolve(fileDescriptor.realPath, entries[i].name), { bigint: true });
|
|
1912
|
+
const entryData = new Uint8Array(24 + nameData.byteLength);
|
|
1913
|
+
const entryView = new DataView(entryData.buffer);
|
|
1914
|
+
entryView.setBigUint64(0, BigInt(i + 1), true);
|
|
1915
|
+
entryView.setBigUint64(8, BigInt(entryInfo.ino ? entryInfo.ino : 0), true);
|
|
1916
|
+
entryView.setUint32(16, nameData.byteLength, true);
|
|
1917
|
+
let type;
|
|
1918
|
+
if (entries[i].isFile()) {
|
|
1919
|
+
type = 4 /* WasiFileType.REGULAR_FILE */;
|
|
1920
|
+
}
|
|
1921
|
+
else if (entries[i].isDirectory()) {
|
|
1922
|
+
type = 3 /* WasiFileType.DIRECTORY */;
|
|
1923
|
+
}
|
|
1924
|
+
else if (entries[i].isSymbolicLink()) {
|
|
1925
|
+
type = 7 /* WasiFileType.SYMBOLIC_LINK */;
|
|
1926
|
+
}
|
|
1927
|
+
else if (entries[i].isCharacterDevice()) {
|
|
1928
|
+
type = 2 /* WasiFileType.CHARACTER_DEVICE */;
|
|
1929
|
+
}
|
|
1930
|
+
else if (entries[i].isBlockDevice()) {
|
|
1931
|
+
type = 1 /* WasiFileType.BLOCK_DEVICE */;
|
|
1932
|
+
}
|
|
1933
|
+
else if (entries[i].isSocket()) {
|
|
1934
|
+
type = 6 /* WasiFileType.SOCKET_STREAM */;
|
|
1935
|
+
}
|
|
1936
|
+
else {
|
|
1937
|
+
type = 0 /* WasiFileType.UNKNOWN */;
|
|
1938
|
+
}
|
|
1939
|
+
entryView.setUint8(20, type);
|
|
1940
|
+
entryData.set(nameData, 24);
|
|
1941
|
+
const data = entryData.slice(0, Math.min(entryData.length, buf_len - bufferUsed));
|
|
1942
|
+
HEAPU8.set(data, buf + bufferUsed);
|
|
1943
|
+
bufferUsed += data.byteLength;
|
|
1944
|
+
}
|
|
1945
|
+
view.setUint32(bufused, bufferUsed, true);
|
|
1946
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1947
|
+
}, ['i32', 'i32', 'i32', 'i64', 'i32'], ['i32']);
|
|
1948
|
+
defineImport('fd_renumber', function fd_renumber(from, to) {
|
|
1949
|
+
const wasi = _wasi.get(this);
|
|
1950
|
+
wasi.fds.renumber(to, from);
|
|
1951
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1952
|
+
}, async function fd_renumber(from, to) {
|
|
1953
|
+
const wasi = _wasi.get(this);
|
|
1954
|
+
await wasi.fds.renumber(to, from);
|
|
1955
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1956
|
+
}, ['i32', 'i32'], ['i32']);
|
|
1957
|
+
defineImport('fd_sync', function fd_sync(fd) {
|
|
1958
|
+
const wasi = _wasi.get(this);
|
|
1959
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_SYNC, BigInt(0));
|
|
1960
|
+
const fs = getFs(this);
|
|
1961
|
+
fs.fsyncSync(fileDescriptor.fd);
|
|
1962
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1963
|
+
}, async function fd_sync(fd) {
|
|
1964
|
+
const wasi = _wasi.get(this);
|
|
1965
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_SYNC, BigInt(0));
|
|
1966
|
+
await fileDescriptor.fd.sync();
|
|
1967
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1968
|
+
}, ['i32'], ['i32']);
|
|
1969
|
+
defineImport('fd_write', function fd_write(fd, iovs, iovslen, size) {
|
|
1970
|
+
iovs = Number(iovs);
|
|
1971
|
+
size = Number(size);
|
|
1972
|
+
if ((iovs === 0 && iovslen) || size === 0) {
|
|
1973
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
1974
|
+
}
|
|
1975
|
+
const { HEAPU8, view } = getMemory(this);
|
|
1976
|
+
const wasi = _wasi.get(this);
|
|
1977
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_WRITE, BigInt(0));
|
|
1978
|
+
if (!iovslen) {
|
|
1979
|
+
view.setUint32(size, 0, true);
|
|
1980
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1981
|
+
}
|
|
1982
|
+
const buffer = concatBuffer(Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
1983
|
+
const offset = iovs + (i * 8);
|
|
1984
|
+
const buf = view.getInt32(offset, true);
|
|
1985
|
+
const bufLen = view.getUint32(offset + 4, true);
|
|
1986
|
+
return HEAPU8.subarray(buf, buf + bufLen);
|
|
1987
|
+
}));
|
|
1988
|
+
let nwritten;
|
|
1989
|
+
if (fd === 1 || fd === 2) {
|
|
1990
|
+
nwritten = fileDescriptor.write(buffer);
|
|
1991
|
+
}
|
|
1992
|
+
else {
|
|
1993
|
+
const fs = getFs(this);
|
|
1994
|
+
nwritten = fs.writeSync(fileDescriptor.fd, buffer, 0, buffer.length, Number(fileDescriptor.pos));
|
|
1995
|
+
fileDescriptor.pos += BigInt(nwritten);
|
|
1996
|
+
}
|
|
1997
|
+
view.setUint32(size, nwritten, true);
|
|
1998
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
1999
|
+
}, async function fd_write(fd, iovs, iovslen, size) {
|
|
2000
|
+
iovs = Number(iovs);
|
|
2001
|
+
size = Number(size);
|
|
2002
|
+
if ((iovs === 0 && iovslen) || size === 0) {
|
|
2003
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2004
|
+
}
|
|
2005
|
+
const { HEAPU8, view } = getMemory(this);
|
|
2006
|
+
const wasi = _wasi.get(this);
|
|
2007
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_WRITE, BigInt(0));
|
|
2008
|
+
if (!iovslen) {
|
|
2009
|
+
view.setUint32(size, 0, true);
|
|
2010
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2011
|
+
}
|
|
2012
|
+
const buffer = concatBuffer(Array.from({ length: Number(iovslen) }, (_, i) => {
|
|
2013
|
+
const offset = iovs + (i * 8);
|
|
2014
|
+
const buf = view.getInt32(offset, true);
|
|
2015
|
+
const bufLen = view.getUint32(offset + 4, true);
|
|
2016
|
+
return HEAPU8.subarray(buf, buf + bufLen);
|
|
2017
|
+
}));
|
|
2018
|
+
let nwritten;
|
|
2019
|
+
if (fd === 1 || fd === 2) {
|
|
2020
|
+
nwritten = fileDescriptor.write(buffer);
|
|
2021
|
+
}
|
|
2022
|
+
else {
|
|
2023
|
+
nwritten = await (await (fileDescriptor.fd.write(buffer, 0, buffer.length, Number(fileDescriptor.pos)))).bytesWritten;
|
|
2024
|
+
fileDescriptor.pos += BigInt(nwritten);
|
|
2025
|
+
}
|
|
2026
|
+
view.setUint32(size, nwritten, true);
|
|
2027
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2028
|
+
}, ['i32', 'i32', 'i32', 'i32'], ['i32']);
|
|
2029
|
+
defineImport('path_create_directory', function path_create_directory(fd, path, path_len) {
|
|
2030
|
+
path = Number(path);
|
|
2031
|
+
path_len = Number(path_len);
|
|
2032
|
+
if (path === 0) {
|
|
2033
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2034
|
+
}
|
|
2035
|
+
const { HEAPU8 } = getMemory(this);
|
|
2036
|
+
const wasi = _wasi.get(this);
|
|
2037
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_CREATE_DIRECTORY, BigInt(0));
|
|
2038
|
+
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
2039
|
+
pathString = resolve(fileDescriptor.realPath, pathString);
|
|
2040
|
+
const fs = getFs(this);
|
|
2041
|
+
fs.mkdirSync(pathString);
|
|
2042
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2043
|
+
}, async function path_create_directory(fd, path, path_len) {
|
|
2044
|
+
path = Number(path);
|
|
2045
|
+
path_len = Number(path_len);
|
|
2046
|
+
if (path === 0) {
|
|
2047
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2048
|
+
}
|
|
2049
|
+
const { HEAPU8 } = getMemory(this);
|
|
2050
|
+
const wasi = _wasi.get(this);
|
|
2051
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_CREATE_DIRECTORY, BigInt(0));
|
|
2052
|
+
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
2053
|
+
pathString = resolve(fileDescriptor.realPath, pathString);
|
|
2054
|
+
const fs = getFs(this);
|
|
2055
|
+
await fs.promises.mkdir(pathString);
|
|
2056
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2057
|
+
}, ['i32', 'i32', 'i32'], ['i32']);
|
|
2058
|
+
defineImport('path_filestat_get', function path_filestat_get(fd, flags, path, path_len, filestat) {
|
|
2059
|
+
path = Number(path);
|
|
2060
|
+
path_len = Number(path_len);
|
|
2061
|
+
filestat = Number(filestat);
|
|
2062
|
+
if (path === 0 || filestat === 0) {
|
|
2063
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2064
|
+
}
|
|
2065
|
+
const { HEAPU8, view } = getMemory(this);
|
|
2066
|
+
const wasi = _wasi.get(this);
|
|
2067
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_FILESTAT_GET, BigInt(0));
|
|
2068
|
+
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
2069
|
+
const fs = getFs(this);
|
|
2070
|
+
pathString = resolve(fileDescriptor.realPath, pathString);
|
|
2071
|
+
let stat;
|
|
2072
|
+
if ((flags & 1) === 1) {
|
|
2073
|
+
stat = fs.statSync(pathString, { bigint: true });
|
|
2074
|
+
}
|
|
2075
|
+
else {
|
|
2076
|
+
stat = fs.lstatSync(pathString, { bigint: true });
|
|
2077
|
+
}
|
|
2078
|
+
toFileStat(view, filestat, stat);
|
|
2079
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2080
|
+
}, async function path_filestat_get(fd, flags, path, path_len, filestat) {
|
|
2081
|
+
path = Number(path);
|
|
2082
|
+
path_len = Number(path_len);
|
|
2083
|
+
filestat = Number(filestat);
|
|
2084
|
+
if (path === 0 || filestat === 0) {
|
|
2085
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2086
|
+
}
|
|
2087
|
+
const { HEAPU8, view } = getMemory(this);
|
|
2088
|
+
const wasi = _wasi.get(this);
|
|
2089
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_FILESTAT_GET, BigInt(0));
|
|
2090
|
+
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
2091
|
+
const fs = getFs(this);
|
|
2092
|
+
pathString = resolve(fileDescriptor.realPath, pathString);
|
|
2093
|
+
let stat;
|
|
2094
|
+
if ((flags & 1) === 1) {
|
|
2095
|
+
stat = await fs.promises.stat(pathString, { bigint: true });
|
|
2096
|
+
}
|
|
2097
|
+
else {
|
|
2098
|
+
stat = await fs.promises.lstat(pathString, { bigint: true });
|
|
2099
|
+
}
|
|
2100
|
+
toFileStat(view, filestat, stat);
|
|
2101
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2102
|
+
}, ['i32', 'i32', 'i32', 'i32', 'i32'], ['i32']);
|
|
2103
|
+
defineImport('path_filestat_set_times', function path_filestat_set_times(fd, flags, path, path_len, atim, mtim, fst_flags) {
|
|
2104
|
+
path = Number(path);
|
|
2105
|
+
path_len = Number(path_len);
|
|
2106
|
+
if (path === 0)
|
|
2107
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2108
|
+
const { HEAPU8 } = getMemory(this);
|
|
2109
|
+
const wasi = _wasi.get(this);
|
|
2110
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_FILESTAT_SET_TIMES, BigInt(0));
|
|
2111
|
+
if (validateFstFlagsOrReturn(fst_flags)) {
|
|
2112
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2113
|
+
}
|
|
2114
|
+
const fs = getFs(this);
|
|
2115
|
+
const resolvedPath = resolvePathSync(fs, fileDescriptor, decoder.decode(unsharedSlice(HEAPU8, path, path + path_len)), flags);
|
|
2116
|
+
if ((fst_flags & 2 /* WasiFstFlag.SET_ATIM_NOW */) === 2 /* WasiFstFlag.SET_ATIM_NOW */) {
|
|
2117
|
+
atim = BigInt(Date.now() * 1000000);
|
|
2118
|
+
}
|
|
2119
|
+
if ((fst_flags & 8 /* WasiFstFlag.SET_MTIM_NOW */) === 8 /* WasiFstFlag.SET_MTIM_NOW */) {
|
|
2120
|
+
mtim = BigInt(Date.now() * 1000000);
|
|
2121
|
+
}
|
|
2122
|
+
fs.utimesSync(resolvedPath, Number(atim), Number(mtim));
|
|
2123
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2124
|
+
}, async function path_filestat_set_times(fd, flags, path, path_len, atim, mtim, fst_flags) {
|
|
2125
|
+
path = Number(path);
|
|
2126
|
+
path_len = Number(path_len);
|
|
2127
|
+
if (path === 0)
|
|
2128
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2129
|
+
const { HEAPU8 } = getMemory(this);
|
|
2130
|
+
const wasi = _wasi.get(this);
|
|
2131
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_FILESTAT_SET_TIMES, BigInt(0));
|
|
2132
|
+
if (validateFstFlagsOrReturn(fst_flags)) {
|
|
2133
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2134
|
+
}
|
|
2135
|
+
const fs = getFs(this);
|
|
2136
|
+
const resolvedPath = await resolvePathAsync(fs, fileDescriptor, decoder.decode(unsharedSlice(HEAPU8, path, path + path_len)), flags);
|
|
2137
|
+
if ((fst_flags & 2 /* WasiFstFlag.SET_ATIM_NOW */) === 2 /* WasiFstFlag.SET_ATIM_NOW */) {
|
|
2138
|
+
atim = BigInt(Date.now() * 1000000);
|
|
2139
|
+
}
|
|
2140
|
+
if ((fst_flags & 8 /* WasiFstFlag.SET_MTIM_NOW */) === 8 /* WasiFstFlag.SET_MTIM_NOW */) {
|
|
2141
|
+
mtim = BigInt(Date.now() * 1000000);
|
|
2142
|
+
}
|
|
2143
|
+
await fs.promises.utimes(resolvedPath, Number(atim), Number(mtim));
|
|
2144
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2145
|
+
}, ['i32', 'i32', 'i32', 'i32', 'i64', 'i64', 'i32'], ['i32']);
|
|
2146
|
+
defineImport('path_link', function path_link(old_fd, old_flags, old_path, old_path_len, new_fd, new_path, new_path_len) {
|
|
2147
|
+
old_path = Number(old_path);
|
|
2148
|
+
old_path_len = Number(old_path_len);
|
|
2149
|
+
new_path = Number(new_path);
|
|
2150
|
+
new_path_len = Number(new_path_len);
|
|
2151
|
+
if (old_path === 0 || new_path === 0) {
|
|
2152
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2153
|
+
}
|
|
2154
|
+
const wasi = _wasi.get(this);
|
|
2155
|
+
let oldWrap;
|
|
2156
|
+
let newWrap;
|
|
2157
|
+
if (old_fd === new_fd) {
|
|
2158
|
+
oldWrap = newWrap = wasi.fds.get(old_fd, WasiRights.PATH_LINK_SOURCE | WasiRights.PATH_LINK_TARGET, BigInt(0));
|
|
2159
|
+
}
|
|
2160
|
+
else {
|
|
2161
|
+
oldWrap = wasi.fds.get(old_fd, WasiRights.PATH_LINK_SOURCE, BigInt(0));
|
|
2162
|
+
newWrap = wasi.fds.get(new_fd, WasiRights.PATH_LINK_TARGET, BigInt(0));
|
|
2163
|
+
}
|
|
2164
|
+
const { HEAPU8 } = getMemory(this);
|
|
2165
|
+
const fs = getFs(this);
|
|
2166
|
+
const resolvedOldPath = resolvePathSync(fs, oldWrap, decoder.decode(unsharedSlice(HEAPU8, old_path, old_path + old_path_len)), old_flags);
|
|
2167
|
+
const resolvedNewPath = resolve(newWrap.realPath, decoder.decode(unsharedSlice(HEAPU8, new_path, new_path + new_path_len)));
|
|
2168
|
+
fs.linkSync(resolvedOldPath, resolvedNewPath);
|
|
2169
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2170
|
+
}, async function path_link(old_fd, old_flags, old_path, old_path_len, new_fd, new_path, new_path_len) {
|
|
2171
|
+
old_path = Number(old_path);
|
|
2172
|
+
old_path_len = Number(old_path_len);
|
|
2173
|
+
new_path = Number(new_path);
|
|
2174
|
+
new_path_len = Number(new_path_len);
|
|
2175
|
+
if (old_path === 0 || new_path === 0) {
|
|
2176
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2177
|
+
}
|
|
2178
|
+
const wasi = _wasi.get(this);
|
|
2179
|
+
let oldWrap;
|
|
2180
|
+
let newWrap;
|
|
2181
|
+
if (old_fd === new_fd) {
|
|
2182
|
+
oldWrap = newWrap = wasi.fds.get(old_fd, WasiRights.PATH_LINK_SOURCE | WasiRights.PATH_LINK_TARGET, BigInt(0));
|
|
2183
|
+
}
|
|
2184
|
+
else {
|
|
2185
|
+
oldWrap = wasi.fds.get(old_fd, WasiRights.PATH_LINK_SOURCE, BigInt(0));
|
|
2186
|
+
newWrap = wasi.fds.get(new_fd, WasiRights.PATH_LINK_TARGET, BigInt(0));
|
|
2187
|
+
}
|
|
2188
|
+
const { HEAPU8 } = getMemory(this);
|
|
2189
|
+
const fs = getFs(this);
|
|
2190
|
+
const resolvedOldPath = await resolvePathAsync(fs, oldWrap, decoder.decode(unsharedSlice(HEAPU8, old_path, old_path + old_path_len)), old_flags);
|
|
2191
|
+
const resolvedNewPath = resolve(newWrap.realPath, decoder.decode(unsharedSlice(HEAPU8, new_path, new_path + new_path_len)));
|
|
2192
|
+
await fs.promises.link(resolvedOldPath, resolvedNewPath);
|
|
2193
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2194
|
+
}, ['i32', 'i32', 'i32', 'i32', 'i32', 'i32', 'i32'], ['i32']);
|
|
2195
|
+
function pathOpen(o_flags, fs_rights_base, fs_rights_inheriting, fs_flags) {
|
|
2196
|
+
const read = (fs_rights_base & (WasiRights.FD_READ |
|
|
2197
|
+
WasiRights.FD_READDIR)) !== BigInt(0);
|
|
2198
|
+
const write = (fs_rights_base & (WasiRights.FD_DATASYNC |
|
|
2199
|
+
WasiRights.FD_WRITE |
|
|
2200
|
+
WasiRights.FD_ALLOCATE |
|
|
2201
|
+
WasiRights.FD_FILESTAT_SET_SIZE)) !== BigInt(0);
|
|
2202
|
+
let flags = write ? read ? 2 /* FileControlFlag.O_RDWR */ : 1 /* FileControlFlag.O_WRONLY */ : 0 /* FileControlFlag.O_RDONLY */;
|
|
2203
|
+
let needed_base = WasiRights.PATH_OPEN;
|
|
2204
|
+
let needed_inheriting = fs_rights_base | fs_rights_inheriting;
|
|
2205
|
+
if ((o_flags & 1 /* WasiFileControlFlag.O_CREAT */) !== 0) {
|
|
2206
|
+
flags |= 64 /* FileControlFlag.O_CREAT */;
|
|
2207
|
+
needed_base |= WasiRights.PATH_CREATE_FILE;
|
|
2208
|
+
}
|
|
2209
|
+
if ((o_flags & 2 /* WasiFileControlFlag.O_DIRECTORY */) !== 0) {
|
|
2210
|
+
flags |= 65536 /* FileControlFlag.O_DIRECTORY */;
|
|
2211
|
+
}
|
|
2212
|
+
if ((o_flags & 4 /* WasiFileControlFlag.O_EXCL */) !== 0) {
|
|
2213
|
+
flags |= 128 /* FileControlFlag.O_EXCL */;
|
|
2214
|
+
}
|
|
2215
|
+
if ((o_flags & 8 /* WasiFileControlFlag.O_TRUNC */) !== 0) {
|
|
2216
|
+
flags |= 512 /* FileControlFlag.O_TRUNC */;
|
|
2217
|
+
needed_base |= WasiRights.PATH_FILESTAT_SET_SIZE;
|
|
2218
|
+
}
|
|
2219
|
+
if ((fs_flags & 1 /* WasiFdFlag.APPEND */) !== 0) {
|
|
2220
|
+
flags |= 1024 /* FileControlFlag.O_APPEND */;
|
|
2221
|
+
}
|
|
2222
|
+
if ((fs_flags & 2 /* WasiFdFlag.DSYNC */) !== 0) {
|
|
2223
|
+
// flags |= FileControlFlag.O_DSYNC;
|
|
2224
|
+
needed_inheriting |= WasiRights.FD_DATASYNC;
|
|
2225
|
+
}
|
|
2226
|
+
if ((fs_flags & 4 /* WasiFdFlag.NONBLOCK */) !== 0) {
|
|
2227
|
+
flags |= 2048 /* FileControlFlag.O_NONBLOCK */;
|
|
2228
|
+
}
|
|
2229
|
+
if ((fs_flags & 8 /* WasiFdFlag.RSYNC */) !== 0) {
|
|
2230
|
+
flags |= 1052672 /* FileControlFlag.O_SYNC */;
|
|
2231
|
+
needed_inheriting |= WasiRights.FD_SYNC;
|
|
2232
|
+
}
|
|
2233
|
+
if ((fs_flags & 16 /* WasiFdFlag.SYNC */) !== 0) {
|
|
2234
|
+
flags |= 1052672 /* FileControlFlag.O_SYNC */;
|
|
2235
|
+
needed_inheriting |= WasiRights.FD_SYNC;
|
|
2236
|
+
}
|
|
2237
|
+
if (write && (flags & (1024 /* FileControlFlag.O_APPEND */ | 512 /* FileControlFlag.O_TRUNC */)) === 0) {
|
|
2238
|
+
needed_inheriting |= WasiRights.FD_SEEK;
|
|
2239
|
+
}
|
|
2240
|
+
return { flags, needed_base, needed_inheriting };
|
|
2241
|
+
}
|
|
2242
|
+
defineImport('path_open', function path_open(dirfd, dirflags, path, path_len, o_flags, fs_rights_base, fs_rights_inheriting, fs_flags, fd) {
|
|
2243
|
+
path = Number(path);
|
|
2244
|
+
fd = Number(fd);
|
|
2245
|
+
if (path === 0 || fd === 0) {
|
|
2246
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2247
|
+
}
|
|
2248
|
+
path_len = Number(path_len);
|
|
2249
|
+
fs_rights_base = BigInt(fs_rights_base);
|
|
2250
|
+
fs_rights_inheriting = BigInt(fs_rights_inheriting);
|
|
2251
|
+
const { flags: flagsRes, needed_base: neededBase, needed_inheriting: neededInheriting } = pathOpen(o_flags, fs_rights_base, fs_rights_inheriting, fs_flags);
|
|
2252
|
+
const wasi = _wasi.get(this);
|
|
2253
|
+
const fileDescriptor = wasi.fds.get(dirfd, neededBase, neededInheriting);
|
|
2254
|
+
const memory = getMemory(this);
|
|
2255
|
+
const HEAPU8 = memory.HEAPU8;
|
|
2256
|
+
const pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
2257
|
+
const fs = getFs(this);
|
|
2258
|
+
const resolved_path = resolvePathSync(fs, fileDescriptor, pathString, dirflags);
|
|
2259
|
+
const r = fs.openSync(resolved_path, flagsRes, 0o666);
|
|
2260
|
+
const filetype = wasi.fds.getFileTypeByFd(r);
|
|
2261
|
+
if ((o_flags & 2 /* WasiFileControlFlag.O_DIRECTORY */) !== 0 && filetype !== 3 /* WasiFileType.DIRECTORY */) {
|
|
2262
|
+
return 54 /* WasiErrno.ENOTDIR */;
|
|
2263
|
+
}
|
|
2264
|
+
const { base: max_base, inheriting: max_inheriting } = getRights(wasi.fds.stdio, r, flagsRes, filetype);
|
|
2265
|
+
const wrap = wasi.fds.insert(r, resolved_path, resolved_path, filetype, fs_rights_base & max_base, fs_rights_inheriting & max_inheriting, 0);
|
|
2266
|
+
const stat = fs.fstatSync(r, { bigint: true });
|
|
2267
|
+
if (stat.isFile()) {
|
|
2268
|
+
wrap.size = stat.size;
|
|
2269
|
+
if ((flagsRes & 1024 /* FileControlFlag.O_APPEND */) !== 0) {
|
|
2270
|
+
wrap.pos = stat.size;
|
|
2271
|
+
}
|
|
2272
|
+
}
|
|
2273
|
+
const view = memory.view;
|
|
2274
|
+
view.setInt32(fd, wrap.id, true);
|
|
2275
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2276
|
+
}, async function path_open(dirfd, dirflags, path, path_len, o_flags, fs_rights_base, fs_rights_inheriting, fs_flags, fd) {
|
|
2277
|
+
path = Number(path);
|
|
2278
|
+
fd = Number(fd);
|
|
2279
|
+
if (path === 0 || fd === 0) {
|
|
2280
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2281
|
+
}
|
|
2282
|
+
path_len = Number(path_len);
|
|
2283
|
+
fs_rights_base = BigInt(fs_rights_base);
|
|
2284
|
+
fs_rights_inheriting = BigInt(fs_rights_inheriting);
|
|
2285
|
+
const { flags: flagsRes, needed_base: neededBase, needed_inheriting: neededInheriting } = pathOpen(o_flags, fs_rights_base, fs_rights_inheriting, fs_flags);
|
|
2286
|
+
const wasi = _wasi.get(this);
|
|
2287
|
+
const fileDescriptor = wasi.fds.get(dirfd, neededBase, neededInheriting);
|
|
2288
|
+
const memory = getMemory(this);
|
|
2289
|
+
const HEAPU8 = memory.HEAPU8;
|
|
2290
|
+
const pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
2291
|
+
const fs = getFs(this);
|
|
2292
|
+
const resolved_path = await resolvePathAsync(fs, fileDescriptor, pathString, dirflags);
|
|
2293
|
+
const r = await fs.promises.open(resolved_path, flagsRes, 0o666);
|
|
2294
|
+
const filetype = await wasi.fds.getFileTypeByFd(r);
|
|
2295
|
+
if ((o_flags & 2 /* WasiFileControlFlag.O_DIRECTORY */) !== 0 && filetype !== 3 /* WasiFileType.DIRECTORY */) {
|
|
2296
|
+
return 54 /* WasiErrno.ENOTDIR */;
|
|
2297
|
+
}
|
|
2298
|
+
const { base: max_base, inheriting: max_inheriting } = getRights(wasi.fds.stdio, r.fd, flagsRes, filetype);
|
|
2299
|
+
const wrap = wasi.fds.insert(r, resolved_path, resolved_path, filetype, fs_rights_base & max_base, fs_rights_inheriting & max_inheriting, 0);
|
|
2300
|
+
const stat = await r.stat({ bigint: true });
|
|
2301
|
+
if (stat.isFile()) {
|
|
2302
|
+
wrap.size = stat.size;
|
|
2303
|
+
if ((flagsRes & 1024 /* FileControlFlag.O_APPEND */) !== 0) {
|
|
2304
|
+
wrap.pos = stat.size;
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2307
|
+
const view = memory.view;
|
|
2308
|
+
view.setInt32(fd, wrap.id, true);
|
|
2309
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2310
|
+
}, ['i32', 'i32', 'i32', 'i32', 'i32', 'i64', 'i64', 'i32', 'i32'], ['i32']);
|
|
2311
|
+
defineImport('path_readlink', function path_readlink(fd, path, path_len, buf, buf_len, bufused) {
|
|
2312
|
+
path = Number(path);
|
|
2313
|
+
path_len = Number(path_len);
|
|
2314
|
+
buf = Number(buf);
|
|
2315
|
+
buf_len = Number(buf_len);
|
|
2316
|
+
bufused = Number(bufused);
|
|
2317
|
+
if (path === 0 || buf === 0 || bufused === 0) {
|
|
2318
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2319
|
+
}
|
|
2320
|
+
const { HEAPU8, view } = getMemory(this);
|
|
2321
|
+
const wasi = _wasi.get(this);
|
|
2322
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_READLINK, BigInt(0));
|
|
2323
|
+
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
2324
|
+
pathString = resolve(fileDescriptor.realPath, pathString);
|
|
2325
|
+
const fs = getFs(this);
|
|
2326
|
+
const link = fs.readlinkSync(pathString);
|
|
2327
|
+
const linkData = encoder.encode(link);
|
|
2328
|
+
const len = Math.min(linkData.length, buf_len);
|
|
2329
|
+
if (len >= buf_len)
|
|
2330
|
+
return 42 /* WasiErrno.ENOBUFS */;
|
|
2331
|
+
HEAPU8.set(linkData.subarray(0, len), buf);
|
|
2332
|
+
HEAPU8[buf + len] = 0;
|
|
2333
|
+
view.setUint32(bufused, len, true);
|
|
2334
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2335
|
+
}, async function path_readlink(fd, path, path_len, buf, buf_len, bufused) {
|
|
2336
|
+
path = Number(path);
|
|
2337
|
+
path_len = Number(path_len);
|
|
2338
|
+
buf = Number(buf);
|
|
2339
|
+
buf_len = Number(buf_len);
|
|
2340
|
+
bufused = Number(bufused);
|
|
2341
|
+
if (path === 0 || buf === 0 || bufused === 0) {
|
|
2342
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2343
|
+
}
|
|
2344
|
+
const { HEAPU8, view } = getMemory(this);
|
|
2345
|
+
const wasi = _wasi.get(this);
|
|
2346
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_READLINK, BigInt(0));
|
|
2347
|
+
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
2348
|
+
pathString = resolve(fileDescriptor.realPath, pathString);
|
|
2349
|
+
const fs = getFs(this);
|
|
2350
|
+
const link = await fs.promises.readlink(pathString);
|
|
2351
|
+
const linkData = encoder.encode(link);
|
|
2352
|
+
const len = Math.min(linkData.length, buf_len);
|
|
2353
|
+
if (len >= buf_len)
|
|
2354
|
+
return 42 /* WasiErrno.ENOBUFS */;
|
|
2355
|
+
HEAPU8.set(linkData.subarray(0, len), buf);
|
|
2356
|
+
HEAPU8[buf + len] = 0;
|
|
2357
|
+
view.setUint32(bufused, len, true);
|
|
2358
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2359
|
+
}, ['i32', 'i32', 'i32', 'i32', 'i32', 'i32'], ['i32']);
|
|
2360
|
+
defineImport('path_remove_directory', function path_remove_directory(fd, path, path_len) {
|
|
2361
|
+
path = Number(path);
|
|
2362
|
+
path_len = Number(path_len);
|
|
2363
|
+
if (path === 0) {
|
|
2364
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2365
|
+
}
|
|
2366
|
+
const { HEAPU8 } = getMemory(this);
|
|
2367
|
+
const wasi = _wasi.get(this);
|
|
2368
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_REMOVE_DIRECTORY, BigInt(0));
|
|
2369
|
+
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
2370
|
+
pathString = resolve(fileDescriptor.realPath, pathString);
|
|
2371
|
+
const fs = getFs(this);
|
|
2372
|
+
fs.rmdirSync(pathString);
|
|
2373
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2374
|
+
}, async function path_remove_directory(fd, path, path_len) {
|
|
2375
|
+
path = Number(path);
|
|
2376
|
+
path_len = Number(path_len);
|
|
2377
|
+
if (path === 0) {
|
|
2378
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2379
|
+
}
|
|
2380
|
+
const { HEAPU8 } = getMemory(this);
|
|
2381
|
+
const wasi = _wasi.get(this);
|
|
2382
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_REMOVE_DIRECTORY, BigInt(0));
|
|
2383
|
+
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
2384
|
+
pathString = resolve(fileDescriptor.realPath, pathString);
|
|
2385
|
+
const fs = getFs(this);
|
|
2386
|
+
await fs.promises.rmdir(pathString);
|
|
2387
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2388
|
+
}, ['i32', 'i32', 'i32'], ['i32']);
|
|
2389
|
+
defineImport('path_rename', function path_rename(old_fd, old_path, old_path_len, new_fd, new_path, new_path_len) {
|
|
2390
|
+
old_path = Number(old_path);
|
|
2391
|
+
old_path_len = Number(old_path_len);
|
|
2392
|
+
new_path = Number(new_path);
|
|
2393
|
+
new_path_len = Number(new_path_len);
|
|
2394
|
+
if (old_path === 0 || new_path === 0) {
|
|
2395
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2396
|
+
}
|
|
2397
|
+
const wasi = _wasi.get(this);
|
|
2398
|
+
let oldWrap;
|
|
2399
|
+
let newWrap;
|
|
2400
|
+
if (old_fd === new_fd) {
|
|
2401
|
+
oldWrap = newWrap = wasi.fds.get(old_fd, WasiRights.PATH_RENAME_SOURCE | WasiRights.PATH_RENAME_TARGET, BigInt(0));
|
|
2402
|
+
}
|
|
2403
|
+
else {
|
|
2404
|
+
oldWrap = wasi.fds.get(old_fd, WasiRights.PATH_RENAME_SOURCE, BigInt(0));
|
|
2405
|
+
newWrap = wasi.fds.get(new_fd, WasiRights.PATH_RENAME_TARGET, BigInt(0));
|
|
2406
|
+
}
|
|
2407
|
+
const { HEAPU8 } = getMemory(this);
|
|
2408
|
+
const resolvedOldPath = resolve(oldWrap.realPath, decoder.decode(unsharedSlice(HEAPU8, old_path, old_path + old_path_len)));
|
|
2409
|
+
const resolvedNewPath = resolve(newWrap.realPath, decoder.decode(unsharedSlice(HEAPU8, new_path, new_path + new_path_len)));
|
|
2410
|
+
const fs = getFs(this);
|
|
2411
|
+
fs.renameSync(resolvedOldPath, resolvedNewPath);
|
|
2412
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2413
|
+
}, async function path_rename(old_fd, old_path, old_path_len, new_fd, new_path, new_path_len) {
|
|
2414
|
+
old_path = Number(old_path);
|
|
2415
|
+
old_path_len = Number(old_path_len);
|
|
2416
|
+
new_path = Number(new_path);
|
|
2417
|
+
new_path_len = Number(new_path_len);
|
|
2418
|
+
if (old_path === 0 || new_path === 0) {
|
|
2419
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2420
|
+
}
|
|
2421
|
+
const wasi = _wasi.get(this);
|
|
2422
|
+
let oldWrap;
|
|
2423
|
+
let newWrap;
|
|
2424
|
+
if (old_fd === new_fd) {
|
|
2425
|
+
oldWrap = newWrap = wasi.fds.get(old_fd, WasiRights.PATH_RENAME_SOURCE | WasiRights.PATH_RENAME_TARGET, BigInt(0));
|
|
2426
|
+
}
|
|
2427
|
+
else {
|
|
2428
|
+
oldWrap = wasi.fds.get(old_fd, WasiRights.PATH_RENAME_SOURCE, BigInt(0));
|
|
2429
|
+
newWrap = wasi.fds.get(new_fd, WasiRights.PATH_RENAME_TARGET, BigInt(0));
|
|
2430
|
+
}
|
|
2431
|
+
const { HEAPU8 } = getMemory(this);
|
|
2432
|
+
const resolvedOldPath = resolve(oldWrap.realPath, decoder.decode(unsharedSlice(HEAPU8, old_path, old_path + old_path_len)));
|
|
2433
|
+
const resolvedNewPath = resolve(newWrap.realPath, decoder.decode(unsharedSlice(HEAPU8, new_path, new_path + new_path_len)));
|
|
2434
|
+
const fs = getFs(this);
|
|
2435
|
+
await fs.promises.rename(resolvedOldPath, resolvedNewPath);
|
|
2436
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2437
|
+
}, ['i32', 'i32', 'i32', 'i32', 'i32', 'i32'], ['i32']);
|
|
2438
|
+
defineImport('path_symlink', function path_symlink(old_path, old_path_len, fd, new_path, new_path_len) {
|
|
2439
|
+
old_path = Number(old_path);
|
|
2440
|
+
old_path_len = Number(old_path_len);
|
|
2441
|
+
new_path = Number(new_path);
|
|
2442
|
+
new_path_len = Number(new_path_len);
|
|
2443
|
+
if (old_path === 0 || new_path === 0) {
|
|
2444
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2445
|
+
}
|
|
2446
|
+
const { HEAPU8 } = getMemory(this);
|
|
2447
|
+
const wasi = _wasi.get(this);
|
|
2448
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_SYMLINK, BigInt(0));
|
|
2449
|
+
const oldPath = decoder.decode(unsharedSlice(HEAPU8, old_path, old_path + old_path_len));
|
|
2450
|
+
let newPath = decoder.decode(unsharedSlice(HEAPU8, new_path, new_path + new_path_len));
|
|
2451
|
+
newPath = resolve(fileDescriptor.realPath, newPath);
|
|
2452
|
+
const fs = getFs(this);
|
|
2453
|
+
fs.symlinkSync(oldPath, newPath);
|
|
2454
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2455
|
+
}, async function path_symlink(old_path, old_path_len, fd, new_path, new_path_len) {
|
|
2456
|
+
old_path = Number(old_path);
|
|
2457
|
+
old_path_len = Number(old_path_len);
|
|
2458
|
+
new_path = Number(new_path);
|
|
2459
|
+
new_path_len = Number(new_path_len);
|
|
2460
|
+
if (old_path === 0 || new_path === 0) {
|
|
2461
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2462
|
+
}
|
|
2463
|
+
const { HEAPU8 } = getMemory(this);
|
|
2464
|
+
const wasi = _wasi.get(this);
|
|
2465
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_SYMLINK, BigInt(0));
|
|
2466
|
+
const oldPath = decoder.decode(unsharedSlice(HEAPU8, old_path, old_path + old_path_len));
|
|
2467
|
+
let newPath = decoder.decode(unsharedSlice(HEAPU8, new_path, new_path + new_path_len));
|
|
2468
|
+
newPath = resolve(fileDescriptor.realPath, newPath);
|
|
2469
|
+
const fs = getFs(this);
|
|
2470
|
+
await fs.promises.symlink(oldPath, newPath);
|
|
2471
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2472
|
+
}, ['i32', 'i32', 'i32', 'i32', 'i32'], ['i32']);
|
|
2473
|
+
defineImport('path_unlink_file', function path_unlink_file(fd, path, path_len) {
|
|
2474
|
+
path = Number(path);
|
|
2475
|
+
path_len = Number(path_len);
|
|
2476
|
+
if (path === 0) {
|
|
2477
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2478
|
+
}
|
|
2479
|
+
const { HEAPU8 } = getMemory(this);
|
|
2480
|
+
const wasi = _wasi.get(this);
|
|
2481
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_UNLINK_FILE, BigInt(0));
|
|
2482
|
+
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
2483
|
+
pathString = resolve(fileDescriptor.realPath, pathString);
|
|
2484
|
+
const fs = getFs(this);
|
|
2485
|
+
fs.unlinkSync(pathString);
|
|
2486
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2487
|
+
}, async function path_unlink_file(fd, path, path_len) {
|
|
2488
|
+
path = Number(path);
|
|
2489
|
+
path_len = Number(path_len);
|
|
2490
|
+
if (path === 0) {
|
|
2491
|
+
return 28 /* WasiErrno.EINVAL */;
|
|
2492
|
+
}
|
|
2493
|
+
const { HEAPU8 } = getMemory(this);
|
|
2494
|
+
const wasi = _wasi.get(this);
|
|
2495
|
+
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_UNLINK_FILE, BigInt(0));
|
|
2496
|
+
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
2497
|
+
pathString = resolve(fileDescriptor.realPath, pathString);
|
|
2498
|
+
const fs = getFs(this);
|
|
2499
|
+
await fs.promises.unlink(pathString);
|
|
2500
|
+
return 0 /* WasiErrno.ESUCCESS */;
|
|
2501
|
+
}, ['i32', 'i32', 'i32'], ['i32']);
|
|
2502
|
+
this._setMemory = function setMemory(m) {
|
|
2503
|
+
if (!(m instanceof _WebAssembly.Memory)) {
|
|
2504
|
+
throw new TypeError('"instance.exports.memory" property must be a WebAssembly.Memory');
|
|
2505
|
+
}
|
|
2506
|
+
_memory.set(_this, extendMemory(m));
|
|
2507
|
+
};
|
|
2508
|
+
}
|
|
2509
|
+
static createSync(args, env, preopens, stdio, fs, print, printErr) {
|
|
2510
|
+
const fds = new SyncTable({
|
|
2511
|
+
size: 3,
|
|
2512
|
+
in: stdio[0],
|
|
2513
|
+
out: stdio[1],
|
|
2514
|
+
err: stdio[2],
|
|
2515
|
+
fs,
|
|
2516
|
+
print,
|
|
2517
|
+
printErr
|
|
2518
|
+
});
|
|
2519
|
+
const _this = new WASI$1(args, env, fds, false, fs);
|
|
2520
|
+
if (preopens.length > 0) {
|
|
2521
|
+
for (let i = 0; i < preopens.length; ++i) {
|
|
2522
|
+
const realPath = fs.realpathSync(preopens[i].realPath, 'utf8');
|
|
2523
|
+
const fd = fs.openSync(realPath, 'r', 0o666);
|
|
2524
|
+
fds.insertPreopen(fd, preopens[i].mappedPath, realPath);
|
|
2525
|
+
}
|
|
2526
|
+
}
|
|
2527
|
+
return _this;
|
|
2528
|
+
}
|
|
2529
|
+
static async createAsync(args, env, preopens, stdio, fs, print, printErr, asyncify) {
|
|
2530
|
+
const fds = new AsyncTable({
|
|
2531
|
+
size: 3,
|
|
2532
|
+
in: stdio[0],
|
|
2533
|
+
out: stdio[1],
|
|
2534
|
+
err: stdio[2],
|
|
2535
|
+
print,
|
|
2536
|
+
printErr
|
|
2537
|
+
});
|
|
2538
|
+
const _this = new WASI$1(args, env, fds, true, fs, asyncify);
|
|
2539
|
+
if (preopens.length > 0) {
|
|
2540
|
+
for (let i = 0; i < preopens.length; ++i) {
|
|
2541
|
+
const entry = preopens[i];
|
|
2542
|
+
const realPath = await fs.promises.realpath(entry.realPath);
|
|
2543
|
+
const fd = await fs.promises.open(realPath, 'r', 0o666);
|
|
2544
|
+
await fds.insertPreopen(fd, entry.mappedPath, realPath);
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2547
|
+
return _this;
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
|
|
2551
|
+
// eslint-disable-next-line spaced-comment
|
|
2552
|
+
const kEmptyObject = /*#__PURE__*/ Object.freeze(/*#__PURE__*/ Object.create(null));
|
|
2553
|
+
const kExitCode = Symbol('kExitCode');
|
|
2554
|
+
const kSetMemory = Symbol('kSetMemory');
|
|
2555
|
+
const kStarted = Symbol('kStarted');
|
|
2556
|
+
const kInstance = Symbol('kInstance');
|
|
2557
|
+
const kBindingName = Symbol('kBindingName');
|
|
2558
|
+
function setupInstance(self, instance) {
|
|
2559
|
+
validateObject(instance, 'instance');
|
|
2560
|
+
validateObject(instance.exports, 'instance.exports');
|
|
2561
|
+
self[kInstance] = instance;
|
|
2562
|
+
self[kSetMemory](instance.exports.memory);
|
|
2563
|
+
}
|
|
2564
|
+
function validateOptions(options) {
|
|
2565
|
+
var _a;
|
|
2566
|
+
validateObject(options, 'options');
|
|
2567
|
+
let _WASI;
|
|
2568
|
+
if (options.version !== undefined) {
|
|
2569
|
+
validateString(options.version, 'options.version');
|
|
2570
|
+
switch (options.version) {
|
|
2571
|
+
case 'unstable':
|
|
2572
|
+
_WASI = WASI$1;
|
|
2573
|
+
this[kBindingName] = 'wasi_unstable';
|
|
2574
|
+
break;
|
|
2575
|
+
case 'preview1':
|
|
2576
|
+
_WASI = WASI$1;
|
|
2577
|
+
this[kBindingName] = 'wasi_snapshot_preview1';
|
|
2578
|
+
break;
|
|
2579
|
+
default:
|
|
2580
|
+
throw new TypeError(`unsupported WASI version "${options.version}"`);
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
else {
|
|
2584
|
+
_WASI = WASI$1;
|
|
2585
|
+
this[kBindingName] = 'wasi_snapshot_preview1';
|
|
2586
|
+
}
|
|
2587
|
+
if (options.args !== undefined) {
|
|
2588
|
+
validateArray(options.args, 'options.args');
|
|
2589
|
+
}
|
|
2590
|
+
const args = ((_a = options.args) !== null && _a !== void 0 ? _a : []).map(String);
|
|
2591
|
+
const env = [];
|
|
2592
|
+
if (options.env !== undefined) {
|
|
2593
|
+
validateObject(options.env, 'options.env');
|
|
2594
|
+
Object.entries(options.env).forEach(({ 0: key, 1: value }) => {
|
|
2595
|
+
if (value !== undefined) {
|
|
2596
|
+
env.push(`${key}=${value}`);
|
|
2597
|
+
}
|
|
2598
|
+
});
|
|
2599
|
+
}
|
|
2600
|
+
const preopens = [];
|
|
2601
|
+
if (options.preopens !== undefined) {
|
|
2602
|
+
validateObject(options.preopens, 'options.preopens');
|
|
2603
|
+
Object.entries(options.preopens).forEach(({ 0: key, 1: value }) => preopens.push({ mappedPath: String(key), realPath: String(value) }));
|
|
2604
|
+
}
|
|
2605
|
+
if (preopens.length > 0) {
|
|
2606
|
+
if (options.fs === undefined) {
|
|
2607
|
+
throw new Error('filesystem is disabled, can not preopen directory');
|
|
2608
|
+
}
|
|
2609
|
+
try {
|
|
2610
|
+
validateObject(options.fs, 'options.fs');
|
|
2611
|
+
}
|
|
2612
|
+
catch (_) {
|
|
2613
|
+
throw new TypeError('Node.js fs like implementation is not provided');
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
// if (options.filesystem !== undefined) {
|
|
2617
|
+
// validateObject(options.filesystem, 'options.filesystem')
|
|
2618
|
+
// validateString(options.filesystem.type, 'options.filesystem.type')
|
|
2619
|
+
// if (options.filesystem.type !== 'memfs' && options.filesystem.type !== 'file-system-access-api') {
|
|
2620
|
+
// throw new Error(`Filesystem type ${(options.filesystem as any).type as string} is not supported, only "memfs" and "file-system-access-api" is supported currently`)
|
|
2621
|
+
// }
|
|
2622
|
+
// try {
|
|
2623
|
+
// validateObject(options.filesystem.fs, 'options.filesystem.fs')
|
|
2624
|
+
// } catch (_) {
|
|
2625
|
+
// throw new Error('Node.js fs like implementation is not provided')
|
|
2626
|
+
// }
|
|
2627
|
+
// }
|
|
2628
|
+
if (options.print !== undefined)
|
|
2629
|
+
validateFunction(options.print, 'options.print');
|
|
2630
|
+
if (options.printErr !== undefined)
|
|
2631
|
+
validateFunction(options.printErr, 'options.printErr');
|
|
2632
|
+
if (options.returnOnExit !== undefined) {
|
|
2633
|
+
validateBoolean(options.returnOnExit, 'options.returnOnExit');
|
|
2634
|
+
}
|
|
2635
|
+
// const { stdin = 0, stdout = 1, stderr = 2 } = options
|
|
2636
|
+
// validateInt32(stdin, 'options.stdin', 0)
|
|
2637
|
+
// validateInt32(stdout, 'options.stdout', 0)
|
|
2638
|
+
// validateInt32(stderr, 'options.stderr', 0)
|
|
2639
|
+
// const stdio = [stdin, stdout, stderr] as const
|
|
2640
|
+
const stdio = [0, 1, 2];
|
|
2641
|
+
return {
|
|
2642
|
+
args,
|
|
2643
|
+
env,
|
|
2644
|
+
preopens,
|
|
2645
|
+
stdio,
|
|
2646
|
+
_WASI
|
|
2647
|
+
};
|
|
2648
|
+
}
|
|
2649
|
+
function initWASI(setMemory, wrap) {
|
|
2650
|
+
this[kSetMemory] = setMemory;
|
|
2651
|
+
this.wasiImport = wrap;
|
|
2652
|
+
this[kStarted] = false;
|
|
2653
|
+
this[kExitCode] = 0;
|
|
2654
|
+
this[kInstance] = undefined;
|
|
2655
|
+
}
|
|
2656
|
+
/** @public */
|
|
2657
|
+
class WASI {
|
|
2658
|
+
constructor(options = kEmptyObject) {
|
|
2659
|
+
const { args, env, preopens, stdio, _WASI } = validateOptions.call(this, options);
|
|
2660
|
+
const wrap = _WASI.createSync(args, env, preopens, stdio, options.fs, options.print, options.printErr);
|
|
2661
|
+
const setMemory = wrap._setMemory;
|
|
2662
|
+
delete wrap._setMemory;
|
|
2663
|
+
initWASI.call(this, setMemory, wrap);
|
|
2664
|
+
if (options.returnOnExit) {
|
|
2665
|
+
wrap.proc_exit = wasiReturnOnProcExit.bind(this);
|
|
2666
|
+
}
|
|
2667
|
+
}
|
|
2668
|
+
// Must not export _initialize, must export _start
|
|
2669
|
+
start(instance) {
|
|
2670
|
+
if (this[kStarted]) {
|
|
2671
|
+
throw new Error('WASI instance has already started');
|
|
2672
|
+
}
|
|
2673
|
+
this[kStarted] = true;
|
|
2674
|
+
setupInstance(this, instance);
|
|
2675
|
+
const { _start, _initialize } = this[kInstance].exports;
|
|
2676
|
+
validateFunction(_start, 'instance.exports._start');
|
|
2677
|
+
validateUndefined(_initialize, 'instance.exports._initialize');
|
|
2678
|
+
let ret;
|
|
2679
|
+
try {
|
|
2680
|
+
ret = _start();
|
|
2681
|
+
}
|
|
2682
|
+
catch (err) {
|
|
2683
|
+
if (err !== kExitCode) {
|
|
2684
|
+
throw err;
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
if (ret instanceof Promise) {
|
|
2688
|
+
return ret.then(() => this[kExitCode], (err) => {
|
|
2689
|
+
if (err !== kExitCode) {
|
|
2690
|
+
throw err;
|
|
2691
|
+
}
|
|
2692
|
+
return this[kExitCode];
|
|
2693
|
+
});
|
|
2694
|
+
}
|
|
2695
|
+
return this[kExitCode];
|
|
2696
|
+
}
|
|
2697
|
+
// Must not export _start, may optionally export _initialize
|
|
2698
|
+
initialize(instance) {
|
|
2699
|
+
if (this[kStarted]) {
|
|
2700
|
+
throw new Error('WASI instance has already started');
|
|
2701
|
+
}
|
|
2702
|
+
this[kStarted] = true;
|
|
2703
|
+
setupInstance(this, instance);
|
|
2704
|
+
const { _start, _initialize } = this[kInstance].exports;
|
|
2705
|
+
validateUndefined(_start, 'instance.exports._start');
|
|
2706
|
+
if (_initialize !== undefined) {
|
|
2707
|
+
validateFunction(_initialize, 'instance.exports._initialize');
|
|
2708
|
+
return _initialize();
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
getImportObject() {
|
|
2712
|
+
return { [this[kBindingName]]: this.wasiImport };
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2715
|
+
function wasiReturnOnProcExit(rval) {
|
|
2716
|
+
this[kExitCode] = rval;
|
|
2717
|
+
// eslint-disable-next-line @typescript-eslint/no-throw-literal
|
|
2718
|
+
throw kExitCode;
|
|
2719
|
+
}
|
|
2720
|
+
/** @public */
|
|
2721
|
+
async function createAsyncWASI(options = kEmptyObject) {
|
|
2722
|
+
const _this = Object.create(WASI.prototype);
|
|
2723
|
+
const { args, env, preopens, stdio, _WASI } = validateOptions.call(_this, options);
|
|
2724
|
+
if (options.asyncify !== undefined) {
|
|
2725
|
+
validateObject(options.asyncify, 'options.asyncify');
|
|
2726
|
+
validateFunction(options.asyncify.wrapImportFunction, 'options.asyncify.wrapImportFunction');
|
|
2727
|
+
}
|
|
2728
|
+
const wrap = await _WASI.createAsync(args, env, preopens, stdio, options.fs, options.print, options.printErr, options.asyncify);
|
|
2729
|
+
const setMemory = wrap._setMemory;
|
|
2730
|
+
delete wrap._setMemory;
|
|
2731
|
+
initWASI.call(_this, setMemory, wrap);
|
|
2732
|
+
if (options.returnOnExit) {
|
|
2733
|
+
wrap.proc_exit = wasiReturnOnProcExit.bind(_this);
|
|
2734
|
+
}
|
|
2735
|
+
return _this;
|
|
2736
|
+
}
|
|
2737
|
+
|
|
2738
|
+
export { Asyncify, Memory, WASI, WebAssemblyMemory, asyncifyLoad, asyncifyLoadSync, createAsyncWASI, extendMemory, load, loadSync, wrapAsyncExport, wrapAsyncImport, wrapExports };
|