Commit graph

64 commits

Author SHA1 Message Date
The Ghost of FOSS' Future
71cd924e82
Update quickjs-libc.c
Some checks are pending
ci / windows-msvc-vs2019 (x64, Debug) (push) Waiting to run
ci / windows-msvc-vs2019 (x64, Release) (push) Waiting to run
ci / windows-clang (Debug) (push) Waiting to run
ci / windows-clang (Release) (push) Waiting to run
ci / windows-ninja (Debug) (push) Waiting to run
ci / windows-ninja (Release) (push) Waiting to run
ci / windows-sdk (Win32, Debug) (push) Waiting to run
ci / windows-sdk (Win32, Release) (push) Waiting to run
ci / windows-sdk (x64, Debug) (push) Waiting to run
ci / windows-sdk (x64, Release) (push) Waiting to run
ci / windows-mingw (Debug, clang64) (push) Waiting to run
ci / windows-mingw (Debug, mingw32) (push) Waiting to run
ci / windows-mingw (Debug, mingw64) (push) Waiting to run
ci / windows-mingw (Debug, ucrt64) (push) Waiting to run
ci / windows-mingw (Release, clang64) (push) Waiting to run
ci / windows-mingw (Release, mingw32) (push) Waiting to run
ci / windows-mingw (Release, mingw64) (push) Waiting to run
ci / windows-mingw (Release, ucrt64) (push) Waiting to run
ci / windows-mingw-shared (push) Waiting to run
ci / emscripten (push) Waiting to run
ci / wasi (push) Waiting to run
ci / cygwin (push) Waiting to run
ci / openbsd (push) Waiting to run
ci / freebsd (push) Waiting to run
ci / android (push) Waiting to run
ci / ios (push) Waiting to run
ci / mimalloc-linux (push) Waiting to run
ci / mimalloc-macos (push) Waiting to run
tsan / linux (push) Waiting to run
valgrind / linux (push) Waiting to run
2025-01-09 01:22:52 +00: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
Saúl Ibarra Corretgé
517e9e274e Add ability to load file as Uint8Array in std.loadFile 2024-12-02 21:17:34 +01:00
Saúl Ibarra Corretgé
f7f70fc579 Fix leak when interpreter exits due to exception
Fixes: https://github.com/quickjs-ng/quickjs/issues/720
2024-11-25 11:07:07 +01:00
Ben Noordhuis
81e50f3cae
Use closefrom() to close open file descriptors (#712)
Replace the naive close() loop in js_os_exec with closefrom().

On my system RLIMIT_NOFILE is set to 1 million and the delay from the
loop gets noticeable when I spawn many processes.

Use dlsym() to look up closefrom() because it's not available everywhere
(looking at you, musl.)

Fixes: https://github.com/quickjs-ng/quickjs/issues/711
2024-11-21 20:43:18 +01:00
Ben Noordhuis
f641d4ff18 Don't use rt->user_opaque in quickjs-libc.c
JS_SetRuntimeOpaque() and JS_GetRuntimeOpaque() are intended for
embedders. Stop using them in quickjs-libc.c
2024-11-09 23:14:20 +01:00
Ben Noordhuis
c53a0a86da
Detect if stdout is a console in quickjs-libc (#642)
Use regular libc stdio (fwrite) when stdout is redirected, don't
call WriteConsoleA because that circumvents the redirection.

Fixes: https://github.com/quickjs-ng/quickjs/issues/635
2024-10-31 11:08:41 +01:00
Ben Noordhuis
caa1bf544d Handle bytecode without IC state
Deserialized bytecode does not have IC state, i.e., `bc->ic == NULL`.
That may or may not be bug (IMO, it is and we should rebuild the
IC state during deserialization) but, either way, don't segfault.

DRY add_ic_slot() and its call sites in a hopefully NFC manner.
2024-10-24 09:11:34 +02:00
Ben Noordhuis
0a79b84ef9 Improve deserializer error message for bytecode
Don't raise a "invalid tag 12" exception when encountering bytecode
and JS_READ_OBJ_BYTECODE is not set, because no one knows what "tag 12"
means without looking it up, not even quickjs maintainers.
2024-10-24 09:11:34 +02:00
Saúl Ibarra Corretgé
995de2592a
Avoid requiring atomics on quickjs-libc 2024-10-22 10:24:58 +02:00
Saúl Ibarra Corretgé
364453b3d6
DRY assertion functions in tests 2024-10-10 21:39:12 +02:00
Ben Noordhuis
9a37c57779
Fix thread-safety issue in quickjs-libc (#578)
`JS_NewClassID(rt, &class_id)` where `class_id` is a global variable
is unsafe when called from multiple threads but that is exactly what
quickjs-libc.c did.

Add a new JS_AddRuntimeFinalizer function that lets quickjs-libc
store the class ids in JSRuntimeState and defer freeing the memory
until the runtime is destroyed. Necessary because object finalizers
such as js_std_file_finalizer need to know the class id and run after
js_std_free_handlers runs.

Fixes: https://github.com/quickjs-ng/quickjs/issues/577
2024-10-07 21:27:38 +02:00
Ben Noordhuis
27715a46bb
Forbid closing stdio from quickjs-libc (#576)
Intrinsically dangerous because it leaves the std{in,out,err} C globals
in an undefined state.
2024-10-07 09:35:09 +02:00
Andrew Johnson
72d4587163
Support printing unicode characters on Windows 2024-09-30 13:30:08 +02:00
Ben Noordhuis
0bf36b98b9
Fix ThreadSanitizer warning in quickjs-libc (#562)
A global function pointer was getting accessed from multiple threads.
Replace it with an atomic integer and an immediate function call.
2024-09-28 22:27:18 +02:00
zeromake
902cc2cf0e
Add native module support on Windows 2024-09-10 22:47:40 +02:00
Saúl Ibarra Corretgé
7ad980704c Report async failures via exit code
Fixes: https://github.com/quickjs-ng/quickjs/issues/340
2024-09-10 21:42:01 +02:00
Saúl Ibarra Corretgé
5bf35450cd Use an integer as the timer handle
Port of
9e561d5c2e
but adapted.
2024-09-09 23:42:53 +02:00
Ben Noordhuis
da1d3cb994
Accept more flags in bjson read/write methods (#479)
Change the last argument from a boolean to an integer and export the
JS_READ_* and JS_WRITE_* flags on the bjson module object.
2024-08-12 16:53:39 +02:00
Ben Noordhuis
5a50ce3b08
Export bjson module (#478)
I find it convenient to have access to JS_ReadObject and JS_WriteObject
from JS land. That's precisely the functionality that tests/bjson.c
provides, ergo, move it into quickjs-libc.c
2024-08-11 11:04:08 +02:00
Andrew Johnson
a959457309 Add recommended workaround for dlsym void* return cast 2024-07-30 11:09:21 +02:00
Andrew Johnson
8f1ac67ea9 Avoid void pointer to function pointer casts 2024-07-30 11:09:21 +02:00
Andrew Johnson
7b0e05dea9 Use ISO C syntax for flexible array members 2024-07-30 11:09:21 +02:00
Saúl Ibarra Corretgé
763010663b Add auxiliary structure for retrieving SAB tabs 2024-07-15 16:53:52 +02:00
Tom Lienard
d3da56b630 Sync TLA implementation with upstream
Fixes: https://github.com/quickjs-ng/quickjs/issues/339
2024-06-07 15:46:44 +02:00
Charlie Gordon
921c1eef50
Simpler utf8_decode (#414)
- no longer pass the array length to `utf8_decode`
- add `utf8_decode_len` for border cases
- use switch based dispatch in `utf8_decode_len` to work around a gcc 12.2 optimizer bug
2024-05-27 08:15:52 +02:00
Charlie Gordon
1baa6763f8
Improve UTF-8 decoding and encoding functions (#410)
Ensure proper UTF-8 encoding (1 to 4 bytes).
Handle invalid encodings (return 0xFFFD and consume a single byte)
Individually encoded surrogate code points are accepted.

- add `utf8_scan()` to analyze a byte array for UTF-8 contents
  detects invalid encoding, computes number of codepoints and content kind:
  plain ASCII, 8-bit, 16-bit or larger codepoints.
- add `utf8_encode_len(c)` to compute the number of bytes to encode `c`
- rename `unicode_to_utf8` as `utf8_encode`
- rename `unicode_from_utf8` as `utf8_decode`
- add `utf8_decode_buf8(dest, size, src, len)` to decode a UTF-8 encoded
  byte array known to contain only ASCII and 8-bit codepoints.
- add `utf8_decode_buf16(dest, size, src, len)` to decode a UTF-8 encoded
  byte array into an array of 16-bit codepoints using UTF-16 surrogate pairs
  for non-BMP1 codepoints.
- add `utf8_encode_buf8(dest, size, src, len)` to encode an array of 8-bit
  codepoints as a UTF-8 encoded null terminated string
- add `utf16_encode_buf8(dest, size, src, len)` to decode an array of 16-bit
  codepoints (including surrogate pairs) as a UTF-8 encoded null terminated string
- detect invalid UTF-8 encoding in RegExp parser
- simplify `JS_AtomGetStrRT`, `JS_NewStringLen` using the above functions
- simplify UTF-8 decoding and error testing
2024-05-21 14:08:33 +02:00
Ben Noordhuis
f80a5b08cf
Implement setInterval() (#338)
Coincidentally fixes a timer ordering bug for which a regression test
has been added.

Fixes: https://github.com/quickjs-ng/quickjs/issues/279
2024-03-30 09:36:38 +01:00
Charlie Gordon
5f8c636cef
Add os.getpid (#320) 2024-03-17 20:01:06 +01:00
Charlie Gordon
5aef8b67b1
fix potential memory leak (#318)
- fix memory leak in `js_std_file_printf`
- fix `errno` clobber in `js_os_stat`
2024-03-16 08:51:58 +01:00
Charlie Gordon
79d417a90d Simplify and clarify URL quoting js_std_urlGet 2024-02-23 11:55:29 +01:00
Felix S
ed49e0f39e Fix shell injection bug in std.urlGet
Refs: https://github.com/bellard/quickjs/pull/61
2024-02-23 11:55:29 +01:00
Saúl Ibarra Corretgé
fb03ca24d2 Add WASI support 2024-02-14 08:59:15 +01:00
Ben Noordhuis
4b138c8923
Run V8 spec conformance test suite (#243)
The shell script runs the tests and diffs stdout against v8.txt.
Lines added/removed means tests were broken/fixed.

Future work is to a) fix failing tests, and b) enable more tests.

A number are disabled for various reasons and mjsunit subdirectories are
currently skipped. Need to decide on a case-by-case basis what is and
isn't relevant to us.

At the moment about 430 tests are run of which approx. 80% pass.
2024-01-02 07:47:40 +01:00
Saúl Ibarra Corretgé
d1852b5ea2 Remove unnecessary casts
Follow-up to https://github.com/quickjs-ng/quickjs/pull/195
2023-12-20 09:02:28 +01:00
Ben Noordhuis
f1b7b6da71
Replace JSValueConst with JSValue (#195)
JSValueConst was only used for the now removed CONFIG_CHECK_JSVALUE
build mode. It is kept around as an alias for JSValue in quickjs.h to
avoid breaking everyone's source builds but remove it everywhere else.
2023-12-10 15:15:42 +01:00
Felipe Gasper
9de152667f
Add NetBSD support (#177) 2023-12-07 15:48:31 +01:00
Saúl Ibarra Corretgé
8128e66145 Add FreeBSD support 2023-12-05 12:34:02 +01:00
Saúl Ibarra Corretgé
478bcf74f2 Add OpenBSD support 2023-12-05 12:34:02 +01:00
Felipe Gasper
56738d8b4b
Add Cygwin compatibility 2023-12-03 18:15:07 +01:00
Ben Noordhuis
a5b9e54151
Re-enable stack depth checks under ASan (#161)
The default 256 kb stack is too small to run some of the test262 tests
when ASAN is enabled.

Double it to 512 kb and ensure threads created by quickjs have big
enough stacks.
2023-11-30 22:18:23 +01:00
Saúl Ibarra Corretgé
bfd8c381cb Add support for building with ClangCL on Windows
Since ClangCL is compatible with MSVC this should get us almost there.

Ref: https://clang.llvm.org/docs/MSVCCompatibility.html
2023-11-30 01:23:09 +01:00
Ben Noordhuis
b6b70e471c
Add os.cputime() (#159)
And use it in microbench to get slightly more accurate results.
2023-11-30 00:05:48 +01:00
Marcin Kolny
699744562e Enable support for GCC compler v < 4.9
GCCv4.8 and lower doesn't ship with stdatomic implementation
(even though they don't define __STD_NO_ATOMICS__ for c11).
If the code is compiled with GCCv4.8 and older, we use builtin
GCC atomic operations instead.

The patch was initially proposed in quickjs's mailing group:
https://www.freelists.org/post/quickjs-devel/PATCH-support-for-older-gcc-versions-whitespace-changes-excluded
2023-11-29 09:22:27 +01:00