Commit Graph

95 Commits

Author SHA1 Message Date
Zia
adcfe4cadb class id argument type fix 2024-03-14 01:20:53 +03:30
Zia
a4eff5077e duplicated gettimeofday 2024-03-14 01:20:11 +03:30
Zia
f058e2a5f3 new string allocator 2024-03-14 01:19:41 +03:30
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
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
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
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
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
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
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
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
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
37bd4ae62d Strip trailing spaces 2024-02-10 16:19:17 +01:00
Fabrice Bellard
6f480abbc8 avoid using INT64_MAX in double comparisons because it cannot be exactly represented as a double (bnoordhuis) 2024-02-03 15:48:57 +01:00
Fabrice Bellard
00967aac24 fixed Promise return in the REPL by using a wrapper object in async std.evalScript() (github issue #231) 2024-02-03 15:47:42 +01:00
Fabrice Bellard
c6cc6a9a5e export JS_GetModuleNamespace (github issue #34) 2024-01-27 13:27:32 +01:00
Fabrice Bellard
cd666a851f simplified and fixed arrow function parsing (github issue #226) 2024-01-27 13:12:54 +01:00
Fabrice Bellard
efdb722f02 fixed JS_GetScriptOrModuleName() in direct or indirect eval code 2024-01-13 11:15:06 +01:00
Fabrice Bellard
9a4379daf6 native cosmopolitan build 2024-01-11 15:29:19 +01:00
Fabrice Bellard
e66ce48872 more portable and Windows version for getTimezoneOffset() (github issue #122) 2024-01-11 15:26:39 +01:00
Fabrice Bellard
f25e5d4094 optional chaining fixes (github issue #103) 2024-01-09 19:15:40 +01:00
Fabrice Bellard
e1e65aca91 fixed Date.toLocaleString() (kuzmas) 2024-01-08 19:02:30 +01:00
Fabrice Bellard
c06c399f4f fixed next token parsing after a function definition (github issue #77) 2024-01-08 18:40:35 +01:00
Fabrice Bellard
5935a26eae fixed class name init in static initializers 2024-01-08 18:39:58 +01:00
Fabrice Bellard
c3635861f6 avoid potentially undefined behavior and make valgrind happy (bnoordhuis) (github issue #153) 2024-01-08 18:39:26 +01:00
Fabrice Bellard
df3781d082 make for in faster and spec compliant (github issue #137) 2024-01-06 14:43:29 +01:00
Fabrice Bellard
24aa7ba4f0 fixed test262: derived-this-uninitialized-realm.js 2024-01-06 14:42:43 +01:00
Fabrice Bellard
bd0b7048de added a comment for non-initialized warning in Valgrind (github issue #153) 2024-01-06 11:20:20 +01:00
Fabrice Bellard
3ab1c2b314 added 'in' operator for private fields 2024-01-02 16:11:20 +01:00
Fabrice Bellard
16057644f3 class static block (initial patch by bnoordhuis) 2024-01-02 16:10:43 +01:00
Fabrice Bellard
8f897d64d4 fixed crash in JS_DumpMemoryUsage (github issue #65) 2024-01-02 16:09:55 +01:00
Fabrice Bellard
e44b793e38 allow 'await' in the REPL and added os.sleepAsync() 2024-01-02 16:09:30 +01:00
Fabrice Bellard
8de4538ff3 make JS_NewClassID thread safe 2024-01-02 16:08:48 +01:00
Fabrice Bellard
5c120cd471 added Error cause 2024-01-02 16:08:08 +01:00
Fabrice Bellard
2ee6be705f added os.now() 2023-12-27 19:09:29 +01:00
Fabrice Bellard
2785ede778 fixed JS module autodetection with shebang (github issue #91) 2023-12-27 18:19:46 +01:00
Fabrice Bellard
b4d80502b6 fixed crash when resizing property shapes in case of OOM (github issue #129) 2023-12-27 18:19:06 +01:00
Fabrice Bellard
7414e5f67f fixed the garbage collection of async functions with closures (github issue #156) 2023-12-27 17:21:46 +01:00