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
- `-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
* 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`
- 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
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
* 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)
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>
* 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>
`a[42] = 1` where a is a detached typed array should not throw but
`Object.defineProperty()` still should. Add a check and a flag that
distinguishes between the two cases.
JSValueConst was only used for the now removed CONFIG_CHECK_JSVALUE
build mode. It is kept around as an alias for JSValue in quickjs.h to
avoid breaking everyone's source builds but remove it everywhere else.
Change JS_WriteObject() and JS_WriteObject2() to write little-endian
data and update JS_ReadObject() to byte-swap data when running on a
big-endian system.
Obsoletes the JS_WRITE_OBJ_BSWAP flag, it is now a no-op.
Fixes: https://github.com/quickjs-ng/quickjs/issues/125