Commit graph

312 commits

Author SHA1 Message Date
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
Saúl Ibarra Corretgé
3781c2a6db Add valgrind to CI
Fixes: https://github.com/quickjs-ng/quickjs/issues/71
2024-03-20 20:03:05 +01:00
Saúl Ibarra Corretgé
72cebeaf2a Remove unused variables in REPL 2024-03-20 11:50:06 +01:00
Saúl Ibarra Corretgé
dd2427785f Check for RegExp objects before going the standard object path in REPL 2024-03-20 11:50:06 +01:00
aabajyan
48cb3ac410 Do not link to pthread when targeting Android
I had issues compiling this for Android, and as it turns out, pthread functionality
is part of Bionic itself and linking is not required.
2024-03-20 07:30:39 +01:00
Enno Boland
8db7d24f98 fix compiler warning: -Wunused-variable 2024-03-18 12:34:45 +01:00
Charlie Gordon
5f8c636cef
Add os.getpid (#320) 2024-03-17 20:01:06 +01:00
Ben Noordhuis
99e4e0d55e
Disable ASLR, upgrade Ubuntu CI images (#321)
After much tinkering with libuv's CI, I finally figured out that ASLR
is the root cause for the ASan and MSan failures. Newer kernels use
bigger PIE slides and the sanitizer runtimes don't know how to handle
those (yet - looks like it's been fixed upstream.)

Refs: https://github.com/quickjs-ng/quickjs/pull/315
Refs: https://github.com/libuv/libuv/pull/4365
2024-03-17 19:59:24 +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
5aef8b67b1
fix potential memory leak (#318)
- fix memory leak in `js_std_file_printf`
- fix `errno` clobber in `js_os_stat`
2024-03-16 08:51:58 +01:00
Ben Noordhuis
5d2202cad0
Pin Ubuntu CI images to 20.04 (#315)
GitHub recently upgraded the ubuntu-latest images and I suspect that is
the cause of the linux-asan and linux-msan failures. Pin to the old LTS
for now.

Fixes: https://github.com/quickjs-ng/quickjs/issues/314
2024-03-15 10:49:33 +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
Ben Noordhuis
761ad7856f
Fix tcc build action (#311)
Clone the full repo, otherwise the known-good commit we want to test
against won't be available.
2024-03-14 00:06:48 +01:00
Saúl Ibarra Corretgé
7c7b72a74e Update README, add fork information 2024-03-12 20:00:41 +01:00
Saúl Ibarra Corretgé
50dcc707e0 Add TCC workflows to CI 2024-03-12 11:01:33 +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
Saúl Ibarra Corretgé
e859eae483 Add Android CI 2024-03-12 10:26:10 +01:00
Saúl Ibarra Corretgé
5b1d9e4194 Now working on 0.5.0 2024-03-11 11:23:43 +01:00
Saúl Ibarra Corretgé
d64967b73f Add wasi release job dependency 2024-03-11 11:23:11 +01:00
Saúl Ibarra Corretgé
99a7fbb276 Set version to 0.4.1 2024-03-11 11:16:31 +01:00
Saúl Ibarra Corretgé
d7a2025238 Fix not building qjsc during release process 2024-03-11 11:15:57 +01:00
Saúl Ibarra Corretgé
125373836d Now working on 0.5.0 2024-03-11 11:01:45 +01:00
Saúl Ibarra Corretgé
434fecda17 Set version to 0.4.0 2024-03-11 11:01:00 +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
Charlie Gordon
8d0d9391f9
Unbreak repl string output (#300)
- fix incorrect argument in s = `JSON.stringify(s);`
- add closures for `RegExp` and `JSON`
2024-03-10 13:32:33 +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é
c61336c4fc Update checkout actions
Fixes: https://github.com/quickjs-ng/quickjs/issues/292
2024-03-07 11:15:15 +01:00
Saúl Ibarra Corretgé
d49a14ba3a Release WASM / WASI build artifacts too 2024-03-07 10:24:10 +01:00
Saúl Ibarra Corretgé
4d052a7e71 Log endianness when dumping memory stats 2024-03-06 11:21:50 +01:00
Saúl Ibarra Corretgé
215f246974 Add Big Endian CI target 2024-03-06 11:21:50 +01:00
henrydf
4d6c98115b
Fix Emscripten build
Co-authored-by: Henry <henrydf2018@gmail.com>
2024-03-06 08:56:45 +01:00
Charlie Gordon
5abbeacc62
Fix bug in GET_PREV_CHAR macro (#278)
* Fix bug in `GET_PREV_CHAR` macro

- pass `cbuf_type` variable to `XXX_CHAR` macros in `lre_exec_backtrack()`
- improve readability of these macros
- fix `GET_PREV_CHAR` macro: `cptr` was decremented twice on invalid high surrogate.
- minimize non functional changes
2024-03-03 17:12:52 +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
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
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
377e6a6c06 Fix JS_INVALID_PROMISE_STATE macro 2024-02-26 18:37:30 +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
79d417a90d Simplify and clarify URL quoting js_std_urlGet 2024-02-23 11:55:29 +01:00
Felix S
ed49e0f39e Fix shell injection bug in std.urlGet
Refs: https://github.com/bellard/quickjs/pull/61
2024-02-23 11:55:29 +01:00
Charlie Gordon
ef4d8ab2ed
Force evaluation order in set_date_fields (#268) 2024-02-22 14:08:29 +01:00
Tyler Rockwood
33f72491a9
Add method to GetClassID (#275)
* Add method to 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.

Signed-off-by: Tyler Rockwood <rockwood@redpanda.com>

* introduce constant for invalid class ID

Signed-off-by: Tyler Rockwood <rockwood@redpanda.com>

---------

Signed-off-by: Tyler Rockwood <rockwood@redpanda.com>
2024-02-20 09:29:08 +01:00