Commit graph

104 commits

Author SHA1 Message Date
Richard Davison
7f156b6ef9
Add typed array utility functions 2024-12-22 16:35:10 +01:00
Saúl Ibarra Corretgé
be2db73000 Use 1 MB as the default stack size
In addition:

- Move the WASI override to quickjs.c
- Allow it to be user defined

Ref: https://github.com/quickjs-ng/quickjs/issues/749#issuecomment-2540167690
2024-12-17 10:03:17 +01:00
Cryse Hillmes
4b9d0ebdba Expose JS_IsUncatchableError API.
Very useful when handling errors.
2024-12-10 07:09:07 +01:00
Saúl Ibarra Corretgé
721766faa1 Fix exporting JS_GetModuleNamespace 2024-12-03 17:11:34 +01:00
Ben Noordhuis
f93dd58ea0 Work around msvc definition of NAN
NAN is reportedly no longer a compile-time expression in some versions
of MSVC. Work around that by minting a NaN from a uint64.

Fixes: https://github.com/quickjs-ng/quickjs/issues/622
Fixes: https://github.com/quickjs-ng/quickjs/issues/693
2024-11-18 10:49:30 +01:00
Saúl Ibarra Corretgé
428204b802 Align JS_SetOpaque with other similar APIs
Returns < 0 on failure. Also document it in the header file.

