Commit graph

361 commits

Author SHA1 Message Date
gschwind
1b957f71e3
Fix JS_NewClassID comment (#784) 2025-01-05 20:46:21 +01:00
Ben Noordhuis
99c02eb451
Update stack limit in ASan builds (#778)
Otherwise recursive calls keep going until they trip ASan checks.

Remove the `__ASAN__` and `__UBSAN__` defines; no longer necessary.

Remove `globalThis.__running_with_sanitizer__` from qjs; likewise.

Fixes: https://github.com/quickjs-ng/quickjs/issues/671
Fixes: https://github.com/quickjs-ng/quickjs/issues/775
Fixes: https://github.com/quickjs-ng/quickjs/issues/776
2024-12-30 11:29:22 +01:00
Richard Davison
74fd4d7dc9
Add js_string_eq (#765)
Avoids checking equality when string lengths don't match.

Co-authored-by: Richard Davison <ridaviso@amazon.com>
2024-12-27 22:45:42 +01:00
Richard Davison
7f156b6ef9
Add typed array utility functions 2024-12-22 16:35:10 +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é
53b641d4b3 Fixes timezone bias on Windows
`GetTimeZoneInformation`returns the bias in minutes already, so no need to adjust it.

Also handle the return code since it determines if the time zone is in the daylight saving range.

Ref: https://learn.microsoft.com/en-us/windows/win32/api/timezoneapi/nf-timezoneapi-gettimezoneinformation
Fixes: https://github.com/saghul/txiki.js/issues/325
2024-12-09 22:53:43 +01:00
Ben Noordhuis
66732e78ef
Fix break statement in presence of labels (#742)
In this snippet...

    for (;;) label: break

...the break statement jumped back to the start of the loop instead of
*out* of the loop.

Fixes: https://github.com/quickjs-ng/quickjs/issues/741
2024-12-04 23:56:52 +01:00
Saúl Ibarra Corretgé
fd054b7231 Fix Date.prototype.set* when date is invalid
setYear required special handing since calling date.setYear(NaN) has
specific defined behavior.
2024-11-28 20:45:54 +01:00
Saúl Ibarra Corretgé
c351133dcc Implement Error.captureStackTrace 2024-11-26 12:13:42 +01:00
Ben Noordhuis
0b0b794605
Simplify close_lexical_var (#726)
Its implementation was borderline wrong: calling it with is_arg=TRUE
segfaults because it looks up the var ref index in the wrong array.

Fortunately, there is only one caller and it only passes FALSE.
2024-11-26 00:34:46 +01:00
Penner
61dae5d420 fix crash when add property maybe failed on build arguments 2024-11-25 07:59:23 +01:00
pancake
df44d66291
Do not depend on c99 for(int
NB: The project requires C11, but sicne this is the only occurrence of such kind, we let it slide. See the PR conversation.
2024-11-24 12:46:29 +01:00
Saúl Ibarra Corretgé
4ca6d9bba0
Don't share class functions across Set and Map
Map has groupBy and Set doesn't.

Fixes: https://github.com/quickjs-ng/quickjs/issues/714
2024-11-22 08:33:48 +01:00
Saúl Ibarra Corretgé
ef15418807 Fix null deref in js_iterator_helper_next
Fixes: https://github.com/quickjs-ng/quickjs/issues/705
2024-11-19 19:21:34 +01:00
Saúl Ibarra Corretgé
0b9b6c1915
Simplify iterator helpers code, remove duplication 2024-11-18 23:43:39 +01:00
Ben Noordhuis
f93dd58ea0 Work around msvc definition of NAN
NAN is reportedly no longer a compile-time expression in some versions
of MSVC. Work around that by minting a NaN from a uint64.

Fixes: https://github.com/quickjs-ng/quickjs/issues/622
Fixes: https://github.com/quickjs-ng/quickjs/issues/693
2024-11-18 10:49:30 +01:00
Ben Noordhuis
e1a0f4f1cf
Add Math.sumPrecise (#697) 2024-11-16 11:34:14 +01:00
Saúl Ibarra Corretgé
428204b802 Align JS_SetOpaque with other similar APIs
Returns < 0 on failure. Also document it in the header file.

Fixes: https://github.com/quickjs-ng/quickjs/issues/695
2024-11-16 10:35:01 +01:00
Ben Noordhuis
407683bd98 Add Atomics.pause 2024-11-15 20:30:40 +01:00
bptato
42f0945114 Fix NULL deref in JS_NewRuntime2
The API allows for the malloc_usable_size callback to be NULL, so it
must not be dereferenced before the NULL check.
2024-11-15 15:02:59 +01:00
Saúl Ibarra Corretgé
284510f781 Make Iterator.from spec compliant
Create a proper wrapper around the inner iterator and proxy the calls to
next / return.
2024-11-15 13:35:25 +01:00
Saúl Ibarra Corretgé
559029baad Fix Iterator.prototype
Make sure all descriptors are attached to the one and only iterator
prototype.
2024-11-15 13:16:28 +01:00
Ben Noordhuis
554907e88f
Add RegExp.escape (#687) 2024-11-15 12:17:38 +01:00
Ben Noordhuis
b5d41818e2
Fix bytecode stack frame printing (#686)
Handle OP_get_loc0_loc1 specially. Fixes an off-by-one when printing
variable names.

Fixes: https://github.com/quickjs-ng/quickjs/issues/683
2024-11-14 22:50:42 +01:00
Saúl Ibarra Corretgé
6d7448ed3e Implement Iterator.prototype.flatMap 2024-11-14 19:48:41 +01:00
Ben Noordhuis
1cc19e4dbf
Fix detach check in ArrayBuffer.prototype.resize (#681) 2024-11-13 16:04:49 +01:00
Ben Noordhuis
fa4d2454aa
Add Error.isError (#682)
It's strictly speaking not at phase 3 yet (almost!) but it's very easy
to implement and quite useful.
2024-11-13 15:08:06 +01:00
Saúl Ibarra Corretgé
17a8772379 Implement Iterator.prototype.map 2024-11-13 12:55:25 +01:00
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
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
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
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
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
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