Commit graph

87 commits

Author SHA1 Message Date
Ben Noordhuis
b9be6d4ff2 Run local tests with run-test262 2024-10-10 21:52:34 +02:00
Saúl Ibarra Corretgé
364453b3d6
DRY assertion functions in tests 2024-10-10 21:39:12 +02:00
Ben Noordhuis
d79aa871d1
Include <intrin.h> on Windows (#584)
Needed for the definition of _BitScanReverse and _BitScanReverse64.
2024-10-08 22:32:24 +02:00
Ben Noordhuis
27715a46bb
Forbid closing stdio from quickjs-libc (#576)
Intrinsically dangerous because it leaves the std{in,out,err} C globals
in an undefined state.
2024-10-07 09:35:09 +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
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
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é
5f5170796e
regexp: fixed the zero advance logic in quantifiers
Ref: 10fc744ae4
2024-09-14 22:00:48 +02:00
Saúl Ibarra Corretgé
ac958f1d2f Optional chaining fixes
Ref: f25e5d4094
2024-09-13 23:27:35 +02:00
Saúl Ibarra Corretgé
9bb8a68390 Delete tests/test262.patch
We don't use it.
2024-09-13 21:40:43 +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
Saúl Ibarra Corretgé
7ad980704c Report async failures via exit code
Fixes: https://github.com/quickjs-ng/quickjs/issues/340
2024-09-10 21:42:01 +02:00
Saúl Ibarra Corretgé
54afb19745 Make the timeout test more resilient
Since we don't keep timers sorted by deadline but by insertion order,
the test is flaky in slow environments (GHA seemingly). Increase the
timeouts to give it a bigger chance of success.

ASan / UBSan builds are notoriously slow, so skip the test in those.
2024-09-09 22:42:51 +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é
ad834a1445 Fix Error.prepareStackTrace tests on Windows
- Reset state before doing assertions since they also throw errors
- Make the path check independent of the path separator
2024-09-08 21:50:20 +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
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
Ben Noordhuis
da1d3cb994
Accept more flags in bjson read/write methods (#479)
Change the last argument from a boolean to an integer and export the
JS_READ_* and JS_WRITE_* flags on the bjson module object.
2024-08-12 16:53:39 +02:00
Ben Noordhuis
5a50ce3b08
Export bjson module (#478)
I find it convenient to have access to JS_ReadObject and JS_WriteObject
from JS land. That's precisely the functionality that tests/bjson.c
provides, ergo, move it into quickjs-libc.c
2024-08-11 11:04:08 +02:00
Kevin Wang
c4d3833966 Fix declaring property named get/set/async 2024-07-25 23:21:16 +02:00
Fabrice Bellard
009a60218f regexp: fix non greedy quantizers with zero length matches
Cherry-picked from:
36911f0d3a
2024-07-16 22:23:37 +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
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
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
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
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
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
Null
8dcdb92047
fix crash in js_typed_array_slice caused by memory overlap (#379)
Use memmove instead of memcpy to prevent UB.
Fixes: https://github.com/quickjs-ng/quickjs/issues/378
Co-authored-by: zhang.yuping <zhangyuping.ypz@bytedance.com>
2024-04-15 06:40:00 +02:00
Charlie Gordon
b8a2cf40d8
Fix fix-js-get-string AM/PM computation for Date.prototype.toLocaleString (#355)
- Fix AM/PM computation for Date.prototype.toLocalString: 11:00 and 23:00 used to convert to -1:00
2024-04-07 16:25:03 +02:00
Charlie Gordon
0de570988a
Fix strict name conformity cases (#335)
- reject *future strict reserved words* in `js_parse_function_check_names()`.
- add tests for reserved names in tests/test_language.js
- allow running tests/test_language.js with v8
- update v8.txt
2024-03-30 17:15:25 +01:00
Ben Noordhuis
f80a5b08cf
Implement setInterval() (#338)
Coincidentally fixes a timer ordering bug for which a regression test
has been added.

Fixes: https://github.com/quickjs-ng/quickjs/issues/279
2024-03-30 09:36:38 +01:00
Charlie Gordon
f02ed184a2
Fix more error cases (#332)
* Fix more error cases

- fix more cases of missing `sf->cur_pc`.
- use more precise error messages for number conversion methods
- add test cases in test_builtin.js
- updated v8 test results
2024-03-26 13:22:37 +01:00
Charlie Gordon
3a55b803b0
Make Object.prototype an immutable prototype object (#317)
* make `Object.prototype` an immutable prototype object
* throw an exception on `Object.setPrototypeOf(Object.prototype, xxx)`
* do not throw an exception for `Reflect.setPrototypeOf(Object.prototype, xxx)`
2024-03-16 08:53:29 +01:00
Charlie Gordon
aaa208ac8f
Improve error handling (#297)
* Improve error handling

- throw RangeError for invalid string length
- throw RangeError for stack overflow with updated message
- fix case for `BigInt` error messages
- refine stack check for `next_token` and `json_next_token`
- throw SyntaxError for too many variables, arguments, parameters...
- v8.js: disable v8 specific tests
- v8.js: disable Realm object tests
- v8.js: disable MODULE tests
- v8.js: disable RegExp static properties tests
- use more precise error messages
- reorder property lookup in `js_obj_to_desc()` according to ECMA
- set global object's [Symbol.toStringTag] to "global"
- fix error message for duplicate parameter name in strict mode
2024-03-10 17:04:06 +01:00
Charlie Gordon
648a8f5be1
Improve Date.parse (#289)
* Improve `Date.parse()`

- rewrite `Date.parse()` with separate parsers
- return `NaN` for out of bounds field values as specified
- add `js_tzabbr` and `string_get_tzabbr` to handle timezone abbreviations
- improve `string_get_milliseconds` readability
- accept up to 9 decimals for millisecond fraction but truncate at 3
- accept many more alternative date/time formats
- add test cases in **tests/test_builtin.js**
- produce readable output for `Date` objects in repl 
- use `JSON.stringify` to output `Date` and `string` values in **repl.js**
- remove `String.prototype.__quote`
- add `minimum_length` macro to specify argument array sizes (C99 except MSVC)
- v8.js: parse all environment variables and output them, update **v8.txt**
2024-03-10 10:34:26 +01:00
Ben Noordhuis
f406d6f78c
Accept /[\-]/u as a valid regular expression (#288)
The non-Unicode version of the pattern was already accepted.

test262 tests it in an inverted sense in
test/built-ins/RegExp/unicode_restricted_identity_escape.js but
it appears to be per spec and both V8 and Spidermonkey accept it.

Fixes: https://github.com/quickjs-ng/quickjs/issues/286
2024-03-02 13:29:15 +01:00
Charlie Gordon
47e07b25aa
Fix Map hash bug (#281)
- `map_hash_key` must generate the same key for JS_INT and JS_FLOAT64
   with the same value
- add test cases in tests/test_builtin.js
2024-02-23 11:57:43 +01:00
Charlie Gordon
ef4d8ab2ed
Force evaluation order in set_date_fields (#268) 2024-02-22 14:08:29 +01:00
Ben Noordhuis
9f9bf3c9ab
Fix for/in iteration over proxy objects (#241) 2023-12-30 22:47:32 +01:00
Saúl Ibarra Corretgé
b8402ad388 Fix js_strtod with large integers
Ref: a96f440746
2023-12-23 00:11:41 +01:00
Ben Noordhuis
f0ef9e1593
Implement RegExp 'v' flag, part 1 (#229)
This commit implements the flag itself and teaches the regex engine to
reject previously accepted patterns when in unicodeSets mode.

Refs: https://github.com/quickjs-ng/quickjs/issues/228
2023-12-21 19:37:31 +01:00
Saúl Ibarra Corretgé
4c929c5b6b Implement Error.stackTraceLimit
We default to 10 with a max cap of 64.

Ref: https://v8.dev/docs/stack-trace-api
2023-12-19 22:45:36 +01:00
Saúl Ibarra Corretgé
555d837334 Implement Error.prepareStackTrace support
Based on V8's API: https://v8.dev/docs/stack-trace-api.

Bits picked from Frida: 78fd25fed8

Closes: https://github.com/quickjs-ng/quickjs/issues/134
2023-12-19 15:36:44 +01:00
Ben Noordhuis
5cbf8727a6
Retain function source code in serialized bytecode (#218)
Also fix a small memory leak in the output from `qjsc -e`.

Fixes: https://github.com/quickjs-ng/quickjs/issues/217
2023-12-16 01:01:26 +01:00
Saúl Ibarra Corretgé
e5812862f9 Fix 'return' handling with 'yield' in 'for of' or with finally blocks
Ref: 4bb8c35da7
2023-12-14 11:49:14 +01:00
Ben Noordhuis
bace4f635e
Record source column positions (#193)
And:
- display them in stack traces
- expose them as Function.prototype.columnNumber

OP_line_num is renamed to OP_source_loc and the pc2line data structure
is extended with the column number in zigzag encoding.

The bytecode version number BC_VERSION is incremented because pc2line
data is read and written by JS_ReadObject() and JS_WriteObject() when
it is present.

Fixes: https://github.com/quickjs-ng/quickjs/issues/149
2023-12-11 22:36:13 +01:00