Commit graph

563 commits

Author SHA1 Message Date
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
7faef8680d Extern after windows.h 2024-07-15 00:23:49 +02:00
Andrew Johnson
af084de6f9 Add 'extern' statements to public headers for C++ compatibility 2024-07-15 00:23:49 +02:00
Saúl Ibarra Corretgé
f9d1029ea3 Fix Linux with GCC 4.8 CI
Complains in the post-ckeckout step:

```
 Post job cleanup.
/usr/bin/docker exec  f32fc88d37a181d710e2802cbad0646c9780efe4af35a093fe68d09d8201a74e sh -c "cat /etc/*release | grep ^ID"
/__e/node20/bin/node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by /__e/node20/bin/node)
```
2024-07-12 16:42:00 +02:00
Nathan Rajlich
b071d36ab5 Rename qjsc -r to qjsc -b 2024-07-04 10:27:39 +02:00
Nathan Rajlich
aa5e4d2132
Add qjsc -r flag to output raw bytecode 2024-07-04 06:52:01 +02:00
Andrew Johnson
76f99007f7 Reduce duplication in Linux and MacOS CI file, improve flexibility 2024-07-03 09:52:00 +02:00
Nathan Rajlich
ba9b4a82ec
Add qjsc -n parameter to override script name stored in bytecode (#459) 2024-07-03 09:51:30 +02:00
Nathan Rajlich
193d1a864f Document qjsc -s flag in help output
The `-s` flag added in #388 was missing in the `-h` help output.
2024-07-03 09:49:13 +02:00
Andrew Johnson
07fa1cbc4a
Add js_dbuf_realloc to avoid ubsan error 2024-07-02 00:43:34 +02:00
Andrew Johnson
b9de2b0bf8 Ignore maybe-uninitialised on MacOS with GCC >= 11 2024-07-01 23:14:06 +02:00
Andrew Johnson
e8ef9d6072 Avoid function name collisions 2024-06-27 22:54:40 +02:00
Andrew Johnson
d489078ea1 Avoid macro and function name collisions between sources 2024-06-27 22:54:40 +02:00
Andrew Johnson
845150232f Remove quickjs-libc from sources when BUILD_QJS_LIBC enabled 2024-06-27 22:53:43 +02:00
Andrew Johnson
136f5a2c66 Cleanup unused-variable warnings 2024-06-24 17:35:01 +02:00
Saúl Ibarra Corretgé
2ea0848616 Add CI for Windows x86 + MSVC 2024-06-17 09:59:46 +02:00
startewho
a008f1c098 Fix the Windows x86 MSVC build
Fixes: https://github.com/quickjs-ng/quickjs/issues/430
2024-06-17 09:59:46 +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
Saúl Ibarra Corretgé
b09ad82622 Now working on 0.6.0 2024-06-07 22:26:48 +02:00
Saúl Ibarra Corretgé
e1e8112f98 Fix uploading all built artifacts to a release 2024-06-07 22:25:01 +02:00
Saúl Ibarra Corretgé
0827b37f8c Set version to 0.5.0 2024-06-07 22:11:28 +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é
a4e48a6a65
Add riscv64 builds to CI 2024-06-07 08:29:50 +02:00
KaruroChori
6efe30b4b4
Improve macro compatibility with C++
Fixes: https://github.com/quickjs-ng/quickjs/issues/425
2024-06-07 08:29:12 +02:00
Charlie Gordon
e36f4bc4b6 add missing include files in headers 2024-06-06 21:09:10 +02:00
nekosu
22c10224ac fix: missing math.h for NAN 2024-06-06 10:26:02 +02:00
nekosu
8ac7c0d51f fix: nested member access 2024-06-05 14:57:09 +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
Frère Jérôme
c7bd41197a Explicit cast in JS_NewInt64 & JS_NewUint32
This avoids the two GCC -Wconversion warnings in this public header, which is useful when using extensive error reporting from the compiler, and treating warnings as errors.
2024-06-04 00:54:56 +02:00
Saúl Ibarra Corretgé
1746ab8e28 Make Linux aarch64 binaries on release too
Fixes: https://github.com/quickjs-ng/quickjs/discussions/417
2024-05-30 09:01:56 +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
Jonathan Barronville
5ca3c509d0
Fixed CMakeLists.txt for Emscripten builds (#403)
Prevent compilation of __run-test262__  for Emscripten (fails due to the `ftw()` usage, but not needed anyway).
2024-05-14 08:44:46 +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é
6cb1301305 Accept "kmg" suffixes for memory limits
Switch the default in the CLI to kilobytes too.
2024-05-06 11:22:16 +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
Saúl Ibarra Corretgé
2050bc782a Fix CLI memory stats output 2024-05-05 19:12:42 +02:00