Commit graph

582 commits

Author SHA1 Message Date
Saúl Ibarra Corretgé
4933e17d1b Remove error handling for JS_NewInt64, it's infallible
Also use js_int64(v) internally.
2024-11-12 22:33:22 +01:00
Saúl Ibarra Corretgé
c68c416e2e
Implement Iterator.prototype.filter 2024-11-12 22:01:45 +01:00
Ben Noordhuis
000061f635
Improve performance of variable resolver (#672)
Switch to a hash table when the number of variables grows beyond
a threshold.

Speeds up the test case from the linked issue by about 70%.

Fixes: https://github.com/quickjs-ng/quickjs/issues/456
2024-11-12 21:22:47 +01:00
Saúl Ibarra Corretgé
0362c0a4eb
Implement Iterator.prototype.take (#676) 2024-11-12 08:10:19 +01:00
Ben Noordhuis
487129055f
Work around broken atomics in tinycc (#669) 2024-11-12 01:01:52 +01:00
Saúl Ibarra Corretgé
c41ee4f15f Implement Iterator.prototype.drop
Includes the scaffold for other iterator helper methods that require an
Iterator Helper object.
2024-11-11 22:25:24 +01:00
Ben Noordhuis
243b968ee1 Update to Unicode 16.0 2024-11-09 23:14:52 +01:00
Ben Noordhuis
416ab66f0b Update to Unicode 15.1 2024-11-09 23:14:52 +01:00
Ben Noordhuis
6fdb9b4bbb Update Unicode download URL
Seems I forgot to update the unicode_download.sh script when I upgraded
from Unicode 14.0 to 15.0 in November 2023.
2024-11-09 23:14:52 +01:00
Ben Noordhuis
b29332697b Don't use _Thread_local in run-test262.c
Allows building with tcc and old gcc versions again.
2024-11-09 23:14:20 +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
55b829e666
Update test262_errors.txt after commit 73cc00e (#665)
Commit 73cc00e improves the accuracy of line and column number tracking
but I forgot that that also affects the output of run-test262.
2024-11-09 16:02:44 +01:00
Saúl Ibarra Corretgé
d7c5c7c302 Remove qjs namespace backwards compatibility
Fixes: https://github.com/quickjs-ng/quickjs/issues/650
2024-11-08 22:10:53 +01:00
Saúl Ibarra Corretgé
43151dd78c Fix valgrind and tsan CI
Checkout test262.
2024-11-08 15:09:00 +01:00
Richard Davison
cd2947bded
Don't automatically update test262 submodule 2024-11-08 15:02:48 +01:00
Richard Davison
04307af779 Make "performance" global writable 2024-11-08 08:52:45 +01:00
Ben Noordhuis
73cc00e57e
Improve line:column tracking (#660)
Emit source locations manually for more precise tracking. Don't infer
them from emitted bytecode opcodes because that leads to inaccurate
and sometimes surprising results.

Speeds up code generation (although infinitesimally) as a bonus.

Fixes: https://github.com/quickjs-ng/quickjs/issues/236
2024-11-07 22:03:00 +01:00
Saúl Ibarra Corretgé
c8be383367 Prevent JS_SetOpaque from overriding internal class state
Fixes: https://github.com/quickjs-ng/quickjs/issues/657
2024-11-07 21:26:28 +01:00
Saúl Ibarra Corretgé
e30da0e8bc Don't throw oob exception when setting numeric indexes on TAs
Relevant spec section: https://tc39.es/ecma262/multipage/ordinary-and-exotic-objects-behaviours.html#sec-typedarraysetelement

It should only throw if Object.defineProperty is used and the TA is
detached or OOB if a RAB is used.

Fixes: https://github.com/quickjs-ng/quickjs/issues/645
2024-11-07 19:48:05 +01:00
Ben Noordhuis
9c5c441744
Fix FinalizationRegistry refcounting bug (#656)
Introduced in commit 61c8fe6 from last month that moved the callback
into the job queue:

1. It leaked `fre->held_val` when no job was enqueued

2. It fumbled the reference count when enqueuing; JS_EnqueueJob already
   takes care of incrementing and decrementing it

Reverts commit 0a70623 from earlier today because that didn't turn out
to be a complete fix.

Fixes: https://github.com/quickjs-ng/quickjs/issues/648
2024-11-07 09:12:34 +01:00
Ben Noordhuis
aedd829e61
Fix DUMP_LEAKS memory leak false positive (#655)
Run DUMP_LEAKS after finalizers run; they call js_free_rt too.

Fixes: https://github.com/quickjs-ng/quickjs/issues/654
2024-11-06 22:56:10 +01:00
Ben Noordhuis
83fe8f1166
Fix exception in WeakRef.prototype.deref (#653)
Set the object's opaque to a sentinel value instead of NULL, to stop
JS_GetOpaque2 from raising an "illegal class" exception.

Fixes: https://github.com/quickjs-ng/quickjs/issues/651
2024-11-06 22:54:47 +01:00
Ben Noordhuis
0a706236d7
Move "no more objects" assert to right place (#649)
No test because I can only get it to trigger with qjs, not run-test262,
but the problem is that we need to run FinalizationRegistry finalizers
before asserting no objects remain.

Fixes: https://github.com/quickjs-ng/quickjs/issues/648
2024-11-06 14:54:52 +01:00
Ben Noordhuis
37fe427d59
Add resizable ArrayBuffers (#646)
This commit implements resizable ArrayBuffers - RABs for short - and
extends typed arrays (TAs) to support fixed-length and length-tracking
modes.

SharedArrayBuffers (SABs) also support the maxByteLength option now but
I cheated and allocate all memory upfront because atomically resizing
memory allocations is hard and this commit is already big and complex.

The lion's share is updating all the TA prototype methods to deal with
RABs resizing underneath them. Method arguments can be arbitrary objects
with arbitrary .valueOf methods and arbitrary side effects, like...
resizing the RAB we're currently operating on.

Fixes: https://github.com/quickjs-ng/quickjs/issues/477
2024-11-05 21:55:42 +01:00
Ben Noordhuis
e569f39bf1
Add stack trace to Test262Error (#644)
Only enabled in verboser mode.

Necessary because Test262Error doesn't subclass from Error. Make it tell
not just _what_ but also _where_.
2024-11-04 23:21:52 +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
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