Commit graph

361 commits

Author SHA1 Message Date
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
Ben Noordhuis
b751ed5026
Add Set.prototype.intersection (#511) 2024-09-09 22:08:24 +02:00
Ben Noordhuis
6ba2448751
Add Set.prototype.symmetricDifference (#507) 2024-09-09 19:39:30 +02:00
Saúl Ibarra Corretgé
61c8fe6fb0 Run FinalizationRegistry callback in the job queue
The spec says HostMakeJobCallback has to be used on the callback: https://tc39.es/ecma262/multipage/managing-memory.html#sec-finalization-registry-cleanup-callback

That makes the following (arguably contrived) example run forever until
memory is exhausted.

```js
let count = 0;
function main() {
    console.log(`main! ${++count}`);
    const registry = new FinalizationRegistry(() => {
        globalThis.foo = main();
    });
    registry.register([]);
    registry.register([]);
    return registry;
}
main();

console.log(count);
```

That is unlike V8, which runs 0 times. This can be explained by the
difference in GC implementations and since FinRec makes GC observable,
here we are!

Fixes: https://github.com/quickjs-ng/quickjs/issues/432
2024-09-09 11:32:36 +02:00
Saúl Ibarra Corretgé
c740aa07c1 Fix zero-length gnu_printf format string warning
```
src/quickjs/quickjs.c: In function ‘JS_ReadString’:
src/quickjs/quickjs.c:34274:26: warning: zero-length gnu_printf format string [-Wformat-zero-length]
34274 |         bc_read_trace(s, "");  // hex dump and indentation
      |                          ^~
src/quickjs/quickjs.c: In function ‘JS_ReadFunctionBytecode’:
src/quickjs/quickjs.c:34334:30: warning: zero-length gnu_printf format string [-Wformat-zero-length]
34334 |             bc_read_trace(s, "");   // hex dump + indent
```

Ref: https://github.com/quickjs-ng/quickjs/issues/502
2024-09-09 11:18:02 +02:00
Ben Noordhuis
7513260d9a
Add Set.prototype.difference (#504) 2024-09-07 09:44:55 +02:00
Saúl Ibarra Corretgé
89d9305582 Fix DUMP_MODULE_RESOLVE flag checks
Make sure to always check if the flag is enabled.
2024-09-06 23:19:47 +02:00
Ben Noordhuis
8e81a88a18
Add Set.prototype.union (#499) 2024-09-06 09:24:21 +02:00
Saúl Ibarra Corretgé
77884360d6 Silence format-zero-length warning 2024-09-05 23:24:57 +02:00
Saúl Ibarra Corretgé
048f4278c0 Fix misleading indentation compilation errors 2024-09-05 23:24:57 +02:00
Saúl Ibarra Corretgé
114b8a4095 Enable all debug flags when compiling in debug mode
They still need to be individually enabled either via API or with the -D
CLI flag, but there is no need to modify the code and re-compile.
2024-09-05 23:24:57 +02:00
Ben Noordhuis
8c58e01928
Fix FinalizationRegistry with primitive held value (#496)
Apparently test262 does not test FinalizationRegistry#register() with
held values that are not objects.

Fixes: https://github.com/quickjs-ng/quickjs/issues/494
2024-09-04 12:32:32 +02:00
Ben Noordhuis
9bc41a8a00
Add Float16Array (#491) 2024-09-03 20:32:17 +02:00
Ben Noordhuis
0e5e9c2c49
Fix broken DUMP_BYTECODE debug option (#489)
Broken in commit 1baa6763f8 when unicode_from_utf8 was renamed to
utf8_decode_len.
2024-08-25 11:53:30 +02:00
Ben Noordhuis
568ac13ff5
Optimize js_map_write, don't loop twice (#488) 2024-08-23 17:53:17 +02:00
Ben Noordhuis
cee3b88edb
Fix async iterator missing throw method behavior (#485) 2024-08-22 09:02:11 +02:00
Ben Noordhuis
3a58376485
Support (de)serializing Map and Set objects (#483)
Fixes: https://github.com/quickjs-ng/quickjs/issues/482
2024-08-19 12:20:42 +02:00
Andrew Johnson
b65ed3bb73 Remove unnecessary forward reference for OpCodeEnum 2024-07-30 11:09:21 +02:00
Andrew Johnson
4bfffe8e12 Mark indirect goto and address-as-label as extensions 2024-07-30 11:09:21 +02:00
Andrew Johnson
9ba23f269c Forward reference to enum type 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
Kevin Wang
c4d3833966 Fix declaring property named get/set/async 2024-07-25 23:21:16 +02:00
Dmitry Volyntsev
da5b95dcaf Fix GC leak in js_proxy_get()
Fixes: https://github.com/bellard/quickjs/issues/277
2024-07-16 23:04:18 +02:00
Saúl Ibarra Corretgé
763010663b Add auxiliary structure for retrieving SAB tabs 2024-07-15 16:53:52 +02:00
Saúl Ibarra Corretgé
3ed591c02d Introduce JS_ReadObject2
Analogously to JS_WriteObject2, it allows the user to get a tab with all
the SAB objects that were read.

This can help adjust reference counts in a scenario where a SAB that was
written increased it and it's necessary to decrease it upon reading it.
2024-07-15 16:53:52 +02:00
Saúl Ibarra Corretgé
c011898ea0 Fix memory leak in JS_WriteObject2
If a SAB was written sab_tab will have been allocated. Free it if the
user didn't provide a way to retrieve it.
2024-07-15 08:59:20 +02:00
Andrew Johnson
07fa1cbc4a
Add js_dbuf_realloc to avoid ubsan error 2024-07-02 00:43:34 +02:00
Andrew Johnson
d489078ea1 Avoid macro and function name collisions between sources 2024-06-27 22:54:40 +02:00
Andrew Johnson
136f5a2c66 Cleanup unused-variable warnings 2024-06-24 17:35:01 +02:00
Saúl Ibarra Corretgé
c98d445b63 Save cur_pc on delete OP
Fixes: https://github.com/quickjs-ng/quickjs/issues/431
2024-06-13 12:23:12 +02:00
KaruroChori
ed8f73413c Add getter for GC threshold 2024-06-07 22:07:38 +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
Saúl Ibarra Corretgé
e5673a8e68 Add JS_ToBigUint64
Fixes: https://github.com/quickjs-ng/quickjs/issues/376
2024-06-04 19:03:26 +02:00
Charlie Gordon
3eaea6c4cf Improve number conversions
- pass string length to `js_atof()` instead of end pointer
- get string length from `bf_ftoa()` in `js_bigint_to_string1`
2024-05-27 10:23:21 +02:00
Saúl Ibarra Corretgé
bb4878dd50 Add JS_ThrowPlainError
It's a helper for doing the following steps:

- Building an Error object
- Attaching a formatted message
- Throwing the object

Fixes: https://github.com/quickjs-ng/quickjs/issues/375
2024-05-27 10:11:49 +02:00
Icemic
569f51fba2 Add JS_GetLength 2024-05-27 08:41:40 +02:00
Icemic
9a2a246b51 Add JS_FreePropertyEnum corresponding to JS_GetOwnPropertyNames 2024-05-27 08:41:40 +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
9e67b47c0d
Improve number to string conversions (#400)
integer conversions:
- improve `u32toa_radix` and `u64toa_radix`, add `i32toa_radix`
- use `i32toa_radix` for small ints in `js_number_toString`

floating point conversions (`js_dtoa`):
- complete rewrite with fewer calls to `snprintf`
- remove `JS_DTOA_FORMAT`, define 4 possible modes for `js_dtoa`
- remove the radix argument in `js_dtoa`
- merge `js_dtoa1` into `js_dtoa`
- add `js_dtoa_infinite` for non finite values
- simplify sign handling
- handle locale specific decimal point transparently

helper function `js_fcvt`:
- simplify `js_fcvt`, remove `js_fcvt1`, reduce overhead
- round up manually instead of using `fesetround(FE_UPWARD)`.

helper function `js_ecvt`:
- document `js_ecvt` and `js_ecvt1` behavior
- avoid redundant `js_ecvt1` calls in `js_ecvt`
- fixed buffer contents, no buffer copies
- simplify decimal point handling
- round up manually instead of using `fesetround(FE_UPWARD)`.

miscellaneous:
- remove `CONFIG_PRINTF_RNDN`. This fixes some of the conversion errors
  on Windows. Updated the tests accordingly
- this fixes a v8.sh bug on macOS: `0.5.toFixed(0)` used to produce `0` instead of `1`
- add regression tests, update test_conv unit tests
- add benchmarks for `toFixed`, `toPrecision` and `toExponential` number methods
- benchmarks show all conversions are now 40 to 45% faster (M2)
2024-05-26 08:06:36 +02:00
Charlie Gordon
139b51fe4b
Simplify number parsing (#386)
- use single test in `js_strtod` loop.
- use more explicit `ATOD_xxx` flags
- remove `ATOD_TYPE_MASK`, use `ATOD_WANT_BIG_INT` instead
- remove unused arguments `flags` and `pexponent` in `js_string_to_bigint`
- merge `js_atof` and `js_atof2`, remove `slimb_t *pexponent` argument
- simplify and document `js_atof` parser, remove cumbersome labels,
- simplify `js_parseInt` test for zero radix for `ATOD_ACCEPT_HEX_PREFIX`
- simplify `next_token` number parsing, handle legacy octal in parser only
- simplify `JS_StringToBigInt`, use flags only.
- remove unused `slimb_t exponent` token field
- add number syntax tests
2024-05-26 00:17:04 +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
KaruroChori
f588210641
Cherrypick https://github.com/bellard/quickjs/pull/289 (#404)
Co-authored-by: karurochari <nope>
2024-05-18 10:15:34 +02:00
Charlie Gordon
5a7e578482
Improve parsing error messages (#405)
- output more informative error messages in `js_parse_expect`.

The previous code was bogus:
```
    return js_parse_error(s, "expecting '%c'", tok);
```
this was causing a bug on `eval("do;")` where `tok` is `TOK_WHILE` (-70, 0xBA)
creating an invalid UTF-8 encoding (lone trailing byte).
This would ultimately have caused a failure in `JS_ThrowError2` if `JS_NewString`
failed when converting the error message to a string if the conversion detected the invalid
UTF-8 encoding and throwed an error (it currently does not, but should).

- test for `JS_NewString` failure in `JS_ThrowError2`
- test for `JS_FreeCString` failure in run-test262.c
- add more test cases
2024-05-14 20:36:10 +02:00
KaruroChori
99c6719b7d
Fix invalid exception for class method with name "get"
Ref: https://github.com/bellard/quickjs/pull/258
2024-05-14 09:16:26 +02:00
Charlie Gordon
b81d4deee4
Improve internal string allocation methods (#398)
String values are allocated as temporary or final results. This commit
attempts to improve the consistency and performance of this step.

- define `JS_NewString` as an inline function to allow simple expansion
  of `strlen()` for string literals
- document string contents constraints regarding UTF-8 encoding.
- rename `js_new_string8` as `js_new_string8_len`. takes `const char *`.
- new inline function `js_new_string8` takes `const char *`, computes
  string length with `strlen` and calls `js_new_string8_len`. No overhead
  for string literals
- rename `js_new_string16` to `js_new_string16_len`
- use internal string allocation functions where appropriate, remove overhead
- allocate extra byte for null terminator in source code string
2024-05-10 12:43:35 +02:00
Charlie Gordon
f9ecc1a598
Fix encoding bug in js_dtoa_radix (#399)
- fix radix conversion rounding code: incrementing the digit
  does not work for '9'.  We can assume ASCII so it works for
  all other digits, especially all letters
- also avoid recomputing the string length
2024-05-07 19:35:34 +02:00
Saúl Ibarra Corretgé
e5ae6cf106 Fix handling of memory limit
Default to 0, which is "disabled", just like the stack limit.
2024-05-06 11:22:16 +02:00
Charlie Gordon
a77873d657
Optimize String.fromCharCode and String.fromCodePoint (#391)
- test for common case: single integer argument and create string directly
2024-04-21 08:28:02 +02:00
Charlie Gordon
83726bb00c
Add utility functions for string to integer conversions (#366)
* Add utility functions, improve integer conversion functions

- move `is_be()` to cutils.h
- add `is_upper_ascii()` and `to_upper_ascii()`
- add extensive benchmark for integer conversion variants in **tests/test_conv.c**
- add `u32toa()`, `i32toa()`, `u64toa()`, `i64toa()` based on register shift variant
- add  `u32toa_radix()`, `u64toa_radix()`, `i64toa_radix()` based on length_loop variant
- use direct converters instead of `snprintf()`
- copy NaN and Infinity directly in `js_dtoa1()`
- optimize `js_number_toString()` for small integers
- use `JS_NewStringLen()` instead of `JS_NewString()` when possible
- add more precise conversion tests in microbench.js
- disable some benchmark tests for gcc (they cause ASAN failures)
2024-04-19 11:35:44 +02:00
Charlie Gordon
f326a7a195
Add strip option in qjsc to reduce object size (#388)
- `-s` strips the source code
- `-ss` strips source and line/column numbers information
- `qjsc repl.js` generates an object size of **105726** bytes
- `qjsc -s repl.js` generates an object size of **20853** bytes
- `qjsc -ss repl.js` generates an object size of only **16147** bytes
- compile repl.js with `-ss`
- bump byte code version to 12
2024-04-19 08:41:12 +02:00
Charlie Gordon
43dc65d605
Fix potential conversion errors (#384)
- fix undefined behavior in double to int conversions
- do not pass an `int64_t` to `js_bool()`
2024-04-16 23:18:02 +02:00
bptato
29b45337f0
Fix member accesses for non-decimal numeric literals (#377)
* Fix member accesses for non-decimal numeric literals
    e.g. 0x0.a should return undefined, not SyntaxError.
* Remove ineffective non-decimal float parsing code and redundant checks on `is_float && radix != 10`
    (The code already wasn't doing anything because of the `is_float` check.)
2024-04-16 14:17:50 +02:00
Charlie Gordon
5797f2a716
Improve DUMP_READ_OBJECT (#382)
- improve `JS_DumpString`: use `L` prefix for wide strings
- dump variable kind and flags for locals and closures
- disassemble byte code in DUMP_READ_OBJECT
- pass start_pos to `dump_byte_code` and `dump_single_byte_code`
- write constant pool before function bytecode (bump version to 11)
- update generated code
2024-04-16 09:24:21 +02:00