visaljs 0.0.3 → 0.0.4
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 -1
- package/cli.js +155 -27
- package/node/include/js_node.h +2 -0
- package/node/prelude/async_hooks.js +0 -0
- package/node/prelude/buffer.js +0 -0
- package/node/prelude/events.js +0 -0
- package/node/prelude/fs.js +0 -0
- package/node/prelude/http2.js +0 -0
- package/node/prelude/internal/crypto/asym.js +0 -0
- package/node/prelude/internal/crypto/cipher.js +0 -0
- package/node/prelude/internal/crypto/kdf.js +0 -0
- package/node/prelude/internal/crypto/keys.js +0 -0
- package/node/prelude/internal/crypto/random.js +0 -0
- package/node/prelude/internal/crypto/util.js +0 -0
- package/node/prelude/internal/errors.js +0 -0
- package/node/prelude/internal/querystring.js +0 -0
- package/node/prelude/internal/tls/wrap.js +5 -2
- package/node/prelude/module.js +0 -0
- package/node/prelude/net.js +1 -2
- package/node/prelude/os.js +2 -2
- package/node/prelude/path.js +0 -0
- package/node/prelude/process.js +0 -0
- package/node/prelude/querystring.js +0 -0
- package/node/prelude/stream.js +0 -0
- package/node/prelude/stream_promises.js +0 -0
- package/node/prelude/stream_web.js +0 -0
- package/node/prelude/string_decoder.js +0 -0
- package/node/prelude/tty.js +0 -0
- package/node/prelude/url.js +0 -0
- package/node/prelude/util.js +0 -0
- package/node/prelude/zlib.js +0 -0
- package/node/src/host_fs.c +10 -2
- package/node/src/host_os.c +0 -0
- package/node/src/host_sys.c +44 -32
- package/node/third_party/libuv/LICENSE +0 -0
- package/node/third_party/libuv/include/uv/aix.h +0 -0
- package/node/third_party/libuv/include/uv/bsd.h +0 -0
- package/node/third_party/libuv/include/uv/darwin.h +0 -0
- package/node/third_party/libuv/include/uv/errno.h +0 -0
- package/node/third_party/libuv/include/uv/linux.h +0 -0
- package/node/third_party/libuv/include/uv/os390.h +0 -0
- package/node/third_party/libuv/include/uv/posix.h +0 -0
- package/node/third_party/libuv/include/uv/sunos.h +0 -0
- package/node/third_party/libuv/include/uv/threadpool.h +0 -0
- package/node/third_party/libuv/include/uv/tree.h +0 -0
- package/node/third_party/libuv/include/uv/unix.h +0 -0
- package/node/third_party/libuv/include/uv/version.h +0 -0
- package/node/third_party/libuv/include/uv/win.h +0 -0
- package/node/third_party/libuv/include/uv.h +0 -0
- package/node/third_party/libuv/src/fs-poll.c +0 -0
- package/node/third_party/libuv/src/heap-inl.h +0 -0
- package/node/third_party/libuv/src/idna.c +0 -0
- package/node/third_party/libuv/src/idna.h +0 -0
- package/node/third_party/libuv/src/inet.c +0 -0
- package/node/third_party/libuv/src/queue.h +0 -0
- package/node/third_party/libuv/src/random.c +0 -0
- package/node/third_party/libuv/src/strscpy.c +0 -0
- package/node/third_party/libuv/src/strscpy.h +0 -0
- package/node/third_party/libuv/src/strtok.c +0 -0
- package/node/third_party/libuv/src/strtok.h +0 -0
- package/node/third_party/libuv/src/thread-common.c +0 -0
- package/node/third_party/libuv/src/threadpool.c +0 -0
- package/node/third_party/libuv/src/timer.c +0 -0
- package/node/third_party/libuv/src/unix/async.c +0 -0
- package/node/third_party/libuv/src/unix/bsd-ifaddrs.c +0 -0
- package/node/third_party/libuv/src/unix/core.c +0 -0
- package/node/third_party/libuv/src/unix/darwin-proctitle.c +0 -0
- package/node/third_party/libuv/src/unix/darwin-stub.h +0 -0
- package/node/third_party/libuv/src/unix/darwin-syscalls.h +0 -0
- package/node/third_party/libuv/src/unix/darwin.c +0 -0
- package/node/third_party/libuv/src/unix/dl.c +0 -0
- package/node/third_party/libuv/src/unix/fs.c +0 -0
- package/node/third_party/libuv/src/unix/fsevents.c +0 -0
- package/node/third_party/libuv/src/unix/getaddrinfo.c +0 -0
- package/node/third_party/libuv/src/unix/getnameinfo.c +0 -0
- package/node/third_party/libuv/src/unix/internal.h +0 -0
- package/node/third_party/libuv/src/unix/kqueue.c +0 -0
- package/node/third_party/libuv/src/unix/linux.c +0 -0
- package/node/third_party/libuv/src/unix/loop-watcher.c +0 -0
- package/node/third_party/libuv/src/unix/loop.c +0 -0
- package/node/third_party/libuv/src/unix/pipe.c +0 -0
- package/node/third_party/libuv/src/unix/poll.c +0 -0
- package/node/third_party/libuv/src/unix/process.c +0 -0
- package/node/third_party/libuv/src/unix/procfs-exepath.c +0 -0
- package/node/third_party/libuv/src/unix/proctitle.c +0 -0
- package/node/third_party/libuv/src/unix/random-devurandom.c +0 -0
- package/node/third_party/libuv/src/unix/random-getentropy.c +0 -0
- package/node/third_party/libuv/src/unix/random-getrandom.c +0 -0
- package/node/third_party/libuv/src/unix/random-sysctl-linux.c +0 -0
- package/node/third_party/libuv/src/unix/signal.c +0 -0
- package/node/third_party/libuv/src/unix/stream.c +0 -0
- package/node/third_party/libuv/src/unix/tcp.c +0 -0
- package/node/third_party/libuv/src/unix/thread.c +0 -0
- package/node/third_party/libuv/src/unix/tty.c +0 -0
- package/node/third_party/libuv/src/unix/udp.c +0 -0
- package/node/third_party/libuv/src/uv-common.c +0 -0
- package/node/third_party/libuv/src/uv-common.h +0 -0
- package/node/third_party/libuv/src/uv-data-getter-setters.c +0 -0
- package/node/third_party/libuv/src/version.c +0 -0
- package/node/third_party/libuv/src/win/async.c +98 -0
- package/node/third_party/libuv/src/win/atomicops-inl.h +61 -0
- package/node/third_party/libuv/src/win/core.c +683 -0
- package/node/third_party/libuv/src/win/detect-wakeup.c +56 -0
- package/node/third_party/libuv/src/win/dl.c +135 -0
- package/node/third_party/libuv/src/win/error.c +183 -0
- package/node/third_party/libuv/src/win/fs-event.c +620 -0
- package/node/third_party/libuv/src/win/fs-fd-hash-inl.h +200 -0
- package/node/third_party/libuv/src/win/fs.c +3774 -0
- package/node/third_party/libuv/src/win/getaddrinfo.c +388 -0
- package/node/third_party/libuv/src/win/getnameinfo.c +146 -0
- package/node/third_party/libuv/src/win/handle-inl.h +180 -0
- package/node/third_party/libuv/src/win/handle.c +162 -0
- package/node/third_party/libuv/src/win/internal.h +335 -0
- package/node/third_party/libuv/src/win/loop-watcher.c +122 -0
- package/node/third_party/libuv/src/win/pipe.c +2725 -0
- package/node/third_party/libuv/src/win/poll.c +586 -0
- package/node/third_party/libuv/src/win/process-stdio.c +419 -0
- package/node/third_party/libuv/src/win/process.c +1407 -0
- package/node/third_party/libuv/src/win/req-inl.h +214 -0
- package/node/third_party/libuv/src/win/signal.c +282 -0
- package/node/third_party/libuv/src/win/snprintf.c +42 -0
- package/node/third_party/libuv/src/win/stream-inl.h +54 -0
- package/node/third_party/libuv/src/win/stream.c +252 -0
- package/node/third_party/libuv/src/win/tcp.c +1674 -0
- package/node/third_party/libuv/src/win/thread.c +568 -0
- package/node/third_party/libuv/src/win/tty.c +2460 -0
- package/node/third_party/libuv/src/win/udp.c +1162 -0
- package/node/third_party/libuv/src/win/util.c +1750 -0
- package/node/third_party/libuv/src/win/winapi.c +144 -0
- package/node/third_party/libuv/src/win/winapi.h +4831 -0
- package/node/third_party/libuv/src/win/winsock.c +575 -0
- package/node/third_party/libuv/src/win/winsock.h +160 -0
- package/node/third_party/llhttp/LICENSE +0 -0
- package/node/third_party/llhttp/api.c +0 -0
- package/node/third_party/llhttp/http.c +0 -0
- package/node/third_party/llhttp/llhttp.c +0 -0
- package/node/third_party/llhttp/llhttp.h +0 -0
- package/package.json +1 -1
- package/runtime/include/js_atoms.gen.h +0 -0
- package/runtime/include/js_atoms.h +0 -0
- package/runtime/include/js_bigint.h +0 -0
- package/runtime/include/js_buffer.h +0 -0
- package/runtime/include/js_builtins.h +0 -0
- package/runtime/include/js_console.h +0 -0
- package/runtime/include/js_convert.h +0 -0
- package/runtime/include/js_core.def +0 -0
- package/runtime/include/js_error.h +0 -0
- package/runtime/include/js_exception.h +0 -0
- package/runtime/include/js_function.h +0 -0
- package/runtime/include/js_gc.h +0 -0
- package/runtime/include/js_generator.h +0 -0
- package/runtime/include/js_host.h +0 -0
- package/runtime/include/js_jobs.h +0 -0
- package/runtime/include/js_module.h +0 -0
- package/runtime/include/js_object.h +0 -0
- package/runtime/include/js_ops.h +0 -0
- package/runtime/include/js_promise.h +0 -0
- package/runtime/include/js_regexp.h +0 -0
- package/runtime/include/js_runtime.h +0 -0
- package/runtime/include/js_symbol.h +0 -0
- package/runtime/include/js_web.h +0 -0
- package/runtime/include/jscell.h +0 -0
- package/runtime/include/jscontext.h +0 -0
- package/runtime/include/jsnum.h +0 -0
- package/runtime/include/jsstring.h +0 -0
- package/runtime/include/jsvalue.h +0 -0
- package/runtime/src/arguments.c +0 -0
- package/runtime/src/array.c +0 -0
- package/runtime/src/arraybuffer.c +0 -0
- package/runtime/src/async_iter.c +0 -0
- package/runtime/src/atoms.c +0 -0
- package/runtime/src/base64.c +0 -0
- package/runtime/src/bigint.c +0 -0
- package/runtime/src/blob.c +0 -0
- package/runtime/src/boringssl_support.cc +4 -1
- package/runtime/src/buffer.c +0 -0
- package/runtime/src/builtin_table.c +0 -0
- package/runtime/src/builtins.c +0 -0
- package/runtime/src/builtins_util.h +0 -0
- package/runtime/src/collections.c +0 -0
- package/runtime/src/components.c +0 -0
- package/runtime/src/console.c +0 -0
- package/runtime/src/convert.c +0 -0
- package/runtime/src/core_all.c +0 -0
- package/runtime/src/crypto.c +0 -0
- package/runtime/src/crypto_host.c +0 -0
- package/runtime/src/crypto_kdf.c +0 -0
- package/runtime/src/crypto_key.c +0 -0
- package/runtime/src/date.c +0 -0
- package/runtime/src/domexception.c +0 -0
- package/runtime/src/elements.c +0 -0
- package/runtime/src/elements.h +0 -0
- package/runtime/src/encoding.c +0 -0
- package/runtime/src/error.c +0 -0
- package/runtime/src/events.c +0 -0
- package/runtime/src/exception.c +0 -0
- package/runtime/src/fetch.c +0 -0
- package/runtime/src/function.c +0 -0
- package/runtime/src/gc.c +0 -0
- package/runtime/src/generator.c +0 -0
- package/runtime/src/global.c +0 -0
- package/runtime/src/headers.c +0 -0
- package/runtime/src/inspect.c +0 -0
- package/runtime/src/internal.h +0 -0
- package/runtime/src/iterate.c +0 -0
- package/runtime/src/iterator.c +0 -0
- package/runtime/src/jobs.c +0 -0
- package/runtime/src/jsnum.c +0 -0
- package/runtime/src/json.c +0 -0
- package/runtime/src/math.c +0 -0
- package/runtime/src/module.c +0 -0
- package/runtime/src/number.c +0 -0
- package/runtime/src/object.c +0 -0
- package/runtime/src/ops.c +0 -0
- package/runtime/src/os.c +0 -0
- package/runtime/src/os.h +0 -0
- package/runtime/src/process.c +7 -0
- package/runtime/src/promise.c +0 -0
- package/runtime/src/proxy.c +0 -0
- package/runtime/src/reflect.c +0 -0
- package/runtime/src/regexp.c +0 -0
- package/runtime/src/regexp_anchor.h +0 -0
- package/runtime/src/regexp_message.h +0 -0
- package/runtime/src/shape.c +0 -0
- package/runtime/src/shape.h +0 -0
- package/runtime/src/streams.c +0 -0
- package/runtime/src/streams.h +0 -0
- package/runtime/src/string.c +0 -0
- package/runtime/src/string_builtins.c +0 -0
- package/runtime/src/symbol.c +0 -0
- package/runtime/src/test_host.c +0 -0
- package/runtime/src/typedarray.c +0 -0
- package/runtime/src/tznames.gen.h +0 -0
- package/runtime/src/uri.c +0 -0
- package/runtime/src/url.c +0 -0
- package/runtime/src/weak.c +0 -0
- package/runtime/src/web.c +0 -0
- package/runtime/src/wrapper.c +0 -0
- package/runtime/src/writable.c +0 -0
- package/runtime/third_party/ada-idna/LICENSE-MIT +0 -0
- package/runtime/third_party/ada-idna/README.md +0 -0
- package/runtime/third_party/ada-idna/convert.mjs +0 -0
- package/runtime/third_party/ada-idna/idna.c +0 -0
- package/runtime/third_party/ada-idna/idna.h +0 -0
- package/runtime/third_party/ada-idna/idna_tables.h +0 -0
- package/runtime/third_party/quickjs-dtoa/LICENSE +0 -0
- package/runtime/third_party/quickjs-dtoa/README.md +0 -0
- package/runtime/third_party/quickjs-dtoa/dtoa.c +0 -0
- package/runtime/third_party/quickjs-dtoa/dtoa.h +0 -0
- package/runtime/third_party/quickjs-dtoa/dtoa_compat.h +0 -0
- package/runtime/third_party/quickjs-regexp/LICENSE +0 -0
- package/runtime/third_party/quickjs-regexp/README.md +0 -0
- package/runtime/third_party/quickjs-regexp/cutils.c +0 -0
- package/runtime/third_party/quickjs-regexp/cutils.h +0 -0
- package/runtime/third_party/quickjs-regexp/libregexp-opcode.h +0 -0
- package/runtime/third_party/quickjs-regexp/libregexp.c +0 -0
- package/runtime/third_party/quickjs-regexp/libregexp.h +0 -0
- package/runtime/third_party/quickjs-regexp/libunicode-table.h +0 -0
- package/runtime/third_party/quickjs-regexp/libunicode.c +0 -0
- package/runtime/third_party/quickjs-regexp/libunicode.h +0 -0
- package/runtime/third_party/v8-ieee754/LICENSE +0 -0
- package/runtime/third_party/v8-ieee754/README.md +0 -0
- package/runtime/third_party/v8-ieee754/convert.py +0 -0
- package/runtime/third_party/v8-ieee754/ieee754.c +0 -0
- package/runtime/third_party/v8-ieee754/ieee754.h +0 -0
- package/runtime/tools/regexp_compile.c +0 -0
package/README.md
CHANGED
|
@@ -9,7 +9,9 @@ visaljs build app.js -o app
|
|
|
9
9
|
./app
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
Needs Node 22 or later and a C compiler (`cc`, `gcc` or `clang`). Linux and macOS
|
|
12
|
+
Needs Node 22 or later and a C compiler (`cc`, `gcc` or `clang`). Linux and macOS; on Windows,
|
|
13
|
+
a clang-family compiler: [Zig](https://ziglang.org/) (`winget install zig.zig`) or LLVM-MinGW
|
|
14
|
+
(MSVC isn't supported yet).
|
|
13
15
|
The C runtime is built on first use and cached in `~/.cache/visaljs`.
|
|
14
16
|
|
|
15
17
|
`visaljs build` reports each step as it goes:
|
package/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { isBuiltin } from "node:module";
|
|
3
3
|
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
4
|
-
import { basename, delimiter, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
4
|
+
import { basename, delimiter, dirname, extname, isAbsolute, join, normalize, relative, resolve, sep } from "node:path";
|
|
5
5
|
import { parseArgs } from "node:util";
|
|
6
6
|
import ts from "typescript";
|
|
7
7
|
import { rolldown } from "rolldown";
|
|
@@ -113,7 +113,7 @@ function parse(text, file, module, map, entry, hostPrimitives = {}) {
|
|
|
113
113
|
function locAt(sf, pos, map) {
|
|
114
114
|
const { line, character } = sf.getLineAndCharacterOfPosition(pos);
|
|
115
115
|
const loc = {
|
|
116
|
-
file: sf.fileName,
|
|
116
|
+
file: normalize(sf.fileName),
|
|
117
117
|
line: line + 1,
|
|
118
118
|
column: character + 1
|
|
119
119
|
};
|
|
@@ -248,7 +248,7 @@ var Converter = class {
|
|
|
248
248
|
return {
|
|
249
249
|
type: "Program",
|
|
250
250
|
loc: {
|
|
251
|
-
file: this.sf.fileName,
|
|
251
|
+
file: normalize(this.sf.fileName),
|
|
252
252
|
line: 1,
|
|
253
253
|
column: 1
|
|
254
254
|
},
|
|
@@ -6982,9 +6982,15 @@ function boringsslLibrary() {
|
|
|
6982
6982
|
name: "boringssl",
|
|
6983
6983
|
sources: [...parts.flatMap((p) => [...p.srcs, ...p.asm]).map(at), join(RUNTIME_DIR, "src", "boringssl_support.cc")],
|
|
6984
6984
|
headers: parts.flatMap((p) => [...p.hdrs ?? [], ...p.internal_hdrs ?? []]).map(at),
|
|
6985
|
-
flags: [`-I${join(BORINGSSL, "include")}
|
|
6985
|
+
flags: [`-I${join(BORINGSSL, "include")}`, ...process.platform === "win32" ? BORINGSSL_WINDOWS : []]
|
|
6986
6986
|
};
|
|
6987
6987
|
}
|
|
6988
|
+
const BORINGSSL_WINDOWS = [
|
|
6989
|
+
"-DWIN32_LEAN_AND_MEAN",
|
|
6990
|
+
"-DNOMINMAX",
|
|
6991
|
+
"-D_HAS_EXCEPTIONS=0",
|
|
6992
|
+
...process.arch === "x64" ? ["-DOPENSSL_NO_ASM"] : []
|
|
6993
|
+
];
|
|
6988
6994
|
/** The runtime's libraries, in link order: libjsrt, then the libraries it uses. */
|
|
6989
6995
|
function runtimeLibraries() {
|
|
6990
6996
|
return [runtimeLibrary(), boringsslLibrary()];
|
|
@@ -7590,38 +7596,84 @@ const UV_UNIX = [
|
|
|
7590
7596
|
"tty",
|
|
7591
7597
|
"udp",
|
|
7592
7598
|
"proctitle"
|
|
7593
|
-
];
|
|
7599
|
+
].map((f) => `unix/${f}`);
|
|
7594
7600
|
const UV_PLATFORM = {
|
|
7595
7601
|
linux: {
|
|
7596
|
-
sources: [
|
|
7602
|
+
sources: [...UV_UNIX, ...[
|
|
7597
7603
|
"linux",
|
|
7598
7604
|
"procfs-exepath",
|
|
7599
7605
|
"random-getrandom",
|
|
7600
7606
|
"random-sysctl-linux"
|
|
7601
|
-
],
|
|
7607
|
+
].map((f) => `unix/${f}`)],
|
|
7602
7608
|
defines: ["_GNU_SOURCE", "_POSIX_C_SOURCE=200112"]
|
|
7603
7609
|
},
|
|
7604
7610
|
darwin: {
|
|
7605
|
-
sources: [
|
|
7611
|
+
sources: [...UV_UNIX, ...[
|
|
7606
7612
|
"random-getentropy",
|
|
7607
7613
|
"darwin-proctitle",
|
|
7608
7614
|
"darwin",
|
|
7609
7615
|
"fsevents",
|
|
7610
7616
|
"bsd-ifaddrs",
|
|
7611
7617
|
"kqueue"
|
|
7612
|
-
],
|
|
7618
|
+
].map((f) => `unix/${f}`)],
|
|
7613
7619
|
defines: ["_DARWIN_UNLIMITED_SELECT=1", "_DARWIN_USE_64_BIT_INODE=1"]
|
|
7620
|
+
},
|
|
7621
|
+
win32: {
|
|
7622
|
+
sources: [
|
|
7623
|
+
"async",
|
|
7624
|
+
"core",
|
|
7625
|
+
"detect-wakeup",
|
|
7626
|
+
"dl",
|
|
7627
|
+
"error",
|
|
7628
|
+
"fs",
|
|
7629
|
+
"fs-event",
|
|
7630
|
+
"getaddrinfo",
|
|
7631
|
+
"getnameinfo",
|
|
7632
|
+
"handle",
|
|
7633
|
+
"loop-watcher",
|
|
7634
|
+
"pipe",
|
|
7635
|
+
"thread",
|
|
7636
|
+
"poll",
|
|
7637
|
+
"process",
|
|
7638
|
+
"process-stdio",
|
|
7639
|
+
"signal",
|
|
7640
|
+
"snprintf",
|
|
7641
|
+
"stream",
|
|
7642
|
+
"tcp",
|
|
7643
|
+
"tty",
|
|
7644
|
+
"udp",
|
|
7645
|
+
"util",
|
|
7646
|
+
"winapi",
|
|
7647
|
+
"winsock"
|
|
7648
|
+
].map((f) => `win/${f}`),
|
|
7649
|
+
defines: [
|
|
7650
|
+
"WIN32_LEAN_AND_MEAN",
|
|
7651
|
+
"_WIN32_WINNT=0x0A00",
|
|
7652
|
+
"_CRT_DECLARE_NONSTDC_NAMES=0"
|
|
7653
|
+
],
|
|
7654
|
+
link: [
|
|
7655
|
+
"psapi",
|
|
7656
|
+
"user32",
|
|
7657
|
+
"advapi32",
|
|
7658
|
+
"iphlpapi",
|
|
7659
|
+
"userenv",
|
|
7660
|
+
"ws2_32",
|
|
7661
|
+
"dbghelp",
|
|
7662
|
+
"ole32",
|
|
7663
|
+
"shell32"
|
|
7664
|
+
]
|
|
7614
7665
|
}
|
|
7615
7666
|
};
|
|
7616
7667
|
/** The C libraries to build and link (before libjsrt, which they use). */
|
|
7617
7668
|
function libraries(runtimeInclude) {
|
|
7618
7669
|
const uv = UV_PLATFORM[process.platform];
|
|
7619
|
-
const uvSources = uv ? [...UV_COMMON
|
|
7670
|
+
const uvSources = uv ? [...UV_COMMON, ...uv.sources].map((f) => join(UV, "src", `${f}.c`)) : [];
|
|
7620
7671
|
const uvHeaders = [
|
|
7621
7672
|
join(UV, "include"),
|
|
7622
7673
|
join(UV, "include", "uv"),
|
|
7623
7674
|
join(UV, "src"),
|
|
7624
|
-
join(UV, "src", "unix")
|
|
7675
|
+
join(UV, "src", "unix"),
|
|
7676
|
+
join(UV, "src", "win")
|
|
7625
7677
|
].flatMap((d) => files(d, ".h"));
|
|
7626
7678
|
return [{
|
|
7627
7679
|
name: "jsnode",
|
|
@@ -7651,7 +7703,8 @@ function libraries(runtimeInclude) {
|
|
|
7651
7703
|
...(uv?.defines ?? []).map((d) => `-D${d}`),
|
|
7652
7704
|
`-I${join(UV, "include")}`,
|
|
7653
7705
|
`-I${join(UV, "src")}`
|
|
7654
|
-
]
|
|
7706
|
+
],
|
|
7707
|
+
link: uv?.link ?? []
|
|
7655
7708
|
}];
|
|
7656
7709
|
}
|
|
7657
7710
|
//#endregion
|
|
@@ -7673,7 +7726,7 @@ function hostPrimitives(hosts) {
|
|
|
7673
7726
|
/** A bundling failure, already formatted as `file:line:col: Kind: message` lines. */
|
|
7674
7727
|
var BundleError = class extends Error {};
|
|
7675
7728
|
/** Bundles `entry` with the ADR 0009 configuration, `node:*` imports resolved to the host
|
|
7676
|
-
* packages' modules. Warnings go to `warn
|
|
7729
|
+
* packages' modules. Warnings go to `warn`, with their location ("file:line:col: ", or ""). */
|
|
7677
7730
|
async function bundle(entry, hosts, warn) {
|
|
7678
7731
|
try {
|
|
7679
7732
|
const build = await rolldown({
|
|
@@ -7681,7 +7734,7 @@ async function bundle(entry, hosts, warn) {
|
|
|
7681
7734
|
cwd: dirname(resolve(entry)),
|
|
7682
7735
|
platform: "node",
|
|
7683
7736
|
logLevel: "warn",
|
|
7684
|
-
onLog: (_level, log) => warn(
|
|
7737
|
+
onLog: (_level, log) => log.code !== "EVAL" && warn(logText(log), logWhere(log)),
|
|
7685
7738
|
plugins: [hostModules(hosts)]
|
|
7686
7739
|
});
|
|
7687
7740
|
try {
|
|
@@ -7751,8 +7804,14 @@ module.exports = m;
|
|
|
7751
7804
|
const REQUIRED = "\0visaljs-require:";
|
|
7752
7805
|
/** rolldown's messages carry ANSI colors and a code frame: keep the first line, without the `[CODE]` tag. */
|
|
7753
7806
|
function formatLog(log, kind) {
|
|
7754
|
-
|
|
7755
|
-
|
|
7807
|
+
return `${logWhere(log)}${kind}: ${logText(log)}`;
|
|
7808
|
+
}
|
|
7809
|
+
function logText(log) {
|
|
7810
|
+
return log.message.replace(/\x1b\[[0-9;]*m/g, "").split("\n")[0].replace(/^\[[A-Z_]+\] /, "").trim();
|
|
7811
|
+
}
|
|
7812
|
+
/** "file:line:col: ", "file: ", or "". */
|
|
7813
|
+
function logWhere(log) {
|
|
7814
|
+
return log.loc ? `${log.loc.file ?? log.id}:${log.loc.line}:${log.loc.column + 1}: ` : log.id ? `${log.id}: ` : "";
|
|
7756
7815
|
}
|
|
7757
7816
|
//#endregion
|
|
7758
7817
|
//#region cli/src/cc.ts
|
|
@@ -7979,9 +8038,11 @@ function regexpCompiler(cc) {
|
|
|
7979
8038
|
return tool;
|
|
7980
8039
|
}
|
|
7981
8040
|
/** A program's archives, in link order: the host packages' libraries, then libjsrt (which they
|
|
7982
|
-
* use). Each is built the first time; `building`
|
|
8041
|
+
* use), then the system libraries they need (-l…). Each is built the first time; `building`
|
|
8042
|
+
* hears about it. */
|
|
7983
8043
|
function programArchives(tc, hosts, building) {
|
|
7984
|
-
|
|
8044
|
+
const libraries = [...hosts.flatMap((h) => h.libraries(RUNTIME_INCLUDE)).filter((l) => l.sources.length), ...runtimeLibraries()];
|
|
8045
|
+
return [...libraries.map((l) => libraryArchive(tc, l, building)), ...libraries.flatMap((l) => l.link ?? []).map((l) => `-l${l}`)];
|
|
7985
8046
|
}
|
|
7986
8047
|
/** Compiles program.c and links it with `archives` (programArchives). The linker takes only
|
|
7987
8048
|
* what the program reaches: a program without I/O links no libuv. The libraries keep their
|
|
@@ -8030,6 +8091,68 @@ function scratchDir() {
|
|
|
8030
8091
|
return dir;
|
|
8031
8092
|
}
|
|
8032
8093
|
//#endregion
|
|
8094
|
+
//#region cli/src/eval.ts
|
|
8095
|
+
/** Calls of the global eval that may get source text, and of the global Function (with or
|
|
8096
|
+
* without new), in source order. Aliases (`const F = Function`) aren't followed. */
|
|
8097
|
+
function evalCalls(program, info) {
|
|
8098
|
+
const out = [];
|
|
8099
|
+
const global = (callee, name) => callee.type === "Identifier" && callee.name === name && info.references.get(callee)?.binding === null;
|
|
8100
|
+
const walk = (node) => {
|
|
8101
|
+
if (Array.isArray(node)) {
|
|
8102
|
+
for (const x of node) walk(x);
|
|
8103
|
+
return;
|
|
8104
|
+
}
|
|
8105
|
+
if (node === null || typeof node !== "object") return;
|
|
8106
|
+
const n = node;
|
|
8107
|
+
if (n.type === "CallExpression" || n.type === "NewExpression") {
|
|
8108
|
+
if (global(n.callee, "Function")) out.push({
|
|
8109
|
+
kind: "Function",
|
|
8110
|
+
loc: n.loc
|
|
8111
|
+
});
|
|
8112
|
+
else if (n.type === "CallExpression" && global(n.callee, "eval") && mayBeString(n.arguments[0])) out.push({
|
|
8113
|
+
kind: "eval",
|
|
8114
|
+
loc: n.loc
|
|
8115
|
+
});
|
|
8116
|
+
}
|
|
8117
|
+
for (const [key, value] of Object.entries(node)) if (key !== "loc" && value !== null && typeof value === "object") walk(value);
|
|
8118
|
+
};
|
|
8119
|
+
walk(program.body);
|
|
8120
|
+
return out;
|
|
8121
|
+
}
|
|
8122
|
+
function mayBeString(arg) {
|
|
8123
|
+
if (!arg) return false;
|
|
8124
|
+
switch (arg.type) {
|
|
8125
|
+
case "Literal": return typeof arg.value === "string";
|
|
8126
|
+
case "BigIntLiteral":
|
|
8127
|
+
case "ObjectExpression":
|
|
8128
|
+
case "ArrayExpression":
|
|
8129
|
+
case "FunctionExpression": return false;
|
|
8130
|
+
default: return true;
|
|
8131
|
+
}
|
|
8132
|
+
}
|
|
8133
|
+
/** The warning's message (null: no calls), and with `verbose` a line per call. */
|
|
8134
|
+
function evalWarning(calls, verbose) {
|
|
8135
|
+
if (calls.length === 0) return null;
|
|
8136
|
+
const n = (kind) => calls.filter((c) => c.kind === kind).length;
|
|
8137
|
+
const places = (k) => `${k} ${k === 1 ? "place" : "places"}`;
|
|
8138
|
+
const parts = [];
|
|
8139
|
+
if (n("eval")) parts.push(`eval() of source text in ${places(n("eval"))}`);
|
|
8140
|
+
if (n("Function")) parts.push(`new Function() in ${places(n("Function"))}`);
|
|
8141
|
+
const owners = [...new Set(calls.map((c) => packageOf(c.loc.file) ?? "your code"))];
|
|
8142
|
+
let text = `the program uses ${parts.join(" and ")} (in ${owners.join(", ")}): compiled code can't evaluate source text, so ${calls.length === 1 ? "it throws" : "they throw"} a TypeError if reached`;
|
|
8143
|
+
if (verbose) text += calls.map((c) => `\n ${c.loc.file}:${c.loc.line}:${c.loc.column}: ${c.kind === "eval" ? "eval()" : "new Function()"}`).join("");
|
|
8144
|
+
else text += "\n (--verbose lists them)";
|
|
8145
|
+
return text;
|
|
8146
|
+
}
|
|
8147
|
+
/** The npm package a file belongs to: the last node_modules/<name> (or @scope/name) in its path. */
|
|
8148
|
+
function packageOf(file) {
|
|
8149
|
+
const parts = file.split(/[\\/]/);
|
|
8150
|
+
const i = parts.lastIndexOf("node_modules");
|
|
8151
|
+
if (i < 0 || i + 1 >= parts.length) return null;
|
|
8152
|
+
const name = parts[i + 1];
|
|
8153
|
+
return name.startsWith("@") && i + 2 < parts.length ? `${name}/${parts[i + 2]}` : name;
|
|
8154
|
+
}
|
|
8155
|
+
//#endregion
|
|
8033
8156
|
//#region cli/src/regexp.ts
|
|
8034
8157
|
/** The program's regex literals, in source order. */
|
|
8035
8158
|
function regexpLiterals(program) {
|
|
@@ -8066,7 +8189,7 @@ function compileRegExps(cc, literals) {
|
|
|
8066
8189
|
maxBuffer: 1 << 30
|
|
8067
8190
|
});
|
|
8068
8191
|
if (run.status !== 0) throw new Error(`regexp-compile failed: ${run.stderr || run.error?.message}`);
|
|
8069
|
-
const lines = run.stdout.split(
|
|
8192
|
+
const lines = run.stdout.split(/\r?\n/);
|
|
8070
8193
|
let i = 0;
|
|
8071
8194
|
for (const [key, lit] of todo) {
|
|
8072
8195
|
const line = lines[i++] ?? "";
|
|
@@ -8141,6 +8264,10 @@ var Report = class {
|
|
|
8141
8264
|
this.#write(`${text}\n`);
|
|
8142
8265
|
if (this.#live && this.#running) this.#draw();
|
|
8143
8266
|
}
|
|
8267
|
+
/** A warning, after its location (`where`, if any): printed even when quiet, its label in yellow. */
|
|
8268
|
+
warn(message, where = "") {
|
|
8269
|
+
this.note(`${where}${this.#paint("1;33", "warning:")} ${message}`);
|
|
8270
|
+
}
|
|
8144
8271
|
/** The last line, given the whole build's time. */
|
|
8145
8272
|
finish(icon, text) {
|
|
8146
8273
|
if (this.#style) this.#write(`\n ${icon} ${this.#paint("1", text(since(this.#start)))}\n`);
|
|
@@ -8189,7 +8316,7 @@ function lineCount(text) {
|
|
|
8189
8316
|
}
|
|
8190
8317
|
//#endregion
|
|
8191
8318
|
//#region cli/src/main.ts
|
|
8192
|
-
const VERSION = "0.0.
|
|
8319
|
+
const VERSION = "0.0.4";
|
|
8193
8320
|
const USAGE = `usage: visaljs build <entry.js> [options]
|
|
8194
8321
|
|
|
8195
8322
|
options:
|
|
@@ -8203,6 +8330,7 @@ options:
|
|
|
8203
8330
|
--no-bundle skip the bundler: the input is one ES module (a bundle)
|
|
8204
8331
|
--script compile as a classic script (sloppy mode, no bundler)
|
|
8205
8332
|
-q, --quiet don't report each step of the build
|
|
8333
|
+
--verbose list each place a warning is about
|
|
8206
8334
|
--version print the version
|
|
8207
8335
|
--help print this help
|
|
8208
8336
|
`;
|
|
@@ -8230,6 +8358,7 @@ async function main(argv, io) {
|
|
|
8230
8358
|
type: "boolean",
|
|
8231
8359
|
short: "q"
|
|
8232
8360
|
},
|
|
8361
|
+
verbose: { type: "boolean" },
|
|
8233
8362
|
version: { type: "boolean" },
|
|
8234
8363
|
help: {
|
|
8235
8364
|
type: "boolean",
|
|
@@ -8250,10 +8379,6 @@ async function main(argv, io) {
|
|
|
8250
8379
|
io.stdout(USAGE);
|
|
8251
8380
|
return values.help ? 0 : 2;
|
|
8252
8381
|
}
|
|
8253
|
-
if ((io.platform ?? process.platform) === "win32") {
|
|
8254
|
-
io.stderr("visaljs: Windows is not supported yet; use Linux or macOS (on Windows, WSL works)\n");
|
|
8255
|
-
return 1;
|
|
8256
|
-
}
|
|
8257
8382
|
const [command, ...rest] = positionals;
|
|
8258
8383
|
switch (command) {
|
|
8259
8384
|
case "build":
|
|
@@ -8291,7 +8416,7 @@ async function build(entry, options, io) {
|
|
|
8291
8416
|
const bundled = !script && options["no-bundle"] !== true;
|
|
8292
8417
|
let map;
|
|
8293
8418
|
if (bundled) try {
|
|
8294
|
-
const b = await report.step("📦", "Rolling the modules into a single file", () => bundle(entry, hosts, (message) => report.
|
|
8419
|
+
const b = await report.step("📦", "Rolling the modules into a single file", () => bundle(entry, hosts, (message, where) => report.warn(message, where)), (b) => `Rolled ${count(b.modules, "module")} into a single file (${size(Buffer.byteLength(b.code))})`);
|
|
8295
8420
|
source = b.code;
|
|
8296
8421
|
if (b.map) map = new SourceMap(b.map, displayPath);
|
|
8297
8422
|
} catch (e) {
|
|
@@ -8307,6 +8432,8 @@ async function build(entry, options, io) {
|
|
|
8307
8432
|
return 0;
|
|
8308
8433
|
}
|
|
8309
8434
|
const info = analyze(ast);
|
|
8435
|
+
const evalWarn = evalWarning(evalCalls(ast, info), options.verbose === true);
|
|
8436
|
+
if (evalWarn) report.warn(evalWarn);
|
|
8310
8437
|
const literals = regexpLiterals(ast);
|
|
8311
8438
|
const regexps = literals.length ? await report.step("🧩", "Compiling the regular expressions", () => withCompiler(compilers ??= findCompilers(), report, (cc) => compileRegExps(cc, literals)), () => `Compiled ${count(literals.length, "regular expression")}`) : /* @__PURE__ */ new Map();
|
|
8312
8439
|
const unsupported = firstUnsupported(ast);
|
|
@@ -8337,7 +8464,8 @@ async function build(entry, options, io) {
|
|
|
8337
8464
|
report.finish("📂", (time) => `Wrote ${displayPath(resolve(options["emit-c"], "program.c"))} in ${time}`);
|
|
8338
8465
|
return 0;
|
|
8339
8466
|
}
|
|
8340
|
-
|
|
8467
|
+
let output = options.output ?? basename(entry).replace(/\.[cm]?js$/, "");
|
|
8468
|
+
if (process.platform === "win32" && !extname(output)) output += ".exe";
|
|
8341
8469
|
const opt = options.debug ? ["-O0"] : ["-O2"];
|
|
8342
8470
|
const dir = scratchDir();
|
|
8343
8471
|
try {
|
|
@@ -8398,7 +8526,7 @@ async function withCompiler(compilers, report, run) {
|
|
|
8398
8526
|
function displayPath(source) {
|
|
8399
8527
|
if (source.startsWith("\0")) return source.slice(1);
|
|
8400
8528
|
const rel = relative(process.cwd(), source);
|
|
8401
|
-
return rel.startsWith("..") || isAbsolute(rel) ? source : rel;
|
|
8529
|
+
return rel.startsWith("..") || isAbsolute(rel) ? normalize(source) : rel;
|
|
8402
8530
|
}
|
|
8403
8531
|
//#endregion
|
|
8404
8532
|
//#region cli/src/cli.ts
|
package/node/include/js_node.h
CHANGED
|
@@ -14,6 +14,8 @@ JSValue js_host_fs_exists(JSContext *ctx, JSValue callee, JSValue this_val, uint
|
|
|
14
14
|
JSValue js_host_fs_unlink(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
|
|
15
15
|
|
|
16
16
|
/* host_sys.c */
|
|
17
|
+
/* A C errno as the libuv error code Node reports (-ENOENT on POSIX; UV_ENOENT, -4058, on Windows). */
|
|
18
|
+
int js_node_uv_error(int e);
|
|
17
19
|
JSValue js_host_errno_name(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
|
|
18
20
|
JSValue js_host_timer_unref(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
|
|
19
21
|
JSValue js_host_tty_isatty(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target);
|
|
File without changes
|
package/node/prelude/buffer.js
CHANGED
|
File without changes
|
package/node/prelude/events.js
CHANGED
|
File without changes
|
package/node/prelude/fs.js
CHANGED
|
File without changes
|
package/node/prelude/http2.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// to the transport. The transport is a net.Socket's handle, taken over as Node's TLSWrap takes
|
|
8
8
|
// it (its events come to the TLSSocket), or any Duplex stream (Node's JSStreamSocket case).
|
|
9
9
|
import {
|
|
10
|
-
netReadStart, netReadStop, netShutdown, netWrite, tlsExportKeyingMaterial, tlsFinished, tlsInfo, tlsNew, tlsPeerCerts,
|
|
10
|
+
errnoName, netReadStart, netReadStop, netShutdown, netWrite, tlsExportKeyingMaterial, tlsFinished, tlsInfo, tlsNew, tlsPeerCerts,
|
|
11
11
|
tlsRootCertificates, tlsRun, tlsSession, tlsSetNoRenegotiation, tlsShutdown, tlsVerifyError,
|
|
12
12
|
} from "visaljs:host";
|
|
13
13
|
import { codeError, invalidArgType, outOfRange, validateFunction, validateString } from "../errors.js";
|
|
@@ -31,9 +31,12 @@ const kPendingSession = Symbol("pendingSession");
|
|
|
31
31
|
|
|
32
32
|
const connReset = (message) => codeError(Error, "ECONNRESET", message);
|
|
33
33
|
|
|
34
|
+
/** `read ECONNRESET`: a read fails so on Windows, where the peer's reset isn't an end first */
|
|
34
35
|
function errnoException(errno, syscall) {
|
|
35
|
-
const
|
|
36
|
+
const code = errnoName(errno);
|
|
37
|
+
const e = new Error(syscall + " " + code);
|
|
36
38
|
e.errno = errno;
|
|
39
|
+
e.code = code;
|
|
37
40
|
e.syscall = syscall;
|
|
38
41
|
return e;
|
|
39
42
|
}
|
package/node/prelude/module.js
CHANGED
|
File without changes
|
package/node/prelude/net.js
CHANGED
|
@@ -23,7 +23,6 @@ export { BlockList, isIP, isIPv4, isIPv6, SocketAddress };
|
|
|
23
23
|
const NET_CONNECTION = 0, NET_READ = 1, NET_CONNECT = 2, NET_WRITE = 3, NET_SHUTDOWN = 4, NET_CLOSE = 5;
|
|
24
24
|
const UV_EOF = -4095;
|
|
25
25
|
const UV_EINVAL = -22;
|
|
26
|
-
const UV_ENOTCONN = -107;
|
|
27
26
|
const TIMEOUT_MAX = 2 ** 31 - 1;
|
|
28
27
|
|
|
29
28
|
/* a monotonic clock in ms */
|
|
@@ -506,7 +505,7 @@ export class Socket extends Duplex {
|
|
|
506
505
|
return;
|
|
507
506
|
}
|
|
508
507
|
const err = netShutdown(this._handle);
|
|
509
|
-
if (err ===
|
|
508
|
+
if (err < 0 && errnoName(err) === "ENOTCONN") cb(); /* by name: libuv's code differs by platform */
|
|
510
509
|
else if (err < 0) cb(errnoException(err, "shutdown"));
|
|
511
510
|
else this._shutdownCallback = () => cb();
|
|
512
511
|
}
|
package/node/prelude/os.js
CHANGED
|
@@ -12,8 +12,8 @@ const check = (result, syscall) => {
|
|
|
12
12
|
};
|
|
13
13
|
const uname = () => check(osUname(), "uv_os_uname");
|
|
14
14
|
|
|
15
|
-
export const EOL = "\n";
|
|
16
|
-
export const devNull = "/dev/null";
|
|
15
|
+
export const EOL = process.platform === "win32" ? "\r\n" : "\n";
|
|
16
|
+
export const devNull = process.platform === "win32" ? "\\\\.\\nul" : "/dev/null";
|
|
17
17
|
|
|
18
18
|
export function arch() {
|
|
19
19
|
return process.arch;
|
package/node/prelude/path.js
CHANGED
|
File without changes
|
package/node/prelude/process.js
CHANGED
|
File without changes
|
|
File without changes
|
package/node/prelude/stream.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/node/prelude/tty.js
CHANGED
|
File without changes
|
package/node/prelude/url.js
CHANGED
|
File without changes
|
package/node/prelude/util.js
CHANGED
|
File without changes
|
package/node/prelude/zlib.js
CHANGED
|
File without changes
|
package/node/src/host_fs.c
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
#ifdef _WIN32
|
|
18
18
|
#include <io.h>
|
|
19
|
+
#include <sys/stat.h>
|
|
19
20
|
#define access _access
|
|
20
21
|
#define unlink _unlink
|
|
21
22
|
#define F_OK 0
|
|
@@ -40,7 +41,7 @@ char *js_host_path_arg(JSContext *ctx, uint32_t argc, const JSValue *argv, uint3
|
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
static JSValue errno_result(int e) {
|
|
43
|
-
return js_int32(
|
|
44
|
+
return js_int32(js_node_uv_error(e ? e : EIO));
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
/* fsReadFile(path, bytes): the file's contents as a Buffer when `bytes`, else decoded as UTF-8
|
|
@@ -51,8 +52,15 @@ JSValue js_host_fs_read_file(JSContext *ctx, JSValue callee, JSValue this_val, u
|
|
|
51
52
|
char *path = js_host_path_arg(ctx, argc, argv, 0);
|
|
52
53
|
if (!path) return JS_EXCEPTION;
|
|
53
54
|
FILE *f = fopen(path, "rb");
|
|
55
|
+
int e = errno;
|
|
56
|
+
#ifdef _WIN32
|
|
57
|
+
/* Windows won't open a directory as a file (EACCES); elsewhere the open succeeds and the read
|
|
58
|
+
* fails with EISDIR, which Node reports on Windows too */
|
|
59
|
+
struct _stat st;
|
|
60
|
+
if (!f && e == EACCES && _stat(path, &st) == 0 && (st.st_mode & _S_IFDIR)) e = EISDIR;
|
|
61
|
+
#endif
|
|
54
62
|
free(path);
|
|
55
|
-
if (!f) return errno_result(
|
|
63
|
+
if (!f) return errno_result(e);
|
|
56
64
|
size_t length = 0, cap = 4096;
|
|
57
65
|
char *buf = malloc(cap);
|
|
58
66
|
if (!buf) js_fatal("out of memory");
|
package/node/src/host_os.c
CHANGED
|
File without changes
|
package/node/src/host_sys.c
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/* Host primitives shared by the prelude modules (ADR 0012): error names and messages for
|
|
2
2
|
* -errno results, as libuv words them (Node's err.code and message). The working directory
|
|
3
3
|
* (cwd) is the runtime's, for process.cwd(). */
|
|
4
|
+
#define _POSIX_C_SOURCE 200809L /* libuv's headers (the UV_E* codes): pthread_rwlock_t */
|
|
4
5
|
#include "js_node.h"
|
|
5
6
|
|
|
6
7
|
#include <errno.h>
|
|
7
8
|
#include <stdlib.h>
|
|
8
9
|
#include <string.h>
|
|
10
|
+
#include <uv.h>
|
|
9
11
|
#ifdef _WIN32
|
|
10
12
|
#include <io.h>
|
|
11
13
|
#else
|
|
@@ -16,37 +18,47 @@
|
|
|
16
18
|
#include "js_jobs.h"
|
|
17
19
|
#include "jsstring.h"
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
21
|
+
/* Each error by its C errno and its libuv code: the same number on POSIX, but on Windows libuv
|
|
22
|
+
* has codes of its own (UV_ECONNREFUSED is -4078) while the C library's errno has the C values. */
|
|
23
|
+
#define E(name, message) { name, -UV_##name, #name, message }
|
|
24
|
+
static const struct { int code, uv; const char *name, *message; } ERRORS[] = {
|
|
25
|
+
E(EPERM, "operation not permitted"),
|
|
26
|
+
E(ENOENT, "no such file or directory"),
|
|
27
|
+
E(EIO, "i/o error"),
|
|
28
|
+
E(EBADF, "bad file descriptor"),
|
|
29
|
+
E(EACCES, "permission denied"),
|
|
30
|
+
E(EBUSY, "resource busy or locked"),
|
|
31
|
+
E(EEXIST, "file already exists"),
|
|
32
|
+
E(ENOTDIR, "not a directory"),
|
|
33
|
+
E(EISDIR, "illegal operation on a directory"),
|
|
34
|
+
E(EINVAL, "invalid argument"),
|
|
35
|
+
E(EMFILE, "too many open files"),
|
|
36
|
+
E(EFBIG, "file too large"),
|
|
37
|
+
E(ENOSPC, "no space left on device"),
|
|
38
|
+
E(EROFS, "read-only file system"),
|
|
39
|
+
E(ENAMETOOLONG, "name too long"),
|
|
40
|
+
E(ENOTEMPTY, "directory not empty"),
|
|
41
|
+
E(ELOOP, "too many symbolic links encountered"),
|
|
42
|
+
E(EADDRINUSE, "address already in use"),
|
|
43
|
+
E(EADDRNOTAVAIL, "address not available"),
|
|
44
|
+
E(ECONNRESET, "connection reset by peer"),
|
|
45
|
+
E(ECONNREFUSED, "connection refused"),
|
|
46
|
+
E(EPIPE, "broken pipe"),
|
|
47
|
+
E(EAFNOSUPPORT, "address family not supported"),
|
|
48
|
+
E(ENOTCONN, "socket is not connected"),
|
|
49
|
+
E(ECONNABORTED, "software caused connection abort"),
|
|
50
|
+
E(ETIMEDOUT, "connection timed out"),
|
|
51
|
+
E(ENETUNREACH, "network is unreachable"),
|
|
52
|
+
E(EHOSTUNREACH, "host is unreachable"),
|
|
53
|
+
E(ECANCELED, "operation canceled"),
|
|
49
54
|
};
|
|
55
|
+
#undef E
|
|
56
|
+
|
|
57
|
+
int js_node_uv_error(int e) {
|
|
58
|
+
for (size_t i = 0; i < sizeof ERRORS / sizeof ERRORS[0]; i++)
|
|
59
|
+
if (ERRORS[i].code == e) return -ERRORS[i].uv;
|
|
60
|
+
return -e;
|
|
61
|
+
}
|
|
50
62
|
|
|
51
63
|
static int errno_arg(uint32_t argc, const JSValue *argv) {
|
|
52
64
|
return argc > 0 && js_is_int32(argv[0]) ? -js_as_int32(argv[0]) : 0;
|
|
@@ -58,7 +70,7 @@ JSValue js_host_errno_name(JSContext *ctx, JSValue callee, JSValue this_val, uin
|
|
|
58
70
|
(void)callee, (void)this_val, (void)new_target;
|
|
59
71
|
int e = errno_arg(argc, argv);
|
|
60
72
|
for (size_t i = 0; i < sizeof ERRORS / sizeof ERRORS[0]; i++)
|
|
61
|
-
if (ERRORS[i].code == e) return js_new_string_cstr(ctx, ERRORS[i].name);
|
|
73
|
+
if (ERRORS[i].code == e || ERRORS[i].uv == e) return js_new_string_cstr(ctx, ERRORS[i].name);
|
|
62
74
|
return js_new_string_cstr(ctx, "UNKNOWN");
|
|
63
75
|
}
|
|
64
76
|
|
|
@@ -68,7 +80,7 @@ JSValue js_host_errno_message(JSContext *ctx, JSValue callee, JSValue this_val,
|
|
|
68
80
|
(void)callee, (void)this_val, (void)new_target;
|
|
69
81
|
int e = errno_arg(argc, argv);
|
|
70
82
|
for (size_t i = 0; i < sizeof ERRORS / sizeof ERRORS[0]; i++)
|
|
71
|
-
if (ERRORS[i].code == e) return js_new_string_cstr(ctx, ERRORS[i].message);
|
|
83
|
+
if (ERRORS[i].code == e || ERRORS[i].uv == e) return js_new_string_cstr(ctx, ERRORS[i].message);
|
|
72
84
|
return js_new_string_cstr(ctx, "unknown error");
|
|
73
85
|
}
|
|
74
86
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|