Commit graph

313 commits

Author SHA1 Message Date
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é
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
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
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
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
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
satk0
2344d19220 Fix MSVC compilation when atomics experimental feature is not set 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
Saúl Ibarra Corretgé
a0877514b9 fixup! 2024-10-05 12:35:47 +02:00
Saúl Ibarra Corretgé
3dcadf1518 Fix next token parsing after a function definition
Ref: c06c399f4f
Fixes: https://github.com/quickjs-ng/quickjs/issues/572
2024-10-05 12:35:47 +02:00
Richard Davison
5590756b93
Move JS_{Dup,Free}Value and the RT variants from header, reduced duplication 2024-10-04 09:18:12 +02:00
Ben Noordhuis
1eb9608d64
Fix regexp split with zero-length capture group (#566)
The expected result of `"ab".split(/(c)*/)[1]` is `undefined` but
was in fact `"undefined"` due to unintentional stringification.

Fixes: https://github.com/quickjs-ng/quickjs/issues/565
2024-10-01 01:05:01 +02:00
Ben Noordhuis
348d60985d
Add Iterator.from (#555) 2024-09-27 00:16:50 +02:00
Ben Noordhuis
9a618ed426
Add Iterator.prototype.toArray (#552)
Churn in test262_errors.txt is due to fixing Iterator inheritance,
necessary to make the prototype method actually callable.
2024-09-25 22:45:02 +02:00
Ben Noordhuis
aefdee7b9a
Add Iterator (#548) 2024-09-24 22:07:29 +02:00
Saúl Ibarra Corretgé
3a96b9cb6f Support private brand checks
Fixes: https://github.com/quickjs-ng/quickjs/issues/541
Ref: 3ab1c2b314
2024-09-24 18:37:02 +02:00
Saúl Ibarra Corretgé
c963112349 Fix use of js_malloc_usable_size
Make sure the one set in the malloc functions is used rather than the
default one, since it will likely use a different allocator.

For some reason, this didn't cause a problem on macOS, but it does in
Linux. Opsie! Added some CI to prevent these kinds of bugs.
2024-09-24 18:36:23 +02:00
Saúl Ibarra Corretgé
c25aad7b49
Add ability to (de)serialize symbols
Fixes: https://github.com/quickjs-ng/quickjs/issues/481
2024-09-24 10:01:08 +02:00
Saúl Ibarra Corretgé
d9a43d5a82 Provide a description for unitialized values in JS_ToStringInternal
After 56da486312 it's possible existing
code relied on the current exception not being null to dump it, and the
dumped value just said "[unsupported type]". This change provides a more
descriptive value.
2024-09-24 09:56:34 +02:00
Andrew Johnson
fe5be3cad9 Add JS_SetLength API function 2024-09-20 09:49:51 +02:00
Saúl Ibarra Corretgé
cfeeff91db Refactor JSMallocFunctions to simplify the implementation
Rather than having the user take care of JSMallocState, take care of the
bookkeeping internally (and make JSMallocState non-public since it's no
longer necessary) and keep the allocation functions to the bare minimum.

This has the advantage that using a different allocator is just a few
lines of code, and there is no need to copy the default implementation
just to moficy the call to the allocation function.

Fixes: https://github.com/quickjs-ng/quickjs/issues/285
2024-09-19 20:49:09 +02:00
Saúl Ibarra Corretgé
5f5170796e
regexp: fixed the zero advance logic in quantifiers
Ref: 10fc744ae4
2024-09-14 22:00:48 +02:00
Saúl Ibarra Corretgé
56da486312 Add JS_HasException
Ref: db9dbd0a2b
Ref: 5417ab0159
2024-09-14 21:58:58 +02:00
Ben Noordhuis
8557bd0a0a
Add Set.prototype.isSupersetOf (#532) 2024-09-14 00:19:20 +02:00
Saúl Ibarra Corretgé
ac958f1d2f Optional chaining fixes
Ref: f25e5d4094
2024-09-13 23:27:35 +02:00
Ben Noordhuis
0990875ae8
Add Set.prototype.isSubsetOf (#529) 2024-09-13 22:58:47 +02:00
Ben Noordhuis
12940d7877
Add Set.prototype.isDisjointFrom (#528) 2024-09-13 21:04:09 +02:00
Saúl Ibarra Corretgé
fb70e0994b Simplify realloc
Call to our free wrapper when size is 0.
2024-09-11 22:09:27 +02:00
Saúl Ibarra Corretgé
5a41aaa6a3 Use calloc rather than malloc + memset 2024-09-11 22:09:27 +02:00
Saúl Ibarra Corretgé
5765855089 Silence noisy (and useless) MSVC warnings 2024-09-11 20:15:53 +02:00
Saúl Ibarra Corretgé
d6b4c7d24f Actuall fix zero-length gnu_printf format string warning
Turns out it cannot be disabled through the pragma.
2024-09-11 19:49:52 +02:00
Saúl Ibarra Corretgé
4be1bcdb5e Disable stack checks when running with ASAN in Debug builds
Fixes: https://github.com/quickjs-ng/quickjs/issues/502
2024-09-11 10:32:30 +02:00
Saúl Ibarra Corretgé
6dd2ce308a Fix JS_DetectModule if the first statement is an await 2024-09-10 23:12:21 +02:00