@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,39 @@
|
|
|
1
|
+
import { wrapInstanceExports } from "./wasi/util.mjs";
|
|
2
|
+
import { _WebAssembly } from "./webassembly.mjs";
|
|
3
|
+
function checkWebAssemblyFunction() {
|
|
4
|
+
const WebAssemblyFunction = _WebAssembly.Function;
|
|
5
|
+
if (typeof WebAssemblyFunction !== 'function') {
|
|
6
|
+
throw new Error('WebAssembly.Function is not supported in this environment.' +
|
|
7
|
+
' If you are using V8 based browser like Chrome, try to specify' +
|
|
8
|
+
' --js-flags="--wasm-staging --experimental-wasm-stack-switching"');
|
|
9
|
+
}
|
|
10
|
+
return WebAssemblyFunction;
|
|
11
|
+
}
|
|
12
|
+
/** @public */
|
|
13
|
+
export function wrapAsyncImport(f, parameterType, returnType) {
|
|
14
|
+
const WebAssemblyFunction = checkWebAssemblyFunction();
|
|
15
|
+
if (typeof f !== 'function') {
|
|
16
|
+
throw new TypeError('Function required');
|
|
17
|
+
}
|
|
18
|
+
const parameters = parameterType.slice(0);
|
|
19
|
+
parameters.unshift('externref');
|
|
20
|
+
return new WebAssemblyFunction({ parameters, results: returnType }, f, { suspending: 'first' });
|
|
21
|
+
}
|
|
22
|
+
/** @public */
|
|
23
|
+
export function wrapAsyncExport(f) {
|
|
24
|
+
const WebAssemblyFunction = checkWebAssemblyFunction();
|
|
25
|
+
if (typeof f !== 'function') {
|
|
26
|
+
throw new TypeError('Function required');
|
|
27
|
+
}
|
|
28
|
+
return new WebAssemblyFunction({ parameters: [...WebAssemblyFunction.type(f).parameters.slice(1)], results: ['externref'] }, f, { promising: 'first' });
|
|
29
|
+
}
|
|
30
|
+
/** @public */
|
|
31
|
+
export function wrapExports(exports, needWrap) {
|
|
32
|
+
return wrapInstanceExports(exports, (exportValue, name) => {
|
|
33
|
+
let ignore = typeof exportValue !== 'function';
|
|
34
|
+
if (Array.isArray(needWrap)) {
|
|
35
|
+
ignore = ignore || (needWrap.indexOf(name) === -1);
|
|
36
|
+
}
|
|
37
|
+
return ignore ? exportValue : wrapAsyncExport(exportValue);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { _WebAssembly } from "./webassembly.mjs";
|
|
2
|
+
import { Asyncify } from "./asyncify.mjs";
|
|
3
|
+
function validateImports(imports) {
|
|
4
|
+
if (imports && typeof imports !== 'object') {
|
|
5
|
+
throw new TypeError('imports must be an object or undefined');
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
function fetchWasm(urlOrBuffer, imports) {
|
|
9
|
+
if (typeof wx !== 'undefined' && typeof __wxConfig !== 'undefined') {
|
|
10
|
+
return _WebAssembly.instantiate(urlOrBuffer, imports);
|
|
11
|
+
}
|
|
12
|
+
return fetch(urlOrBuffer)
|
|
13
|
+
.then(response => response.arrayBuffer())
|
|
14
|
+
.then(buffer => _WebAssembly.instantiate(buffer, imports));
|
|
15
|
+
}
|
|
16
|
+
/** @public */
|
|
17
|
+
export function load(wasmInput, imports) {
|
|
18
|
+
validateImports(imports);
|
|
19
|
+
imports = imports !== null && imports !== void 0 ? imports : {};
|
|
20
|
+
let source;
|
|
21
|
+
if (wasmInput instanceof ArrayBuffer || ArrayBuffer.isView(wasmInput)) {
|
|
22
|
+
return _WebAssembly.instantiate(wasmInput, imports);
|
|
23
|
+
}
|
|
24
|
+
if (wasmInput instanceof _WebAssembly.Module) {
|
|
25
|
+
return _WebAssembly.instantiate(wasmInput, imports).then((instance) => {
|
|
26
|
+
return { instance, module: wasmInput };
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (typeof wasmInput !== 'string' && !(wasmInput instanceof URL)) {
|
|
30
|
+
throw new TypeError('Invalid source');
|
|
31
|
+
}
|
|
32
|
+
if (typeof _WebAssembly.instantiateStreaming === 'function') {
|
|
33
|
+
let responsePromise;
|
|
34
|
+
try {
|
|
35
|
+
responsePromise = fetch(wasmInput);
|
|
36
|
+
source = _WebAssembly.instantiateStreaming(responsePromise, imports).catch(() => {
|
|
37
|
+
return fetchWasm(wasmInput, imports);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
catch (_) {
|
|
41
|
+
source = fetchWasm(wasmInput, imports);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
source = fetchWasm(wasmInput, imports);
|
|
46
|
+
}
|
|
47
|
+
return source;
|
|
48
|
+
}
|
|
49
|
+
/** @public */
|
|
50
|
+
export function asyncifyLoad(asyncify, urlOrBuffer, imports) {
|
|
51
|
+
validateImports(imports);
|
|
52
|
+
imports = imports !== null && imports !== void 0 ? imports : {};
|
|
53
|
+
const asyncifyHelper = new Asyncify();
|
|
54
|
+
imports = asyncifyHelper.wrapImports(imports);
|
|
55
|
+
return load(urlOrBuffer, imports).then(source => {
|
|
56
|
+
var _a;
|
|
57
|
+
const memory = source.instance.exports.memory || ((_a = imports.env) === null || _a === void 0 ? void 0 : _a.memory);
|
|
58
|
+
return { module: source.module, instance: asyncifyHelper.init(memory, source.instance, asyncify) };
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/** @public */
|
|
62
|
+
export function loadSync(wasmInput, imports) {
|
|
63
|
+
validateImports(imports);
|
|
64
|
+
imports = imports !== null && imports !== void 0 ? imports : {};
|
|
65
|
+
let module;
|
|
66
|
+
if ((wasmInput instanceof ArrayBuffer) || ArrayBuffer.isView(wasmInput)) {
|
|
67
|
+
module = new _WebAssembly.Module(wasmInput);
|
|
68
|
+
}
|
|
69
|
+
else if (wasmInput instanceof WebAssembly.Module) {
|
|
70
|
+
module = wasmInput;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
throw new TypeError('Invalid source');
|
|
74
|
+
}
|
|
75
|
+
const instance = new _WebAssembly.Instance(module, imports);
|
|
76
|
+
const source = { instance, module };
|
|
77
|
+
return source;
|
|
78
|
+
}
|
|
79
|
+
/** @public */
|
|
80
|
+
export function asyncifyLoadSync(asyncify, buffer, imports) {
|
|
81
|
+
var _a;
|
|
82
|
+
validateImports(imports);
|
|
83
|
+
imports = imports !== null && imports !== void 0 ? imports : {};
|
|
84
|
+
const asyncifyHelper = new Asyncify();
|
|
85
|
+
imports = asyncifyHelper.wrapImports(imports);
|
|
86
|
+
const source = loadSync(buffer, imports);
|
|
87
|
+
const memory = source.instance.exports.memory || ((_a = imports.env) === null || _a === void 0 ? void 0 : _a.memory);
|
|
88
|
+
return { module: source.module, instance: asyncifyHelper.init(memory, source.instance, asyncify) };
|
|
89
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { _WebAssembly } from "./webassembly.mjs";
|
|
2
|
+
/** @public */
|
|
3
|
+
export const WebAssemblyMemory = /*#__PURE__*/ (function () { return _WebAssembly.Memory; })();
|
|
4
|
+
/** @public */
|
|
5
|
+
export class Memory extends WebAssemblyMemory {
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
|
|
7
|
+
constructor(descriptor) {
|
|
8
|
+
super(descriptor);
|
|
9
|
+
}
|
|
10
|
+
get HEAP8() { return new Int8Array(super.buffer); }
|
|
11
|
+
get HEAPU8() { return new Uint8Array(super.buffer); }
|
|
12
|
+
get HEAP16() { return new Int16Array(super.buffer); }
|
|
13
|
+
get HEAPU16() { return new Uint16Array(super.buffer); }
|
|
14
|
+
get HEAP32() { return new Int32Array(super.buffer); }
|
|
15
|
+
get HEAPU32() { return new Uint32Array(super.buffer); }
|
|
16
|
+
get HEAP64() { return new BigInt64Array(super.buffer); }
|
|
17
|
+
get HEAPU64() { return new BigUint64Array(super.buffer); }
|
|
18
|
+
get HEAPF32() { return new Float32Array(super.buffer); }
|
|
19
|
+
get HEAPF64() { return new Float64Array(super.buffer); }
|
|
20
|
+
get view() { return new DataView(super.buffer); }
|
|
21
|
+
}
|
|
22
|
+
/** @public */
|
|
23
|
+
export function extendMemory(memory) {
|
|
24
|
+
if (Object.getPrototypeOf(memory) === _WebAssembly.Memory.prototype) {
|
|
25
|
+
Object.setPrototypeOf(memory, Memory.prototype);
|
|
26
|
+
}
|
|
27
|
+
return memory;
|
|
28
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { WasiErrno } from "./types.mjs";
|
|
2
|
+
export function strerror(errno) {
|
|
3
|
+
switch (errno) {
|
|
4
|
+
case WasiErrno.ESUCCESS: return 'Success';
|
|
5
|
+
case WasiErrno.E2BIG: return 'Argument list too long';
|
|
6
|
+
case WasiErrno.EACCES: return 'Permission denied';
|
|
7
|
+
case WasiErrno.EADDRINUSE: return 'Address in use';
|
|
8
|
+
case WasiErrno.EADDRNOTAVAIL: return 'Address not available';
|
|
9
|
+
case WasiErrno.EAFNOSUPPORT: return 'Address family not supported by protocol';
|
|
10
|
+
case WasiErrno.EAGAIN: return 'Resource temporarily unavailable';
|
|
11
|
+
case WasiErrno.EALREADY: return 'Operation already in progress';
|
|
12
|
+
case WasiErrno.EBADF: return 'Bad file descriptor';
|
|
13
|
+
case WasiErrno.EBADMSG: return 'Bad message';
|
|
14
|
+
case WasiErrno.EBUSY: return 'Resource busy';
|
|
15
|
+
case WasiErrno.ECANCELED: return 'Operation canceled';
|
|
16
|
+
case WasiErrno.ECHILD: return 'No child process';
|
|
17
|
+
case WasiErrno.ECONNABORTED: return 'Connection aborted';
|
|
18
|
+
case WasiErrno.ECONNREFUSED: return 'Connection refused';
|
|
19
|
+
case WasiErrno.ECONNRESET: return 'Connection reset by peer';
|
|
20
|
+
case WasiErrno.EDEADLK: return 'Resource deadlock would occur';
|
|
21
|
+
case WasiErrno.EDESTADDRREQ: return 'Destination address required';
|
|
22
|
+
case WasiErrno.EDOM: return 'Domain error';
|
|
23
|
+
case WasiErrno.EDQUOT: return 'Quota exceeded';
|
|
24
|
+
case WasiErrno.EEXIST: return 'File exists';
|
|
25
|
+
case WasiErrno.EFAULT: return 'Bad address';
|
|
26
|
+
case WasiErrno.EFBIG: return 'File too large';
|
|
27
|
+
case WasiErrno.EHOSTUNREACH: return 'Host is unreachable';
|
|
28
|
+
case WasiErrno.EIDRM: return 'Identifier removed';
|
|
29
|
+
case WasiErrno.EILSEQ: return 'Illegal byte sequence';
|
|
30
|
+
case WasiErrno.EINPROGRESS: return 'Operation in progress';
|
|
31
|
+
case WasiErrno.EINTR: return 'Interrupted system call';
|
|
32
|
+
case WasiErrno.EINVAL: return 'Invalid argument';
|
|
33
|
+
case WasiErrno.EIO: return 'I/O error';
|
|
34
|
+
case WasiErrno.EISCONN: return 'Socket is connected';
|
|
35
|
+
case WasiErrno.EISDIR: return 'Is a directory';
|
|
36
|
+
case WasiErrno.ELOOP: return 'Symbolic link loop';
|
|
37
|
+
case WasiErrno.EMFILE: return 'No file descriptors available';
|
|
38
|
+
case WasiErrno.EMLINK: return 'Too many links';
|
|
39
|
+
case WasiErrno.EMSGSIZE: return 'Message too large';
|
|
40
|
+
case WasiErrno.EMULTIHOP: return 'Multihop attempted';
|
|
41
|
+
case WasiErrno.ENAMETOOLONG: return 'Filename too long';
|
|
42
|
+
case WasiErrno.ENETDOWN: return 'Network is down';
|
|
43
|
+
case WasiErrno.ENETRESET: return 'Connection reset by network';
|
|
44
|
+
case WasiErrno.ENETUNREACH: return 'Network unreachable';
|
|
45
|
+
case WasiErrno.ENFILE: return 'Too many files open in system';
|
|
46
|
+
case WasiErrno.ENOBUFS: return 'No buffer space available';
|
|
47
|
+
case WasiErrno.ENODEV: return 'No such device';
|
|
48
|
+
case WasiErrno.ENOENT: return 'No such file or directory';
|
|
49
|
+
case WasiErrno.ENOEXEC: return 'Exec format error';
|
|
50
|
+
case WasiErrno.ENOLCK: return 'No locks available';
|
|
51
|
+
case WasiErrno.ENOLINK: return 'Link has been severed';
|
|
52
|
+
case WasiErrno.ENOMEM: return 'Out of memory';
|
|
53
|
+
case WasiErrno.ENOMSG: return 'No message of the desired type';
|
|
54
|
+
case WasiErrno.ENOPROTOOPT: return 'Protocol not available';
|
|
55
|
+
case WasiErrno.ENOSPC: return 'No space left on device';
|
|
56
|
+
case WasiErrno.ENOSYS: return 'Function not implemented';
|
|
57
|
+
case WasiErrno.ENOTCONN: return 'Socket not connected';
|
|
58
|
+
case WasiErrno.ENOTDIR: return 'Not a directory';
|
|
59
|
+
case WasiErrno.ENOTEMPTY: return 'Directory not empty';
|
|
60
|
+
case WasiErrno.ENOTRECOVERABLE: return 'State not recoverable';
|
|
61
|
+
case WasiErrno.ENOTSOCK: return 'Not a socket';
|
|
62
|
+
case WasiErrno.ENOTSUP: return 'Not supported';
|
|
63
|
+
case WasiErrno.ENOTTY: return 'Not a tty';
|
|
64
|
+
case WasiErrno.ENXIO: return 'No such device or address';
|
|
65
|
+
case WasiErrno.EOVERFLOW: return 'Value too large for data type';
|
|
66
|
+
case WasiErrno.EOWNERDEAD: return 'Previous owner died';
|
|
67
|
+
case WasiErrno.EPERM: return 'Operation not permitted';
|
|
68
|
+
case WasiErrno.EPIPE: return 'Broken pipe';
|
|
69
|
+
case WasiErrno.EPROTO: return 'Protocol error';
|
|
70
|
+
case WasiErrno.EPROTONOSUPPORT: return 'Protocol not supported';
|
|
71
|
+
case WasiErrno.EPROTOTYPE: return 'Protocol wrong type for socket';
|
|
72
|
+
case WasiErrno.ERANGE: return 'Result not representable';
|
|
73
|
+
case WasiErrno.EROFS: return 'Read-only file system';
|
|
74
|
+
case WasiErrno.ESPIPE: return 'Invalid seek';
|
|
75
|
+
case WasiErrno.ESRCH: return 'No such process';
|
|
76
|
+
case WasiErrno.ESTALE: return 'Stale file handle';
|
|
77
|
+
case WasiErrno.ETIMEDOUT: return 'Operation timed out';
|
|
78
|
+
case WasiErrno.ETXTBSY: return 'Text file busy';
|
|
79
|
+
case WasiErrno.EXDEV: return 'Cross-device link';
|
|
80
|
+
case WasiErrno.ENOTCAPABLE: return 'Capabilities insufficient';
|
|
81
|
+
default: return 'Unknown error';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export class WasiError extends Error {
|
|
85
|
+
constructor(message, errno) {
|
|
86
|
+
super(message);
|
|
87
|
+
this.errno = errno;
|
|
88
|
+
}
|
|
89
|
+
getErrorMessage() {
|
|
90
|
+
return strerror(this.errno);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
Object.defineProperty(WasiError.prototype, 'name', {
|
|
94
|
+
configurable: true,
|
|
95
|
+
writable: true,
|
|
96
|
+
value: 'WasiError'
|
|
97
|
+
});
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { WasiErrno, FileControlFlag, WasiFileType, WasiWhence } from "./types.mjs";
|
|
2
|
+
import { getRights } from "./rights.mjs";
|
|
3
|
+
import { WasiError } from "./error.mjs";
|
|
4
|
+
export function concatBuffer(buffers, size) {
|
|
5
|
+
let total = 0;
|
|
6
|
+
if (typeof size === 'number' && size >= 0) {
|
|
7
|
+
total = size;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
for (let i = 0; i < buffers.length; i++) {
|
|
11
|
+
const buffer = buffers[i];
|
|
12
|
+
total += buffer.length;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
let pos = 0;
|
|
16
|
+
const ret = new Uint8Array(total);
|
|
17
|
+
for (let i = 0; i < buffers.length; i++) {
|
|
18
|
+
const buffer = buffers[i];
|
|
19
|
+
ret.set(buffer, pos);
|
|
20
|
+
pos += buffer.length;
|
|
21
|
+
}
|
|
22
|
+
return ret;
|
|
23
|
+
}
|
|
24
|
+
export class FileDescriptor {
|
|
25
|
+
constructor(id, fd, path, realPath, type, rightsBase, rightsInheriting, preopen) {
|
|
26
|
+
this.id = id;
|
|
27
|
+
this.fd = fd;
|
|
28
|
+
this.path = path;
|
|
29
|
+
this.realPath = realPath;
|
|
30
|
+
this.type = type;
|
|
31
|
+
this.rightsBase = rightsBase;
|
|
32
|
+
this.rightsInheriting = rightsInheriting;
|
|
33
|
+
this.preopen = preopen;
|
|
34
|
+
this.pos = BigInt(0);
|
|
35
|
+
this.size = BigInt(0);
|
|
36
|
+
}
|
|
37
|
+
seek(offset, whence) {
|
|
38
|
+
if (whence === WasiWhence.SET) {
|
|
39
|
+
this.pos = BigInt(offset);
|
|
40
|
+
}
|
|
41
|
+
else if (whence === WasiWhence.CUR) {
|
|
42
|
+
this.pos += BigInt(offset);
|
|
43
|
+
}
|
|
44
|
+
else if (whence === WasiWhence.END) {
|
|
45
|
+
this.pos = BigInt(this.size) - BigInt(offset);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
throw new WasiError('Unknown whence', WasiErrno.EIO);
|
|
49
|
+
}
|
|
50
|
+
return this.pos;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export class StandardOutput extends FileDescriptor {
|
|
54
|
+
constructor(log, id, fd, path, realPath, type, rightsBase, rightsInheriting, preopen) {
|
|
55
|
+
super(id, fd, path, realPath, type, rightsBase, rightsInheriting, preopen);
|
|
56
|
+
this._log = log;
|
|
57
|
+
this._buf = null;
|
|
58
|
+
}
|
|
59
|
+
write(buffer) {
|
|
60
|
+
const originalBuffer = buffer;
|
|
61
|
+
if (this._buf) {
|
|
62
|
+
buffer = concatBuffer([this._buf, buffer]);
|
|
63
|
+
this._buf = null;
|
|
64
|
+
}
|
|
65
|
+
if (buffer.indexOf(10) === -1) {
|
|
66
|
+
this._buf = buffer;
|
|
67
|
+
return originalBuffer.byteLength;
|
|
68
|
+
}
|
|
69
|
+
let written = 0;
|
|
70
|
+
let lastBegin = 0;
|
|
71
|
+
let index;
|
|
72
|
+
while ((index = buffer.indexOf(10, written)) !== -1) {
|
|
73
|
+
const str = new TextDecoder().decode(buffer.subarray(lastBegin, index));
|
|
74
|
+
this._log(str);
|
|
75
|
+
written += index - lastBegin + 1;
|
|
76
|
+
lastBegin = index + 1;
|
|
77
|
+
}
|
|
78
|
+
if (written < buffer.length) {
|
|
79
|
+
this._buf = buffer.slice(written);
|
|
80
|
+
}
|
|
81
|
+
return originalBuffer.byteLength;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export function toFileType(stat) {
|
|
85
|
+
if (stat.isBlockDevice())
|
|
86
|
+
return WasiFileType.BLOCK_DEVICE;
|
|
87
|
+
if (stat.isCharacterDevice())
|
|
88
|
+
return WasiFileType.CHARACTER_DEVICE;
|
|
89
|
+
if (stat.isDirectory())
|
|
90
|
+
return WasiFileType.DIRECTORY;
|
|
91
|
+
if (stat.isSocket())
|
|
92
|
+
return WasiFileType.SOCKET_STREAM;
|
|
93
|
+
if (stat.isFile())
|
|
94
|
+
return WasiFileType.REGULAR_FILE;
|
|
95
|
+
if (stat.isSymbolicLink())
|
|
96
|
+
return WasiFileType.SYMBOLIC_LINK;
|
|
97
|
+
return WasiFileType.UNKNOWN;
|
|
98
|
+
}
|
|
99
|
+
export function toFileStat(view, buf, stat) {
|
|
100
|
+
view.setBigUint64(buf, stat.dev, true);
|
|
101
|
+
view.setBigUint64(buf + 8, stat.ino, true);
|
|
102
|
+
view.setBigUint64(buf + 16, BigInt(toFileType(stat)), true);
|
|
103
|
+
view.setBigUint64(buf + 24, stat.nlink, true);
|
|
104
|
+
view.setBigUint64(buf + 32, stat.size, true);
|
|
105
|
+
view.setBigUint64(buf + 40, stat.atimeMs * BigInt(1000000), true);
|
|
106
|
+
view.setBigUint64(buf + 48, stat.mtimeMs * BigInt(1000000), true);
|
|
107
|
+
view.setBigUint64(buf + 56, stat.ctimeMs * BigInt(1000000), true);
|
|
108
|
+
}
|
|
109
|
+
export class FileDescriptorTable {
|
|
110
|
+
constructor(options) {
|
|
111
|
+
this.used = 0;
|
|
112
|
+
this.size = options.size;
|
|
113
|
+
this.fds = Array(options.size);
|
|
114
|
+
this.stdio = [options.in, options.out, options.err];
|
|
115
|
+
this.print = options.print;
|
|
116
|
+
this.printErr = options.printErr;
|
|
117
|
+
this.insertStdio(options.in, 0, '<stdin>');
|
|
118
|
+
this.insertStdio(options.out, 1, '<stdout>');
|
|
119
|
+
this.insertStdio(options.err, 2, '<stderr>');
|
|
120
|
+
}
|
|
121
|
+
insertStdio(fd, expected, name) {
|
|
122
|
+
const type = WasiFileType.CHARACTER_DEVICE;
|
|
123
|
+
const { base, inheriting } = getRights(this.stdio, fd, FileControlFlag.O_RDWR, type);
|
|
124
|
+
const wrap = this.insert(fd, name, name, type, base, inheriting, 0);
|
|
125
|
+
if (wrap.id !== expected) {
|
|
126
|
+
throw new WasiError(`id: ${wrap.id} !== expected: ${expected}`, WasiErrno.EBADF);
|
|
127
|
+
}
|
|
128
|
+
return wrap;
|
|
129
|
+
}
|
|
130
|
+
insert(fd, mappedPath, realPath, type, rightsBase, rightsInheriting, preopen) {
|
|
131
|
+
var _a, _b;
|
|
132
|
+
let index = -1;
|
|
133
|
+
if (this.used >= this.size) {
|
|
134
|
+
const newSize = this.size * 2;
|
|
135
|
+
this.fds.length = newSize;
|
|
136
|
+
index = this.size;
|
|
137
|
+
this.size = newSize;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
for (let i = 0; i < this.size; ++i) {
|
|
141
|
+
if (this.fds[i] == null) {
|
|
142
|
+
index = i;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
let entry;
|
|
148
|
+
if (mappedPath === '<stdout>') {
|
|
149
|
+
entry = new StandardOutput((_a = this.print) !== null && _a !== void 0 ? _a : console.log, index, fd, mappedPath, realPath, type, rightsBase, rightsInheriting, preopen);
|
|
150
|
+
}
|
|
151
|
+
else if (mappedPath === '<stderr>') {
|
|
152
|
+
entry = new StandardOutput((_b = this.printErr) !== null && _b !== void 0 ? _b : console.error, index, fd, mappedPath, realPath, type, rightsBase, rightsInheriting, preopen);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
entry = new FileDescriptor(index, fd, mappedPath, realPath, type, rightsBase, rightsInheriting, preopen);
|
|
156
|
+
}
|
|
157
|
+
this.fds[index] = entry;
|
|
158
|
+
this.used++;
|
|
159
|
+
return entry;
|
|
160
|
+
}
|
|
161
|
+
get(id, base, inheriting) {
|
|
162
|
+
if (id >= this.size) {
|
|
163
|
+
throw new WasiError('Invalid fd', WasiErrno.EBADF);
|
|
164
|
+
}
|
|
165
|
+
const entry = this.fds[id];
|
|
166
|
+
if (!entry || entry.id !== id) {
|
|
167
|
+
throw new WasiError('Bad file descriptor', WasiErrno.EBADF);
|
|
168
|
+
}
|
|
169
|
+
/* Validate that the fd has the necessary rights. */
|
|
170
|
+
if ((~entry.rightsBase & base) !== BigInt(0) || (~entry.rightsInheriting & inheriting) !== BigInt(0)) {
|
|
171
|
+
throw new WasiError('Capabilities insufficient', WasiErrno.ENOTCAPABLE);
|
|
172
|
+
}
|
|
173
|
+
return entry;
|
|
174
|
+
}
|
|
175
|
+
remove(id) {
|
|
176
|
+
if (id >= this.size) {
|
|
177
|
+
throw new WasiError('Invalid fd', WasiErrno.EBADF);
|
|
178
|
+
}
|
|
179
|
+
const entry = this.fds[id];
|
|
180
|
+
if (!entry || entry.id !== id) {
|
|
181
|
+
throw new WasiError('Bad file descriptor', WasiErrno.EBADF);
|
|
182
|
+
}
|
|
183
|
+
this.fds[id] = undefined;
|
|
184
|
+
this.used--;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
export class SyncTable extends FileDescriptorTable {
|
|
188
|
+
constructor(options) {
|
|
189
|
+
super(options);
|
|
190
|
+
this.fs = options.fs;
|
|
191
|
+
}
|
|
192
|
+
getFileTypeByFd(fd) {
|
|
193
|
+
const stats = this.fs.fstatSync(fd, { bigint: true });
|
|
194
|
+
return toFileType(stats);
|
|
195
|
+
}
|
|
196
|
+
insertPreopen(fd, mappedPath, realPath) {
|
|
197
|
+
const type = this.getFileTypeByFd(fd);
|
|
198
|
+
if (type !== WasiFileType.DIRECTORY) {
|
|
199
|
+
throw new WasiError(`Preopen not dir: ["${mappedPath}", "${realPath}"]`, WasiErrno.ENOTDIR);
|
|
200
|
+
}
|
|
201
|
+
const result = getRights(this.stdio, fd, 0, type);
|
|
202
|
+
return this.insert(fd, mappedPath, realPath, type, result.base, result.inheriting, 1);
|
|
203
|
+
}
|
|
204
|
+
renumber(dst, src) {
|
|
205
|
+
if (dst === src)
|
|
206
|
+
return;
|
|
207
|
+
if (dst >= this.size || src >= this.size) {
|
|
208
|
+
throw new WasiError('Invalid fd', WasiErrno.EBADF);
|
|
209
|
+
}
|
|
210
|
+
const dstEntry = this.fds[dst];
|
|
211
|
+
const srcEntry = this.fds[src];
|
|
212
|
+
if (!dstEntry || !srcEntry || dstEntry.id !== dst || srcEntry.id !== src) {
|
|
213
|
+
throw new WasiError('Invalid fd', WasiErrno.EBADF);
|
|
214
|
+
}
|
|
215
|
+
this.fs.closeSync(dstEntry.fd);
|
|
216
|
+
this.fds[dst] = this.fds[src];
|
|
217
|
+
this.fds[dst].id = dst;
|
|
218
|
+
this.fds[src] = undefined;
|
|
219
|
+
this.used--;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
export class AsyncTable extends FileDescriptorTable {
|
|
223
|
+
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
|
|
224
|
+
constructor(options) {
|
|
225
|
+
super(options);
|
|
226
|
+
}
|
|
227
|
+
async getFileTypeByFd(fd) {
|
|
228
|
+
const stats = await fd.stat({ bigint: true });
|
|
229
|
+
return toFileType(stats);
|
|
230
|
+
}
|
|
231
|
+
async insertPreopen(fd, mappedPath, realPath) {
|
|
232
|
+
const type = await this.getFileTypeByFd(fd);
|
|
233
|
+
if (type !== WasiFileType.DIRECTORY) {
|
|
234
|
+
throw new WasiError(`Preopen not dir: ["${mappedPath}", "${realPath}"]`, WasiErrno.ENOTDIR);
|
|
235
|
+
}
|
|
236
|
+
const result = getRights(this.stdio, fd.fd, 0, type);
|
|
237
|
+
return this.insert(fd, mappedPath, realPath, type, result.base, result.inheriting, 1);
|
|
238
|
+
}
|
|
239
|
+
async renumber(dst, src) {
|
|
240
|
+
if (dst === src)
|
|
241
|
+
return;
|
|
242
|
+
if (dst >= this.size || src >= this.size) {
|
|
243
|
+
throw new WasiError('Invalid fd', WasiErrno.EBADF);
|
|
244
|
+
}
|
|
245
|
+
const dstEntry = this.fds[dst];
|
|
246
|
+
const srcEntry = this.fds[src];
|
|
247
|
+
if (!dstEntry || !srcEntry || dstEntry.id !== dst || srcEntry.id !== src) {
|
|
248
|
+
throw new WasiError('Invalid fd', WasiErrno.EBADF);
|
|
249
|
+
}
|
|
250
|
+
await dstEntry.fd.close();
|
|
251
|
+
this.fds[dst] = this.fds[src];
|
|
252
|
+
this.fds[dst].id = dst;
|
|
253
|
+
this.fds[src] = undefined;
|
|
254
|
+
this.used--;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|