Commit graph

213 commits

Author SHA1 Message Date
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
Charlie Gordon
5797f2a716
Improve DUMP_READ_OBJECT (#382)
- improve `JS_DumpString`: use `L` prefix for wide strings
- dump variable kind and flags for locals and closures
- disassemble byte code in DUMP_READ_OBJECT
- pass start_pos to `dump_byte_code` and `dump_single_byte_code`
- write constant pool before function bytecode (bump version to 11)
- update generated code
2024-04-16 09:24:21 +02:00
Cryse Hillmes
2c47b7beb1
Expose public equality comparison and sameness public API. (#373)
* Expose public equality comparison and sameness public API.
- add `JS_IsEqual` (operator `==`), returns an `int`: `-1` if an exception was thrown
- add `JS_IsStrictEqual` (operator `===`) always succeeds, returns a `JS_BOOL`
- add `JS_IsSameValue` always succeeds, returns a `JS_BOOL`
- add `JS_IsSameValueZero` always succeeds, returns a `JS_BOOL`
2024-04-16 08:46:22 +02:00
Saúl Ibarra Corretgé
18c632c754 Fix performance.now() to return a double 2024-04-15 16:16:04 +02:00
Charlie Gordon
7597fc7fb0
Fix potential atom leak in JS_ReadFunctionTag (#380) 2024-04-15 14:03:24 +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
4fb2e38b8a
Simplify arrow function parsing (#360)
- parse arrow functions only in `js_parse_cond_expr`
- remove `PF_ARROW_FUNC` flag and simplify parsing functions with flags
2024-04-14 02:44:34 +02:00
Charlie Gordon
16e7661fa0
Improve dump option support (#344)
- DUMP_XXX defined as nothing or 0 produces unconditional output
- DUMP_XXX defined as a bitmask produces conditional output based
    on command line option -d<bitmask>
- add `JS_SetDumpFlags()` to select active dump options
- accept -d[<hex mask>] and --dump[=<hex mask>] to specify active
    dump options, generalize command line option handling
- improve DUMP_READ_OBJECT output, fix indentation issue
2024-04-14 02:00:19 +02:00
Saúl Ibarra Corretgé
38fa7d7cf6 Fix crash in FinalizationRegistry when the observed object is GC'd
In the pathological case shown in
https://github.com/quickjs-ng/quickjs/issues/367 both the object and the
registry will be destroyed as part of the GC phase of JS_FreeRuntime.
When the GC sweep happens it's possible we are holding on to a corpse so
avoid calling the registry callback in that case.

This is similar to how Weak{Map,Set} deal with iterators being freed as
part of a cycle.

Fixes: https://github.com/quickjs-ng/quickjs/issues/367
2024-04-12 12:23:58 +02:00
Charlie Gordon
6d801de3e5
Improve js_array_lastIndexOf and friends (#359)
- special case fast arrays in `js_array_lastIndexOf`
- simplify `js_array_indexOf` and `js_array_includes` for consistency.
2024-04-08 23:08:49 +02:00
Charlie Gordon
0658d9c3e9
Fix js_math_imul (#356)
- follow ECMA specification
- remove implementation defined signed conversion
2024-04-08 22:50:39 +02:00
Charlie Gordon
97c918662b
Fix crashes in DUMP output (#350)
- avoid crashing on invalid atoms in `JS_AtomGetStrRT`
- do not dump objects and function_bytecode during
  `JS_GC_PHASE_REMOVE_CYCLES` phase
- fix crash in `print_lines` on null source
2024-04-08 21:25:01 +02:00
Charlie Gordon
56593f419b
Fix JS_ReadString for wide strings on big endian targets (#354)
swap words of wide character strings upon loading on a big endian target.
2024-04-08 17:02:20 +02:00
Charlie Gordon
d308a13579
Use string_get for clarity (#352) 2024-04-07 19:35:32 +02:00
Charlie Gordon
3f06c95558
Use more functions for explicit surrogate handling (#353)
- add `is_surrogate`, `get_hi_surrogate` and `get_lo_surrogate`
- use surrogate functions instead of hard coded computations
2024-04-07 18:19:55 +02:00
Charlie Gordon
1db884b140
Unify JS_DumpValue functions (#349)
- merge `JS_DumpValue(ctx, val)` and `JS_DumpValueShort(rt, val)` as `JS_DumpValue(rt, val)`
- remove unused `JS_PrintValue(ctx, val)`
2024-04-07 16:25:55 +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
d61988211c
Accept shell scripts in JS_DetectModule (#358)
- use `skip_shebang` in `JS_DetectModule` before scanning for
  `import` statements
2024-04-07 16:23:50 +02:00
Saúl Ibarra Corretgé
573a60bfc7 Fix compilation on MSVC 2022 in release mode
Fixes: https://github.com/quickjs-ng/quickjs/issues/309
2024-04-07 00:08:19 +02:00
Charlie Gordon
c15ef1f8dc
Add JS_TryGetProperty (#337)
* Optimize `JS_GetPropertyInt64` and `JS_TryGetPropertyInt64`

- add `js_get_fast_array_element()` to special case arrays and typed arrays
- use `js_get_fast_array_element()` in `JS_GetPropertyValue()`,
  `JS_TryGetPropertyInt64()` and `JS_GetPropertyInt64()`.
- simplify `js_array_at()`
2024-04-03 05:10:08 +02:00
Saúl Ibarra Corretgé
569b238ec4
Add cross-platform Atomics support
Fixes: https://github.com/quickjs-ng/quickjs/issues/1
2024-04-02 21:50:42 +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
Charlie Gordon
8b56215cc2
Fix more v8 errors (#336)
- change error message for `Object.create` invalid property descriptor
- disable v8 test cases for deprecated legacy RegExp static properties
  and invalid left hand side error type
- update v8.txt
- fix v8.sh behavior for single tests
2024-03-30 13:11:37 +01:00
Charlie Gordon
93d1742fc4
Small fixes in Date.parse (#333)
* Small fixes in Date.parse

- reject AM/PM suffix for hours > 12
- stricter time parser (fixes last v8 test)
- add explanatory comments
2024-03-27 12:48:08 +01:00
Ben Noordhuis
c7ca3febd3
Don't serialize IC opcodes (#334)
Translate IC opcodes to their non-IC variants before writing them out.
Before this commit they were not byte-swapped properly, breaking the
ability to load serialized bytecode containing ICs on systems with
different endianness. Inline caches are recomputed as needed now.

A pleasing side effect of this change is that serialized bytecode is,
on average, a little smaller because fewer atoms are duplicated now.
2024-03-27 12:07:11 +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
Saúl Ibarra Corretgé
c076339899 Expose JS_GetPropertyInt64 in the public API 2024-03-26 07:59:00 +01:00
Saúl Ibarra Corretgé
b8341ecafa Don't expose JS_{Get,Set}PropertyInternal in the public API 2024-03-26 07:59:00 +01:00
Charlie Gordon
3b50de4848
Improve consistency of JS_NewFloat64 API (#319)
* Improve consistency of JS_NewFloat64 API

- `JS_NewFloat64()` always creates a `JS_TAG_FLOAT64` value
- internal `js_float64()` always creates a `JS_TAG_FLOAT64` value
- add `js_int64` internal function for consistency
- rename `float_is_int32` as `double_is_int32`
- handle `INT32_MIN` in `double_is_int32`, use (somewhat) faster alternative
- add `js_number(d)` to create a `JS_TAG_FLOAT64` or a `JS_TAG_INT` value
  if possible
- add `JS_NewNumber()` API for the same purpose
- use non testing constructor for infinities in `js_atof2`
- always store internal time value as a float64
- merge `JS_NewBigInt64_1` into `JS_NewBigInt64`
- use comparisons instead of `(int32_t)` casts (implementation defined behavior)
2024-03-25 08:29:04 +01:00
Saúl Ibarra Corretgé
18f2898f52
Fix fully initializing JSStackFrame (#328)
Fixes: https://github.com/quickjs-ng/quickjs/issues/323
2024-03-24 22:06:57 +01:00
Saúl Ibarra Corretgé
1796b36db7 Remove JS_VALUE_GET_STRING from the public API
JSString is not part of the API.
2024-03-24 21:01:15 +01:00
Saúl Ibarra Corretgé
4a66289af4 Add JS_Newsymbol, an API for creating symbols
Example usage:

~~~
JSValue global = JS_GetGlobalObject(ctx);
JSValue sym = JS_NewSymbol(ctx, "my.secret.thing", TRUE);
JSAtom atom = JS_ValueToAtom(ctx, sym);
JS_DefinePropertyValue(ctx, global, atom, JS_NewString(ctx, "qjs!"), JS_PROP_C_W_E);
JS_FreeAtom(ctx, atom);
JS_FreeValue(ctx, sym);
JS_FreeValue(ctx, global);
~~~
2024-03-24 21:00:54 +01:00
Charlie Gordon
5e5b00c48c
Improve string parsing and JSON parsing (#316)
* Improve string parsing and JSON parsing

- fix JSON parsing of non ASCII string contents
- more precise string parsing errors
- more precise JSON parsing errors
- add `JS_ParseState::buf_start` to compute line/column
- fix HTML comment detection at start of source code
- improve v8 Failure messages (pulled and modified `formatFailureText` from **mjsunit.js**) 
- ignore more v8 tests
2024-03-22 11:19:36 +01:00
Enno Boland
8db7d24f98 fix compiler warning: -Wunused-variable 2024-03-18 12:34:45 +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
45f8dc247c
Improve JSON parser conformity (#303)
- add JSON specific parsers for strings and numbers
- update JSON parse error messages
- fix `JSON.stringify` handling of boxed objects
- parse Flags in v8 mjsunit test files
- update v8.txt
2024-03-14 08:19:11 +01:00
Saúl Ibarra Corretgé
473bd1d531 Fix Android build
dlmalloc has been removed and the NDK now exposes a malloc.h header with
malloc_usable_size exposed, so use that.

Also remove the duplication in js__malloc_usable_size.

Fixes: https://github.com/quickjs-ng/quickjs/issues/304
2024-03-12 10:26:10 +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
Saúl Ibarra Corretgé
f2a91e86c7 Remove custom __getClass method 2024-03-10 16:55:10 +01:00
Tyler Rockwood
33e38bec00 Enable direct dispatch for WASI
Signed-off-by: Tyler Rockwood <rockwood@redpanda.com>
2024-03-10 11:06:52 +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
Saúl Ibarra Corretgé
4d052a7e71 Log endianness when dumping memory stats 2024-03-06 11:21:50 +01:00
Aful
d11f5f600d
Implement getTimezoneOffset for Win32 (#291)
Retrieves the current time zone settings with GetTimeZoneInformation to calculate time zone offset
2024-03-03 16:23:48 +01:00
Charlie Gordon
708dbcbf5b
Fix big endian serialization (#269)
* 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.
- `bc_tag_str` was missing the `"RegExp"` string
- `lre_byte_swap()` was broken for `REOP_range` and `REOP_range32`

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()`
- fix `bc_tag_str` and `lre_byte_swap()`
2024-03-02 18:38:29 +01:00
Charlie Gordon
7dd2868856
Improve Number.prototype.toString for radix other than 10 (#284)
- 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

Fixes: https://github.com/quickjs-ng/quickjs/issues/242
2024-03-01 17:49:46 +01:00
Tyler Rockwood
ec4f957ca1
Add methods to detect arrays (#282)
I have a use case where a user can hand me many different kinds of
types, array buffer, uint8array, or a string, and I need to be able to
distingush between them.

Signed-off-by: Tyler Rockwood <rockwood@redpanda.com>
2024-02-28 12:17:18 +01:00
Tyler Rockwood
d168361207 Add documentation for promise APIs
Signed-off-by: Tyler Rockwood <rockwood@redpanda.com>
2024-02-23 19:49:52 +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
Ben Noordhuis
2d1473efbc
Revert "Fix sloppy mode arguments uninitialized value use" (#276)
This reverts commit f8b3a2e93c.

No longer necessary after commit 90d8c6bae0.
2024-02-23 11:55:51 +01:00
Charlie Gordon
ef4d8ab2ed
Force evaluation order in set_date_fields (#268) 2024-02-22 14:08:29 +01:00