Skip to content

Commit 53c3c13

Browse files
committed
Update QuickJS
* Read byteOffset for detached buffers bellard/quickjs@00b1d8d * Add `Error.isError()` bellard/quickjs@098f221 Some tests were updated (more tests pass now) and the upstream changelog was updated, but already have most of those changes anyway. Also, update our maintenance scripts -- add a script used to adjust the patches themselves. Normally we just have to run `./update_and_apply_patches.sh` that clones QuickJS and applies our patch. But after some time the line numbers in our patch may start to drift vs the upstream `quickjs.c` file, so it helps to regerate the patch itself periodically. Assuming the local working directory is patched, call the `./update_patches.sh` script and it will clone a fresh QuickJS master and run a diff from that master to our working directory and make that a new patch.
1 parent 4adf245 commit 53c3c13

File tree

7 files changed

+61
-15
lines changed

7 files changed

+61
-15
lines changed

src/couch_quickjs/patches/01-spidermonkey-185-mode.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
--- quickjs-master/quickjs.c 2025-05-24 09:43:14
2-
+++ quickjs/quickjs.c 2025-05-28 21:55:36
3-
@@ -30590,10 +30590,24 @@
1+
--- quickjs-master/quickjs.c 2025-06-14 05:51:48
2+
+++ quickjs/quickjs.c 2025-06-20 13:56:52
3+
@@ -30599,10 +30599,24 @@
44
if (s->token.val == TOK_FUNCTION ||
55
(token_is_pseudo_keyword(s, JS_ATOM_async) &&
66
peek_token(s, TRUE) == TOK_FUNCTION)) {

src/couch_quickjs/quickjs/Changelog

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
- added JSON modules and import attributes
2+
- added JS_PrintValue() API
3+
- qjs: pretty print objects in print() and console.log()
4+
- qjs: better promise rejection tracker heuristics
5+
- added RegExp v flag
6+
- added RegExp modifiers
7+
- added RegExp.escape
8+
- added Float16Array
9+
- added Promise.try
10+
- improved JSON parser spec conformance
11+
- qjs: improved compatibility of std.parseExtJSON() with JSON5 and
12+
accept JSON5 modules
13+
- added JS_FreePropertyEnum() and JS_AtomToCStringLen() API
14+
- added Error.isError()
15+
116
2025-04-26:
217

318
- removed the bignum extensions and qjscalc

src/couch_quickjs/quickjs/quickjs.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39990,6 +39990,16 @@ static const JSCFunctionListEntry js_error_proto_funcs[] = {
3999039990
JS_PROP_STRING_DEF("message", "", JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE ),
3999139991
};
3999239992

39993+
static JSValue js_error_isError(JSContext *ctx, JSValueConst this_val,
39994+
int argc, JSValueConst *argv)
39995+
{
39996+
return JS_NewBool(ctx, JS_IsError(ctx, argv[0]));
39997+
}
39998+
39999+
static const JSCFunctionListEntry js_error_funcs[] = {
40000+
JS_CFUNC_DEF("isError", 1, js_error_isError),
40001+
};
40002+
3999340003
/* AggregateError */
3999440004

3999540005
/* used by C code. */
@@ -52291,6 +52301,7 @@ void JS_AddIntrinsicBaseObjects(JSContext *ctx)
5229152301
"Error", 1, JS_CFUNC_constructor_or_func_magic, -1);
5229252302
JS_NewGlobalCConstructor2(ctx, obj1,
5229352303
"Error", ctx->class_proto[JS_CLASS_ERROR]);
52304+
JS_SetPropertyFunctionList(ctx, obj1, js_error_funcs, countof(js_error_funcs));
5229452305

