106 Commits
Author SHA1 Message Date
Saúl Ibarra Corretgé bb456249d3 Walk the cause chain when dumping uncaught errors (#1509) 2026-05-25 09:39:01 +02:00
Andreas RøsdalandClaude 14892f8b8f Fix errno check in js_waker_signal (#1480)
The retry loop in js_waker_signal used `errno != EAGAIN || errno != EINTR`,
which is always true (any single errno value is unequal to at least one of
the two), so the loop bailed on the first short-write error and silently
dropped the wakeup. Replace with `&&` so the loop only exits on a fatal
errno.

No test: js_waker_signal's transient-error path is reached only when the
pipe is full or the syscall is interrupted by a signal, neither of which
is reliably reproducible in a portable unit test.

Co-authored-by: Claude <[email protected]>
2026-05-17 23:09:03 +02:00
HJfod 01bce21cb7 Support for non-CL Clang on Windows 2026-04-09 12:53:36 +02:00
Ben Noordhuis d17c3228b2 Add support for byte imports (#1420)
Implements https://github.com/tc39/proposal-import-bytes
2026-03-23 22:10:02 +01:00
Ben Noordhuis 2cf4f49c21 Add support for text imports
The two failing tests are:

- a quine (imports itself); needs some more work in the module loader
- dynamic imports; the dynamic loader doesn't support attributes at all
  at the moment
2026-03-21 12:55:22 +01:00
Ben Noordhuis 6d2a9bacbc Improve std file read/write ergonomics (#1365)
- make `pos` and `len` arguments optional
- accept strings in file.write()
2026-02-22 22:34:42 +01:00
Ben Noordhuis 3eb0605721 Add os.mkdtemp() and os.mkstemp() (#1364) 2026-02-21 17:23:07 +01:00
Ben Noordhuis 4f020b26dc Simplify make_obj_error (#1363)
Reimplement it in terms of JS_NewArrayFrom.
2026-02-21 17:21:17 +01:00
Ben Noordhuis e939d4e5b6 Fix file handle leak in js_new_std_file error path (#1362) 2026-02-21 17:20:57 +01:00
Saúl Ibarra Corretgé 4d28bad2f6 Remove SAB support from bjson module 2026-02-19 12:59:25 +01:00
Christian Stewart 6bdf1df2c7 Add WASI reactor build and re-entrant event loop APIs (#1308) 2026-01-21 13:19:49 +01:00
Saúl Ibarra Corretgé bb7a32d541 Add support for import attributes and JSON modules
Ref: https://github.com/bellard/quickjs/commit/f10ef299a6ab4c36c4162cc5840f128f74ec197c
2026-01-08 01:01:10 +01:00
Ben Noordhuis a7ec176ba6 Squelch cl.exe C4232 build warning (#1312)
Statically initialized function pointers are not 100% portable because
functions may not have stable addresses at link time.

Simple fix: don't initialize the function pointers statically.
2026-01-07 23:49:19 +01:00
jwntree 537d004cd2 Fix Illumos build (#1292) 2026-01-04 19:11:40 +01:00
Ben Noordhuis dd1cb4676e Add js_std_set_worker_new_runtime_func() (#1246)
Fixes: https://github.com/quickjs-ng/quickjs/issues/1245
2025-11-23 15:00:52 +01:00
Waldemar Kornewald 38ef7c08cf Support for iOS, tvOS and watchOS (#1214) 2025-10-29 21:11:54 +01:00
Ben Noordhuis 57fffbbb6a Remove unused JSContext argument from JS_IsError (#1206)
Also remove it from JS_IsUncatchableError.

Fixes: https://github.com/quickjs-ng/quickjs/issues/1203
2025-10-20 12:49:46 +02:00
past-dueandFabrice Bellard d100933c49 removed module leak in js_std_eval_binary()
Port of bellard/quickjs@1fdc768fdc

Co-authored-by: Fabrice Bellard <[email protected]>
2025-09-29 22:55:23 +02:00
Ben Noordhuis ce4abdcece Implement os.readdir() natively on Windows (#1132)
Fixes: https://github.com/quickjs-ng/quickjs/issues/968
2025-07-27 21:36:01 +02:00
Ben Noordhuis 3d3b58d881 Enforce R^W in std.popen() (#1101)
Because a popen pipe is unidirectional the mode argument should be
"r" or "w" but not "rw".
2025-06-13 00:08:45 +02:00
Ben Noordhuis f0849adf72 Use poll() instead of select() in js_os_poll (#1097)
It's not safe to add file descriptors > FD_SETSIZE (usually 1,024) to
a fd_set, it writes beyond the buffer. Switch to poll(2).

Fixes: https://github.com/quickjs-ng/quickjs/issues/1096
2025-06-08 21:45:54 +02:00
Pino Toscano 9d0380bd86 Set os.platform as hurd on GNU/Hurd
This makes it possible to detect quickjs is running on GNU/Hurd.
2025-06-04 08:24:26 +02:00
Pino Toscano a9512d4bc4 Use JS__PATH_MAX instead of PATH_MAX in common code
PATH_MAX is optional in POSIX, and it is not available on GNU/Hurd.
There is already a fallback definition called JS__PATH_MAX, so switch
all the common code (i.e. not the bits specific to a certain OS) to use
it.
2025-06-04 08:24:26 +02:00
Pino Toscano 3c4bc745d1 Use ftello() & fseeko() on any OS based on GNU libc
Strictly speaking, they are available in POSIX.1-2008 [1][2], so they
could be used on more platforms/OSes. To be cautious, enable them when
using GNU libc, since they have been available with that libc for a
very long time.

Cherry-pick of bellard/quickjs@8624b5c6f0.

[1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/ftell.html
[2] https://pubs.opengroup.org/onlinepubs/9699919799/functions/fseek.html
2025-06-04 08:24:26 +02:00
Ben Noordhuis 246090a68e Remove unused context argument from JS_IsBigInt (#1063) 2025-05-22 22:18:07 +02:00
Saúl Ibarra Corretgé f316b3d50f Rework promise rejection tracker
This reverts a75498b9c7 and
a4a5a17a9f (except the tests) and adapts
https://github.com/bellard/quickjs/commit/3c39307c22e69e34b85ee766b14b81e4000d71f8
which also passes the tests and feels like a better solution overall.

Ref: https://github.com/quickjs-ng/quickjs/pull/1038
2025-05-20 10:54:54 +02:00
Ben Noordhuis f731e4a3ee Make os.exec support supplementary groups (#1056)
Add a .groups property that is an array of group ids for setgroups.

Fixes: https://github.com/quickjs-ng/quickjs/issues/1055
2025-05-18 22:31:14 +02:00
Saúl Ibarra Corretgé 16785cd45a Add os.exePath
It gets the current executable path. Implementation lifted from libuv.
Currently implemented for the following platforms:

- Linux
- macOS
- Windows
2025-04-16 10:21:07 +02:00
Ben Noordhuis 62fb6362f4 Implement os.Worker on Windows (#1003) 2025-03-31 18:09:56 +02:00
Enno Boland fc3192727f Add pointer cast magic to avoid pedantic warnings with gcc-13
The same trick is used on line 689, so I'm considering it reasonable to
do the same for js_os_exec_once_init.
2025-03-31 09:50:32 +02:00
Zephyr LykosandSaúl Ibarra Corretgé 17757b3e02 quickjs-libc: cast opaque pointer to JSRuntime* in js_std_dbuf_init, suppress clang sanitize warnings
Co-authored-by: Saúl Ibarra Corretgé <[email protected]>
2025-03-08 21:34:55 +01:00
Ben Noordhuis 297a911b21 Add compile-time refcount bug hunt build mode (#952)
Reintroduce JSValueConst and add a JS_CHECK_JSVALUE build mode that
catches reference counting bugs by making JSValue and JSValueConst
different types.

The *vast* majority of this commit is rote work to make our own sources
compile cleanly in said mode.

Refs: https://github.com/quickjs-ng/quickjs/issues/944
2025-03-08 10:30:25 +01:00
Ben Noordhuis e2f61ac35c Support reading script source from stdin in qjs (#947)
Replace js_load_file with something that doesn't choke on special files
and don't call realpath(3) on /dev files because that doesn't work.

Now `echo 'print("hello")' | qjs /dev/stdin` works.

Fixes: https://github.com/quickjs-ng/quickjs/issues/945
2025-03-03 23:49:48 +01:00
Ben Noordhuis e29a713deb Release amalgamated builds (#933)
Roll all the source files into a single jumbo file and release that
along with quickjs.h in a zip file to make embedding for downstream
users easy.

Fixes: https://github.com/quickjs-ng/quickjs/issues/688
2025-02-28 21:12:39 +01:00
Ben Noordhuis 9a902ba3f1 Add std.writeFile (#932)
std.loadFile already exists and is convenient. std.writeFile replaces
the more onerous std.open + std.write + std.close idiom.
2025-02-27 15:52:27 +01:00
Ben Noordhuis 7000a65290 Remove last JSValueConst vestiges (#901) 2025-02-08 22:24:27 +01:00
Ben Noordhuis b091b66364 Unbreak tcc build (#866)
The version of tcc in CI merely warned on unrecognized pragmas but newer
versions treat them as fatal errors.

Upgrade tcc to prevent that from happening again.
2025-01-31 11:37:53 +01:00
Saúl Ibarra Corretgé d162c06278 Add -Wformat=2 compiler flag 2025-01-29 22:43:08 +01:00
Ben Noordhuis 4c32c53a3b Record stack trace for non-object exceptions (#805)
Consider this script that throws an uncaught exception:

    function f() {
        throw "fail"
    }
    f()

Running with `qjs --script t.js` used to print merely:

    fail

But now prints:

    fail
        at f (t.js:2:11)
        at f (t.js:4:1)

qjs has been updated but no public API yet because I still need to think
through the corner cases.

Includes a one-line fix for line:column reporting for throw statements.

Refs: https://github.com/quickjs-ng/quickjs/issues/799
2025-01-24 23:47:37 +01:00
Saúl Ibarra Corretgé ab48ede9ea Handle js_module_set_import_meta errors (#843) 2025-01-22 11:12:43 +01:00
Ben Noordhuis a884e2db88 Add std.file.readAsArrayBuffer() (#835)
Like std.file.readAsString(), except it returns an ArrayBuffer and
doesn't assume anything about the file's character encoding.
2025-01-18 20:42:51 +01:00
Ben Noordhuis d07f6b5232 Handle unprintable objects better in print() (#834)
Before this commit, such objects were printed as `<exception>` because
print() and console.log() had no good way to turn them into strings.

Instead perform the C equivalent of Object.prototype.toString.call(o)
and print the result (which can still error but at least we tried.)

Fixes: https://github.com/quickjs-ng/quickjs/issues/832
2025-01-18 16:04:16 +01:00
Saúl Ibarra Corretgé a7914d1711 Use stdbool rather than custom booleans
Fixes: https://github.com/quickjs-ng/quickjs/issues/817
2025-01-15 14:21:37 +01:00
Saúl Ibarra Corretgé 97ea19dc81 Simplify exiting interpreter with exception
- Avoid keeping the exception object around
- Avoid passing the responsibility of freeing the exeption object to the
  caller
2025-01-08 21:37:49 +01:00
Saúl Ibarra Corretgé 4b8057d512 Exit qjs on unhandled promise rejections
Fixes: https://github.com/quickjs-ng/quickjs/issues/790
2025-01-07 21:27:17 +01:00
Andrew Johnson 8d88f320fb Fix compilation of quickjs-libc under emscripten (#773) 2024-12-27 16:37:34 +01:00
Saúl Ibarra Corretgé be2db73000 Use 1 MB as the default stack size
In addition:

- Move the WASI override to quickjs.c
- Allow it to be user defined

Ref: https://github.com/quickjs-ng/quickjs/issues/749#issuecomment-2540167690
2024-12-17 10:03:17 +01:00
KaruroChori 374915ad0c Rename some internal symbols to avoid collisions 2024-12-15 11:01:16 +01:00
Saúl Ibarra Corretgé 4968ef6e90 Add support for the "x" flag in std.open() 2024-12-03 14:59:50 +01:00
Saúl Ibarra Corretgé e77cfb67b8 Add "compile_module" and "eval_module" flags to std.evalScript
This is preparation for standalone binaries support, we need the ability
to compile source as a module and then evaluate it.
2024-12-02 21:18:08 +01:00