Commit Graph

177 Commits

Author SHA1 Message Date
jieke
83fa050312 Improve JS_GetArrayBuffer 2024-10-12 12:01:58 +08:00
Akos Kiss
6e2e68fd08 Fix termination in Worker test
Function names are case sensitive, `onMessage` is not the same as
`onmessage`.

Related to #98
2024-07-27 23:40:48 +02:00
Pino Toscano
012451d5f3 Define a fallback PATH_MAX if not available
PATH_MAX is optional in POSIX, and it is not available on GNU/Hurd.
While it could be possible to not rely on PATH_MAX, for now provide a
fallback definition (which should be safe enough) to get quickjs built
on GNU/Hurd.
2024-07-21 10:24:01 +02:00
Pino Toscano
8624b5c6f0 Use ftello() & fseeko() on any OS based on GNU libc
Strictly speaking, they are available in POSIX.1-2008 [1][2], so they
could be used on more platforms/OSes. To be cautious, enable them when
using GNU libc, since they have been available with that libc for a
very long time.

[1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/ftell.html
[2] https://pubs.opengroup.org/onlinepubs/9699919799/functions/fseek.html
2024-07-21 10:24:01 +02:00
Pino Toscano
34894936d8 Use malloc_usable_size() on any OS based on GNU libc
malloc_usable_size() is a GNU extension in GNU libc; hence, use it
every time GNU libc is used, rather than only on Linux.
2024-07-21 10:24:01 +02:00
Kasper Isager Dalsgarð
5417ab0159
Fix JS_HasException() when null is thrown (#313)
Use `JS_UNINITIALIZED` instead of `JS_NULL` when no exception is pending, so `null` can be thrown and distinguished from no exception pending.
2024-07-17 13:58:08 +02:00
Dmitry Volyntsev
b3715f7cb1
Fix GC leak in js_proxy_get() (#302)
Fixes #277
2024-07-15 00:08:40 +02:00
Fabrice Bellard
36911f0d3a regexp: fix non greedy quantizers with zero length matches 2024-05-30 16:41:37 +02:00
Fabrice Bellard
d86aaf0b8f updated test262.patch 2024-05-30 15:49:31 +02:00
Fabrice Bellard
adec734346 fixed test of test262 directory 2024-05-30 15:36:20 +02:00
Charlie Gordon
d378a9f3a5
Improve js_os_exec (#295)
- use $(shell) make command to test if closefrom() is available
- use closefrom() if available in js_os_exec()
- limit the fallback loop to 1024 handles to avoid costly loop on linux alpine.
PR inspired by @nicolas-duteil-nova
2024-05-10 01:57:55 +02:00
Charlie Gordon
97be5a32af
Add js_resolve_proxy (#293)
- simplify `JS_IsArray` for proxy chains
- remove `js_proxy_isArray`
2024-05-09 14:14:50 +02:00
Kasper Isager Dalsgarð
f3f2f42717
Add JS_StrictEq(), JS_SameValue(), and JS_SameValueZero() (#264)
* add `JS_StrictEq()`, `JS_SameValue()`, and `JS_SameValueZero()` all accepting `JSValueConst`
* make `js_strict_eq` accept `JSValueConst`, remove uses of this function internally and replace them with
`js_strict_eq2` instead.
2024-05-09 13:07:40 +02:00
Kasper Isager Dalsgarð
6f9d05fd2b
Expose JS_SetUncatchableError() (#262)
* Expose `JS_SetUncatchableError()`

* Remove unnecessary `JS_SetUncatchableError` declaration
2024-05-09 12:45:47 +02:00
Renáta Hodován
d53aafe0f3
Add the missing fuzz_common.c (#292) 2024-05-09 12:36:12 +02:00
Kasper Isager Dalsgarð
db9dbd0a2b
Add JS_HasException() (#265) 2024-05-08 23:19:15 +02:00
Dmitry Volyntsev
6c43013140
Add JS_NewTypedArray() (#272) 2024-05-08 23:17:00 +02:00
Renáta Hodován
01454caf78
OSS-Fuzz targets improvements (#267)
* Move fuzz target sources from the oss-fuzz repository here

* Add support to build libFuzzer targets
* Simplify the fuzz_eval and fuzz_compile targets

The use of JS_NewContext instead of JS_NewContextRaw spares to call
JS_AddIntrinsic<XYZ> functions from the fuzz target, since the public
JS_NewContext API does exactly the same.

* Simplify the fuzz_regexp target

fuzz_regexp doesn't need to be dependant on libquickjs since the
runtime and the context - that were provided by libquickjs - were
only created to call two simple functions implemented in libquickjs
which could be mimicked by the fuzzer.
The removal of runtime and context objects implicated further
simplifications, like the omission of their one-time creation.
Finally, writing the result of the regexp operations into a file
is also superfluous, since it's not used by anybody.

* Recreate and destroy JS runtime and context in fuzz_eval and fuzz_compile targets

Before this patch, the test executions were not independent,
since all the executed tests used the same JavaScript runtime and
context, causing irreproducible failure reports.

* Enable bignumber support in eval and compile targets

Big numbers are used by the input corpus, but the targets were not
able to interpret them since they were not compiled into them.
This change improved the inital coverage of the fuzz_eval target with
21% and the coverage of the fuzz_compile target with 25% when using
the official corpus.

* Ensure std and os modules are available in the fuzz_eval and fuzz_compile targets
* Add fuzzer dictionary with builtin and variable names. Furthermore, added a JS script that collects all the builtin
names from the executing engine. 
* Move common fuzzer code into one place
* Enable to define the LIB_FUZZING_ENGINE variable to ease the oss-fuzz integration
* Add README to fuzzers
2024-05-08 18:19:48 +02:00
Charlie Gordon
0c8fecab23
Improve class parser (#289)
- accept `class P { async = 1 }}`
- accept `class P { static = 1 }}` etc.
- Fixes #261
2024-05-05 19:54:47 +02:00
Richard Davison
d9c699f528
fix class method with name get (#258)
Co-authored-by: Richard Davison <ridaviso@amazon.com>
2024-05-05 18:46:30 +02:00
Charlie Gordon
7a2c6f42d4
Improve libunicode and libregexp headers (#288)
- move all `lre_xxx` functions to libunicode
- use flags table `lre_ctype_bits` instead of bitmaps
- simplify `lre_is_space`, `lre_js_is_ident_first` and `lre_js_is_ident_next`
- simplify `simple_next_token`, handle UTF-8 correctly
- simplify `is_let`, remove dead code
2024-05-05 17:47:40 +02:00
Charlie Gordon
1402478d8d
Improve unicode table handling (#286)
- Document table and index formats
- Add size statistics
- Fix UBSAN issue in `get_le24()`

Fixes #285
2024-05-05 12:10:24 +02:00
Charlie Gordon
3b45d155c7 Fix endianness handling in js_dataview_getValue / js_dataview_setValue 2024-03-23 13:19:04 +01:00
Charlie Gordon
653b2276cb Improve error handling
- detect and report invalid duplicate parameter names
- throw RangeError for too many function arguments
- throw RangeError for invalid string length
- prevent `-Wcast-function-type` warnings
2024-03-23 12:58:53 +01:00
Charlie Gordon
203fe2d539 Improve JSON.stringify
- changed error messages
- clarify `toJSON` method usage
- simplify boxed objects handling
- for ECMA conformity, BigInt objects need a toJSON method in the prototype chain
  including boxed objects
2024-03-23 12:43:45 +01:00
Charlie Gordon
ce6b6dcacd Use more explicit magic values for array methods 2024-03-23 09:52:23 +01:00
Charlie Gordon
c0e67c47cd Simplify redundant initializers for JS_NewBool() 2024-03-23 09:28:38 +01:00
Charlie Gordon
06651314f5 Fix compilation with -DCONFIG_BIGNUM
- disable BigDecimal convertion in `JS_ReadBigNum`
- fix some error messages
2024-03-22 11:23:33 +01:00
Charlie Gordon
65ecb0b0d6 Improve Date.parse, small fixes
- add `minimum_length` to enforce array length validation
- add `JS_NewDate()` API
- add `[Symbol.toStringTag]` property in the global object
- simplify `string_get_milliseconds`
- support more timezone abbrevs using `string_get_tzabbr` and array
2024-03-22 00:47:17 +01:00
Charlie Gordon
6a89d7c270
Add CI targets, fix test_std.js (#247)
This switches the exec test to `SIGTERM` rather than `SIGQUIT` since the
latter didn’t seem to work in QEMU, and the distinction doesn’t really
matter for this test.

This also makes the `isatty()` check smarter by checking whether `STDIN`
is, in fact, a terminal.

Added qemu-alpine targets i386, arm32v6, arm32v7, arm64v8, s390x

Co-authored-by: Felipe Gasper <felipe@felipegasper.com>
2024-03-03 21:57:38 +01:00
Kanstantsin Sokal
ebe7496d14
Fix build: use LRE_BOOL in libunicode.h (#244) 2024-03-03 15:36:00 +01:00
Charlie Gordon
1a5333bcb3 prevent 0 length allocation in js_worker_postMessage 2024-03-03 14:42:01 +01:00
Ben Noordhuis
e17cb9fc7a Add github CI tests
- disable `isatty()` test in `test_os()`
- add `.github/workflows/ci.yml` with 8 targets
2024-03-03 14:14:23 +01:00
Charlie Gordon
06c100c9bf Prevent UB on memcpy and floating point conversions
- add `memcpy_no_ub` that accepts null pointers for 0 count
- prevent 0 length allocation in `js_worker_postMessage`
- use safer test for `int` value in `JS_NewFloat64`,
  `JS_ToArrayLengthFree` and `js_typed_array_indexOf`
2024-03-03 14:05:40 +01:00
Charlie Gordon
3dd93eb4e4
fix microbench when microbench.txt is missing (#246) 2024-03-03 03:38:49 +01:00
Charlie Gordon
35b7b3c379 Improve Date.parse
- accept many more alternative date/time formats
- add test cases in tests/test_builtin.js
- match month and timezone names case insensitively
- accept AM and PM markers
- recognize US timezone names
- skip parenthesized stuff
- fix almost all v8 test cases
2024-03-03 02:59:08 +01:00
Charlie Gordon
8d64731eb8 Improve Number.prototype.toString for radix other than 10
- fix the conversions for integers and exact fractions
- approximate approach for other cases.
- bypass floating point conversions for JS_TAG_INT values
- avoid divisions for base 10 integer conversions
2024-03-02 15:13:18 +01:00
Charlie Gordon
a78d2cbf7c Improve repl regexp handling
- handle regexp with flags in repl completion
- group config_jscalc customisations
2024-03-02 14:36:44 +01:00
Charlie Gordon
8180d3dd87 Improve microbench.js
- ensure handler behavior does not depend on n argument
- load and save reference file in node.js
- add -s filename option to name the output reference file
- add targets in Makefile for tests and bencharks using node.js
- fix incorrect timings when not using high resolution timer
- use performance timer in node.js
- output performance factor instead of percentage
- use smaller threshold by default
- add benchmarks for:
    date_parse(), prop_update(), prop_clone(), array_slice()
    global_func_call(),
2024-02-26 00:14:31 +01:00
Charlie Gordon
78db49cf95 Improve Date.parse
- rewrite Date.parse() with separate parsers
- return `NaN` for out of bounds field values as specified
- 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
2024-02-25 23:47:26 +01:00
Charlie Gordon
6428ce0c8b show readable representation of Date objects in repl 2024-02-25 22:53:29 +01:00
Charlie Gordon
27928ce491 Fix Map hash bug
- `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-22 19:31:57 +01:00
Charlie Gordon
b70e764427 Rewrite set_date_fields to match the ECMA specification
- use `double` arithmetic where necessary to match the spec
- use `volatile` to ensure correct order of evaluation
  and prevent FMA code generation
- reject some border cases.
- avoid undefined behavior in `double` -> `int64_t` conversions
- improved tests/test_builtin.js `assert` function to compare
  values more reliably.
- added some tests in `test_date()`
- disable some of these tests on win32 and cygwin targets
2024-02-21 21:22:10 +01:00
Tyler Rockwood
b91a2aec67 Add C API function JS_GetClassID()
If you want to extend a built-in class you need it's class ID and there
is no robust way to get that without this accessor.

* add JS_INVALID_CLASS_ID constant for invalid class ID.

Signed-off-by: Tyler Rockwood <rockwood@redpanda.com>
2024-02-21 15:33:37 +01:00
Charlie Gordon
12c91df577 Improve surrogate handling readability
- add inline function to test and convert surrogates
  is_surrogate(c), is_hi_surrogate(c), is_lo_surrogate(c),
  get_hi_surrogate(c), get_lo_surrogate(c), from_surrogate(hi, lo)
- use names for BC header offsets and lengths in libregexp.c
- remove strict aliasing violations in `lre_exec_backtrack()`
- pass all context variables to XXX_CHAR macros in `lre_exec_backtrack()`
2024-02-20 00:22:32 +01:00
Charlie Gordon
8d932deb49 Rename regex flag and field utf16 -> unicode
- rename is_utf16 structure member to is_unicode
- rename flag LRE_FLAG_UTF16 as LRE_FLAG_UNICODE
2024-02-19 16:30:08 +01:00
Charlie Gordon
97ae6f39e6 Add benchmarks target
- assuming quickjs-benchmarks is cloned in the parent directory,
- compile quickjs-benchmarks targets and run the benchmarks
2024-02-19 01:13:07 +01:00
Charlie Gordon
c24a865a29 Improve run-test262
- add -t to show timings
- add -C to select compact progress meter
- default to compact progress meter if not attached to console
- set agent stack size to 2MB
- compute module filename relative to current path
- ignore `testdir` for -d and -f options
- return non zero status on errors changes
2024-02-18 15:00:04 +01:00
Charlie Gordon
bbf36d5b84 Fix big endian serialization
Big endian serialization was broken because:
- it partially relied on `WORDS_ENDIAN` (unconditionally undef'd in cutils.h)
- endianness was not handled at all in the bc reader.

Modifications:
- remove `WORDS_ENDIAN`
- use `bc_put_u32()` / `bc_put_u64()` in `JS_WriteBigInt()`
- use `bc_get_u32()` / `bc_get_u64()` in `JS_ReadBigInt()`
- handle host endianness in `bc_get_u16()`, `bc_get_u32()`, `bc_get_u64()` and
  `JS_ReadFunctionBytecode()`

- handle optional littleEndian argument as specified in
  `js_dataview_getValue()` and `js_dataview_setValue()`
2024-02-18 08:29:04 +01:00
Charlie Gordon
530ba6a631 handle missing test262 gracefully 2024-02-17 22:57:57 +01:00