5229552306
/* Used to squelch a -Wcast-function-type warning. */
5229652307
JSCFunctionType ft = { .generic_magic = js_error_constructor };
@@ -54031,7 +54042,8 @@ static JSValue js_typed_array_subarray(JSContext *ctx, JSValueConst this_val,
5403154042
int argc, JSValueConst *argv)
5403254043
{
5403354044
JSValueConst args[4];
54034-
JSValue arr, byteOffset, ta_buffer;
54045+
JSValue arr, ta_buffer;
54046+
JSTypedArray *ta;
5403554047
JSObject *p;
5403654048
int len, start, final, count, shift, offset;
5403754049

@@ -54048,12 +54060,10 @@ static JSValue js_typed_array_subarray(JSContext *ctx, JSValueConst this_val,
5404854060
goto exception;
5404954061
}
5405054062
count = max_int(final - start, 0);
54051-
byteOffset = js_typed_array_get_byteOffset(ctx, this_val, 0);
54052-
if (JS_IsException(byteOffset))
54053-
goto exception;
5405454063
shift = typed_array_size_log2(p->class_id);
54055-
offset = JS_VALUE_GET_INT(byteOffset) + (start << shift);
54056-
JS_FreeValue(ctx, byteOffset);
54064+
ta = p->u.typed_array;
54065+
/* Read byteOffset (ta->offset) even if detached */
54066+
offset = ta->offset + (start << shift);
5405754067
ta_buffer = js_typed_array_get_buffer(ctx, this_val, 0);
5405854068
if (JS_IsException(ta_buffer))
5405954069
goto exception;

src/couch_quickjs/quickjs/test262.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ destructuring-assignment
103103
destructuring-binding
104104
dynamic-import
105105
error-cause
106-
Error.isError=skip
106+
Error.isError
107107
explicit-resource-management=skip
108108
exponentiation
109109
export-star-as-namespace-from-module

src/couch_quickjs/quickjs/test262_errors.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ test262/test/staging/sm/TypedArray/prototype-constructor-identity.js:17: Test262
2323
test262/test/staging/sm/TypedArray/set-detached-bigint.js:27: Error: Assertion failed: expected exception SyntaxError, got RangeError: invalid array length
2424
test262/test/staging/sm/TypedArray/set-detached.js:112: RangeError: invalid array length
2525
test262/test/staging/sm/TypedArray/sort_modifications.js:12: Test262Error: Int8Array at index 0 for size 4 Expected SameValue(«0», «1») to be true
26-
test262/test/staging/sm/TypedArray/subarray.js:15: Test262Error: Expected SameValue(«0», «1») to be true
2726
test262/test/staging/sm/async-functions/async-contains-unicode-escape.js:45: Error: Assertion failed: expected exception SyntaxError, no exception thrown
2827
test262/test/staging/sm/async-functions/await-error.js:12: Test262Error: Expected SameValue(«false», «true») to be true
2928
test262/test/staging/sm/async-functions/await-in-arrow-parameters.js:33: Error: Assertion failed: expected exception SyntaxError, no exception thrown - AsyncFunction:(a = (b = await/r/g) => {}) => {}

src/couch_quickjs/update_and_apply_patches.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ set -e
77
# This is the main branch of the github mirror
88
URL=https://github.com/bellard/quickjs/archive/refs/heads/master.zip
99
#
10-
# The other alternatives:
11-
# https://github.com/quickjs-ng/quickjs/commits/master/
12-
1310

1411
echo
1512
echo " * backup quickjs to quickjs.bak"
@@ -50,6 +47,9 @@ echo " * removing quickjs.bak"
5047
rm -rf quickjs.bak
5148
echo
5249

53-
# Example how to generate patches:
50+
# Example how to update patches themselves:
5451
#
52+
# Run
53+
# ./update_patches.sh
54+
# OR manually run after cloning and unzipping master.zip from quickjs:
5555
# diff -u quickjs-master/quickjs.c quickjs/quickjs.c > patches/01-spidermonkey-185-mode.patch
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Update patches
2+
#
3+
# Call this script after using update_and_apply_patches.sh to adjust
4+
# the patches themselves. Sometimes line offsets drift and so this takes
5+
# a new diff from the master QuickJS vs current source tree and regenerates
6+
# the patch.
7+
8+
set -e
9+
10+
URL=https://github.com/bellard/quickjs/archive/refs/heads/master.zip
11+
12+
echo " * wget ${URL}"
13+
rm -rf master.zip quickjs-master
14+
wget -q ${URL}
15+
echo " * unzip master.zip to quickjs-master"
16+
unzip -q -o master.zip
17+
echo " * updating 01-spidermonkey-185-mode.patch"
18+
set +e
19+
diff -u quickjs-master/quickjs.c quickjs/quickjs.c > patches/01-spidermonkey-185-mode.patch
20+
set -e
21+
echo " * cleaning up"
22+
rm -rf master.zip quickjs-master

0 commit comments

Comments
 (0)