Commit Graph

152 Commits

Author SHA1 Message Date
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
Charlie Gordon
0a361b7c0f handle missing test262 gracefully 2024-02-17 22:56:54 +01:00
Charlie Gordon
74bdb4967c Improve tests
- split test_bigfloat.js from test_bignum.js
- make test_date() compatible with node
- document Date constructor string argument format:
  should add test cases for invalid strings
- test_argument_scope(): only test this syntax error in strict mode:
  `var f = function(a = eval("var arguments")) {};`
2024-02-17 21:54:19 +01:00
Charlie Gordon
85fb2caeae Fix UB signed integer overflow in js_math_imul
- Use uint32_t arithmetics and Standard conformant conversion to
  avoid UB in js_math_imul.
- add builtin tests
- use specific object directories for SAN targets
2024-02-17 21:15:29 +01:00
Ben Noordhuis
8df4327559 Fix UB left shift of negative number 2024-02-17 17:36:50 +01:00
Ben Noordhuis
3bb2ca360e Remove unnecessary ssize_t posix-ism
ssize_t is not always available and the cast it was used in wasn't
necessary in the first place, the value already has the right type.

Note that the field malloc_limit is an int64_t in JSMemoryUsage whereas it
is a size_t in JSMallocState.
2024-02-16 10:25:29 +01:00
Charlie Gordon
c06af876f6 Improve string concatenation hack
- add more cases of in place string concatenation
  this temporary hack improves the microbench timing by 30% but
  has little impact on the test262 timings.
2024-02-15 10:30:04 +01:00
Charlie Gordon
8e21b96738 pass node-js command line arguments to microbench 2024-02-15 09:59:50 +01:00
Charlie Gordon
95e0aa0526 Reverse e140122202
- remove temporary fix for MemorySanitizer:
  setting p->u.array.count to 0 silenced a warning in JS_GetPropertyValue on a
  hacky test agains the length of fast_array object.
  This hack was removed by commit c3635861f6.
2024-02-13 09:45:58 +01:00
Charlie Gordon
1fe04149e9 Fix test262 error
- force evaluation order in `set_date_fields`
- fix evaluation error in test262/test/built-ins/Date/UTC/fp-evaluation-order.js:19:
  unexpected error: Test262Error: precision in MakeDate Expected SameValue(«34448384», «34447360») to be true
2024-02-12 18:37:37 +01:00
Charlie Gordon
ef4e7b23f4 Fix compiler warnings 2024-02-12 18:35:27 +01:00
Charlie Gordon
92e339d14f Simplify and clarify URL quoting js_std_urlGet 2024-02-12 18:34:52 +01:00
Nick Vatamaniuc
636c946531
FreeBSD QuickJS Patch (#203) 2024-02-12 11:28:00 +01:00
Felix S
ae6fa8d3d2
Fix shell injection bug in std.urlGet (#61) 2024-02-12 11:20:25 +01:00
Sam
693449e34e
add gitignore for build objects (#84)
Signed-off-by: Samuel Hellawell <sshellawell@gmail.com>
Co-authored-by: Charlie Gordon <github@chqrlie.org>
2024-02-12 10:28:38 +01:00
Ben Noordhuis
e140122202 Fix sloppy mode arguments uninitialized value use
MemorySanitizer complained about uninitialized reads in
the indexed property code path in JS_GetPropertyValue()
with JS_CLASS_MAPPED_ARGUMENTS objects.
2024-02-11 23:54:19 +01:00
Ben Noordhuis
6dbf01bb1f Remove unsafe sprintf() and strcat() calls
Prep work for enabling the sanitizers on macos CI since they are marked
as deprecated and cause the build to fail when -Werror is enabled.
2024-02-11 21:58:14 +01:00
Charlie Gordon
6535064577 Fix undefined behavior (UBSAN) 2024-02-11 21:32:36 +01:00
Saúl Ibarra Corretgé
e53d622359 Fix UB in js_dtoa1 2024-02-11 20:59:17 +01:00
Ben Noordhuis
fd6e039770 Add UndefinedBehaviorSanitizer support 2024-02-11 20:37:24 +01:00
Ben Noordhuis
325ca194b7 Add MemorySanitizer support 2024-02-11 20:27:34 +01:00
Ben Noordhuis
626e0d4e60 Unbroke tests/test_test_bjson.js 2024-02-11 18:38:47 +01:00
Ben Noordhuis
2e1013429a Add more tests
- add regexp tests in tests/microbench.js
- add bjson_test_regexp in tests/test_test_bjson.js
2024-02-11 16:20:39 +01:00
Charlie Gordon
48deab1aeb Fix runtime bugs
- fix string leak in `js_printf_internal` on errors
- read `errno` before potential side effects in `js_os_stat`
2024-02-11 12:49:40 +01:00
Charlie Gordon
c9e6c56c70 Improve microbench
- remove import statements (invoke with qjs --std)
- fix compatibility issues with node
- add more loop styles
- add more string concatenation tests
- use === and !=== where appropriate
- fix sort timing log
- add `-r ref_file` command line option to specify reference file
- add .gitignore file with target file patterns
2024-02-11 12:11:53 +01:00
Charlie Gordon
2c793e5097 Fix test262o error
- excude test262o/test/suite/ch15/15.5/15.5.4/15.5.4.9/15.5.4.9_CE.js:
  Test262 Error: String.prototype.localeCompare considers ö (\u006f\u0308) = ö (\u00f6).
2024-02-10 20:54:29 +01:00