Commit graph

556 commits

Author SHA1 Message Date
Ben Noordhuis
df81c9940f
Make qjs --std switch include bjson module (#640) 2024-10-29 22:56:00 +01:00
Ben Noordhuis
dfe5675f25
Allow 'undefined' in let or const declaration (#639)
Except at the global scope of a classic script because... who knows,
that's just how it is.

Fixes: https://github.com/quickjs-ng/quickjs/issues/633
2024-10-29 22:55:22 +01:00
Ben Noordhuis
42262a7c53
Don't segfault on missing line number data (#641)
Can be reproduced on the CLI but not from a script:

    # should throw "unsupported object class" TypeError
    $ qjs --std -e 'bjson.write(function(){})'
    /path/to/quickjs.c:6510:15: runtime error: applying zero offset to null pointer
2024-10-29 22:52:56 +01:00
Ben Noordhuis
56e5ffa2db
Auto-detect ASan at compile time (#638)
Fixes: https://github.com/quickjs-ng/quickjs/issues/636
2024-10-29 19:54:33 +01:00
Ben Noordhuis
eae9b23843
Improve run-test262 logging (#631)
In verboser mode (-vv):

- show the output of print() calls
- print exception stack traces

Also sneak in a minor bug fix where I forgot to atomically increment
the fixed_errors variable.
2024-10-27 14:33:00 +01:00
Ben Noordhuis
d2bca87c64
Make quickjs.h -Wall -Wextra -pedantic clean (#628)
Fixes: https://github.com/quickjs-ng/quickjs/issues/585
2024-10-26 17:10:18 +02:00
Ben Noordhuis
89883ae657
Add C++ compile test (#615)
Check that quickjs.h parses without error when fed to a C++ compiler.

Fixes: https://github.com/quickjs-ng/quickjs/issues/608
Co-authored-by: Saúl Ibarra Corretgé <s@saghul.net>
2024-10-26 14:01:45 +02:00
Saúl Ibarra Corretgé
82607f4deb Implement Iterator.prototype.some 2024-10-25 22:37:05 +02:00
Saúl Ibarra Corretgé
de58faaee0 Implement Iterator.prototype.reduce 2024-10-25 21:23:44 +02:00
Saúl Ibarra Corretgé
f78d1e6b94 Implement Iterator.prototype.find 2024-10-25 21:23:26 +02:00
Saúl Ibarra Corretgé
0c8aeb1d50 Eval CLI included files as scripts
After 8cd59bf7c4 any file included by qjs
with -I that would parse as a module is eval'd as so, which is usually
not the intent, but rather to define some global functions.
2024-10-24 22:25:13 +02:00
Saúl Ibarra Corretgé
cc11a829e8
Prefix stdlib modules with "qjs:"
Fixes: https://github.com/quickjs-ng/quickjs/issues/616
2024-10-24 22:24:03 +02:00
Saúl Ibarra Corretgé
3339ef7137 Implement Iterator.prototype.forEach 2024-10-24 19:34:58 +02:00
Saúl Ibarra Corretgé
b9a22f9bdd Implement Iterator.prototype.every 2024-10-24 18:07:51 +02: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
Ben Noordhuis
4fbce79521 Fix UndefinedBehaviorSanitizer error
UBSan is right to complain that `s->ptr_last == NULL` when tracing is
disabled.
2024-10-24 09:11:34 +02:00
Adam Satko
62f4713780
Fix stdc atomics detection and add vs2019 msvc job 2024-10-22 20:02:15 +02:00
Saúl Ibarra Corretgé
995de2592a
Avoid requiring atomics on quickjs-libc 2024-10-22 10:24:58 +02:00
Ben Noordhuis
e21d09c347
Remove macos-12 buildbots (#604)
GitHub is deprecating and removing them. We also test macos-14 so I
opted to remove the buildbots instead of upgrading them to a newer
macOS version.
2024-10-20 13:06:18 +02:00
Ben Noordhuis
763076d109
Rework inline cache handling (#609)
Don't store the update flag in the IC because that's a) an out-of-band
signalling mechanism, and b) makes JSInlineCache bigger than it needs
to be. One is allocated per function so it adds up.

Another reason for making this change is that it makes visible what
I strongly suspect are bugs in the original implementation.
2024-10-20 13:02:09 +02:00
Ben Noordhuis
8cd59bf7c4
Improve JS_DetectModule (#610)
It's still not infallible (I don't think it can ever be, the whole
premise is wrong) but hopefully it's a little less fallible now.

Fixes: https://github.com/quickjs-ng/quickjs/issues/606
2024-10-20 12:42:21 +02:00
Ben Noordhuis
bed51fab0a
Allow turning on multiple sanitizers (#611)
Consolidate the ASan and UBSan buildbots and turn on both sanitizers
when fuzzing.
2024-10-20 12:41:17 +02:00
Ben Noordhuis
966dbfc1f9 Fix crash in deserializer on bad regexp 2024-10-18 10:01:34 +02:00
Ben Noordhuis
7be9d99d15 Restrict atom count in deserializer to 1 million
Otherwise it's too easy to tie up too many resources (cpu, memory) by
crafting inputs with a very large atom count (up to 4 billion.)

This may need some finetuning. If the limit proves too restrictive for
very large snapshots, we can make it relative to the size of the input.
2024-10-18 10:01:34 +02:00
Ben Noordhuis
a1d1bce0b7
Fix crash in deserializer (#602)
Check inside the deserializer that const atoms are indeed const, don't
trust the input. The serializer only writes type 0 records for const
atoms but the byte stream may have been corrupted or manipulated.

Overlooked during review of c25aad7 ("Add ability to (de)serialize
symbols")

Found with libfuzzer and it found it _really_ fast. Great tool.
2024-10-17 08:45:04 +02:00
Ben Noordhuis
e4406fa55f
Remove NetBSD CI buildbot (#603)
It's been super flaky due to GHA changes or the vmactions/netbsd-vm@v1
action it depends on, and I'm not invested enough to investigate.

If someone is motivated enough to fix it up, we can bring it back.

Fixes: https://github.com/quickjs-ng/quickjs/issues/600
2024-10-16 23:08:48 +02:00
Ben Noordhuis
857f711e0f
Simplify extract_desc() (#601)
Overlooked in commit 79eee54 from last week.
2024-10-16 21:05:26 +02:00
Richard Davison
afeeebf89e
Expose ctx->function_proto 2024-10-16 20:39:09 +02:00
Ben Noordhuis
36227a5310
Fix cyclic import/export segfault (#568)
Before this commit it segfaulted, now it throws a SyntaxError.
That's still not correct behavior but better than segfaulting.
To be continued.

Includes a small run-test262 fix to handle Windows line endings.

Refs: https://github.com/quickjs-ng/quickjs/issues/567
2024-10-16 10:13:38 +02:00
Saúl Ibarra Corretgé
d9d6939b20 Implement Promise.try 2024-10-15 14:52:40 +02:00
Saúl Ibarra Corretgé
e204fa53a3 Fix CI for setup-alpine
Ref: https://github.com/jirutka/setup-alpine/issues/15
2024-10-15 14:52:40 +02:00
Saúl Ibarra Corretgé
47846c585b Fix definition of minimum_length
It's part of C99 but we require C11 anyway.
2024-10-13 17:50:33 +02:00
Ben Noordhuis
b9be6d4ff2 Run local tests with run-test262 2024-10-10 21:52:34 +02:00
Ben Noordhuis
79eee54b22 Remove obsolete run-test262 style option
We always run the test262 suite in new-style mode.
2024-10-10 21:52:34 +02:00
Ben Noordhuis
3c3c487e11 Build and run run-test262 on Windows
The ulterior motive here is not that I want to increase CI times
further but that I want to repurpose run-test262 for running our
own tests.
2024-10-10 21:52:34 +02:00
Saúl Ibarra Corretgé
364453b3d6
DRY assertion functions in tests 2024-10-10 21:39:12 +02:00
Ben Noordhuis
e145244999
Replace js_mode with is_strict_mode bit field (#590)
Shrinks some structures by one or more bytes and is easier to read.
2024-10-10 19:31:47 +02:00
Ben Noordhuis
681568353c
Enforce buffer length in utf8_encode definition (#589)
Fixes: https://github.com/quickjs-ng/quickjs/issues/464
2024-10-10 18:55:42 +02:00
Saúl Ibarra Corretgé
416dde8458 Remove unused defines in cutils.h 2024-10-10 17:52:39 +02:00
Ben Noordhuis
d79aa871d1
Include <intrin.h> on Windows (#584)
Needed for the definition of _BitScanReverse and _BitScanReverse64.
2024-10-08 22:32:24 +02:00
Saúl Ibarra Corretgé
a51c77efd8
Build all Windows targets when building in CI 2024-10-08 16:58:08 +02:00
satk0
2344d19220 Fix MSVC compilation when atomics experimental feature is not set 2024-10-07 22:34:01 +02:00
satk0
1db8d6cc19 Fix out-of-bound write in libbf 2024-10-07 22:34:01 +02:00
satk0
7491c81153 Don't include pthread on wasi or enscripten 2024-10-07 22:34:01 +02:00
satk0
ba863b1a82 Follow declaration of variables before for loop 2024-10-07 22:34:01 +02:00
satk0
86b1853a21 Improve gcc warning fix 2024-10-07 22:34:01 +02:00
Saúl Ibarra Corretgé
52e0f24048 Fix computed reference on null or undefined 2024-10-07 21:39:59 +02:00
Saúl Ibarra Corretgé
acc0dd9273 Implement proper Symbol.toStringTag for iterators 2024-10-07 21:39:02 +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