Fixes: https://github.com/quickjs-ng/quickjs/issues/695
2024-11-16 10:35:01 +01:00
Saúl Ibarra Corretgé
859267cc59 Set version to 0.7.0 2024-11-15 21:29:58 +01:00
Ben Noordhuis
f641d4ff18 Don't use rt->user_opaque in quickjs-libc.c
JS_SetRuntimeOpaque() and JS_GetRuntimeOpaque() are intended for
embedders. Stop using them in quickjs-libc.c
2024-11-09 23:14:20 +01:00
Saúl Ibarra Corretgé
c8be383367 Prevent JS_SetOpaque from overriding internal class state
Fixes: https://github.com/quickjs-ng/quickjs/issues/657
2024-11-07 21:26:28 +01:00
Ben Noordhuis
d2bca87c64
Make quickjs.h -Wall -Wextra -pedantic clean (#628)
Fixes: https://github.com/quickjs-ng/quickjs/issues/585
2024-10-26 17:10:18 +02:00
Ben Noordhuis
89883ae657
Add C++ compile test (#615)
Check that quickjs.h parses without error when fed to a C++ compiler.

Fixes: https://github.com/quickjs-ng/quickjs/issues/608
Co-authored-by: Saúl Ibarra Corretgé <s@saghul.net>
2024-10-26 14:01:45 +02:00
Ben Noordhuis
8cd59bf7c4
Improve JS_DetectModule (#610)
It's still not infallible (I don't think it can ever be, the whole
premise is wrong) but hopefully it's a little less fallible now.

Fixes: https://github.com/quickjs-ng/quickjs/issues/606
2024-10-20 12:42:21 +02:00
Richard Davison
afeeebf89e
Expose ctx->function_proto 2024-10-16 20:39:09 +02:00
Ben Noordhuis
9a37c57779
Fix thread-safety issue in quickjs-libc (#578)
`JS_NewClassID(rt, &class_id)` where `class_id` is a global variable
is unsafe when called from multiple threads but that is exactly what
quickjs-libc.c did.

Add a new JS_AddRuntimeFinalizer function that lets quickjs-libc
store the class ids in JSRuntimeState and defer freeing the memory
until the runtime is destroyed. Necessary because object finalizers
such as js_std_file_finalizer need to know the class id and run after
js_std_free_handlers runs.

Fixes: https://github.com/quickjs-ng/quickjs/issues/577
2024-10-07 21:27:38 +02:00
Richard Davison
5590756b93
Move JS_{Dup,Free}Value and the RT variants from header, reduced duplication 2024-10-04 09:18:12 +02:00
Saúl Ibarra Corretgé
2b953a72be Set version to 0.6.1 2024-09-24 19:45:59 +02:00
Saúl Ibarra Corretgé
1defa63c73
Add version to navigator.userAgent (#542)
A la Deno and Bun.
2024-09-24 18:28:14 +02:00
Saúl Ibarra Corretgé
d3c340373e Now working on 0.7.0 2024-09-21 21:34:30 +02:00
Saúl Ibarra Corretgé
a815d1b7b6 Set version to 0.6.0 2024-09-20 21:26:07 +02:00
Andrew Johnson
fe5be3cad9 Add JS_SetLength API function 2024-09-20 09:49:51 +02:00
Saúl Ibarra Corretgé
cfeeff91db Refactor JSMallocFunctions to simplify the implementation
Rather than having the user take care of JSMallocState, take care of the
bookkeeping internally (and make JSMallocState non-public since it's no
longer necessary) and keep the allocation functions to the bare minimum.

This has the advantage that using a different allocator is just a few
lines of code, and there is no need to copy the default implementation
just to moficy the call to the allocation function.

Fixes: https://github.com/quickjs-ng/quickjs/issues/285
2024-09-19 20:49:09 +02:00
Saúl Ibarra Corretgé
56da486312 Add JS_HasException
Ref: db9dbd0a2b
Ref: 5417ab0159
2024-09-14 21:58:58 +02:00
Saúl Ibarra Corretgé
5a41aaa6a3 Use calloc rather than malloc + memset 2024-09-11 22:09:27 +02:00
Saúl Ibarra Corretgé
5db156fb08 Use INT32_MAX instead of inline value 2024-08-13 12:56:11 +02:00
Saúl Ibarra Corretgé
763010663b Add auxiliary structure for retrieving SAB tabs 2024-07-15 16:53:52 +02:00
Saúl Ibarra Corretgé
3ed591c02d Introduce JS_ReadObject2
Analogously to JS_WriteObject2, it allows the user to get a tab with all
the SAB objects that were read.

This can help adjust reference counts in a scenario where a SAB that was
written increased it and it's necessary to decrease it upon reading it.
2024-07-15 16:53:52 +02:00
Saúl Ibarra Corretgé
b09ad82622 Now working on 0.6.0 2024-06-07 22:26:48 +02:00
Saúl Ibarra Corretgé
0827b37f8c Set version to 0.5.0 2024-06-07 22:11:28 +02:00
KaruroChori
ed8f73413c Add getter for GC threshold 2024-06-07 22:07:38 +02:00
Tom Lienard
d3da56b630 Sync TLA implementation with upstream
Fixes: https://github.com/quickjs-ng/quickjs/issues/339
2024-06-07 15:46:44 +02:00
KaruroChori
6efe30b4b4
Improve macro compatibility with C++
Fixes: https://github.com/quickjs-ng/quickjs/issues/425
2024-06-07 08:29:12 +02:00
nekosu
22c10224ac fix: missing math.h for NAN 2024-06-06 10:26:02 +02:00
nekosu
8ac7c0d51f fix: nested member access 2024-06-05 14:57:09 +02:00
Saúl Ibarra Corretgé
e5673a8e68 Add JS_ToBigUint64
Fixes: https://github.com/quickjs-ng/quickjs/issues/376
2024-06-04 19:03:26 +02:00
Frère Jérôme
c7bd41197a Explicit cast in JS_NewInt64 & JS_NewUint32
This avoids the two GCC -Wconversion warnings in this public header, which is useful when using extensive error reporting from the compiler, and treating warnings as errors.
2024-06-04 00:54:56 +02:00
Saúl Ibarra Corretgé
bb4878dd50 Add JS_ThrowPlainError
It's a helper for doing the following steps:

- Building an Error object
- Attaching a formatted message
- Throwing the object

Fixes: https://github.com/quickjs-ng/quickjs/issues/375
2024-05-27 10:11:49 +02:00
Icemic
569f51fba2 Add JS_GetLength 2024-05-27 08:41:40 +02:00
Icemic
9a2a246b51 Add JS_FreePropertyEnum corresponding to JS_GetOwnPropertyNames 2024-05-27 08:41:40 +02:00
Charlie Gordon
b81d4deee4
Improve internal string allocation methods (#398)
String values are allocated as temporary or final results. This commit
attempts to improve the consistency and performance of this step.

- define `JS_NewString` as an inline function to allow simple expansion
  of `strlen()` for string literals
- document string contents constraints regarding UTF-8 encoding.
- rename `js_new_string8` as `js_new_string8_len`. takes `const char *`.
- new inline function `js_new_string8` takes `const char *`, computes
  string length with `strlen` and calls `js_new_string8_len`. No overhead
  for string literals
- rename `js_new_string16` to `js_new_string16_len`
- use internal string allocation functions where appropriate, remove overhead
- allocate extra byte for null terminator in source code string
2024-05-10 12:43:35 +02:00
Saúl Ibarra Corretgé
e5ae6cf106 Fix handling of memory limit
Default to 0, which is "disabled", just like the stack limit.
2024-05-06 11:22:16 +02:00
Charlie Gordon
f326a7a195
Add strip option in qjsc to reduce object size (#388)
- `-s` strips the source code
- `-ss` strips source and line/column numbers information
- `qjsc repl.js` generates an object size of **105726** bytes
- `qjsc -s repl.js` generates an object size of **20853** bytes
- `qjsc -ss repl.js` generates an object size of only **16147** bytes
- compile repl.js with `-ss`
- bump byte code version to 12
2024-04-19 08:41:12 +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
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
Ben Noordhuis
325ce95c5e
Remove js_unlikely macro (#370)
It was a wrapper around gcc's __builtin_expect macro but it was only
used in three places and not in a way that suggests it really helps
branch prediction on modern (or even not so modern) CPUs.

Refs: https://github.com/quickjs-ng/quickjs/issues/369
2024-04-12 12:21:20 +02: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é
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
Saúl Ibarra Corretgé
5b1d9e4194 Now working on 0.5.0 2024-03-11 11:23:43 +01:00