This is an automated email from the ASF dual-hosted git repository. vatamane pushed a commit to branch new-quicks-release in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 111edd90f19b36f4e19243e9e10f830aa2403d96 Author: Nick Vatamaniuc <[email protected]> AuthorDate: Sat Apr 26 19:34:42 2025 -0400 New quickjs release 2025-04-26 We have most of the stuff from it already. Except these two: New commits: * More precise source location reporting [1] * Extra C callbacks for "exotic" objects (we don't use proxies) [2] [1] https://github.com/bellard/quickjs/commit/7645ce5f632b34b228f39bb9868801d484d76791 [2] https://github.com/bellard/quickjs/commit/1b13fa6450ac040e4b171291280f87f169c1c6ad --- .../patches/01-spidermonkey-185-mode.patch | 6 +- src/couch_quickjs/quickjs/Changelog | 8 + src/couch_quickjs/quickjs/Makefile | 7 +- src/couch_quickjs/quickjs/VERSION | 2 +- src/couch_quickjs/quickjs/quickjs.c | 183 ++++++++++++++++----- src/couch_quickjs/quickjs/quickjs.h | 11 ++ src/couch_quickjs/update_and_apply_patches.sh | 2 + 7 files changed, 168 insertions(+), 51 deletions(-) diff --git a/src/couch_quickjs/patches/01-spidermonkey-185-mode.patch b/src/couch_quickjs/patches/01-spidermonkey-185-mode.patch index 34a6c137b..4dc302853 100644 --- a/src/couch_quickjs/patches/01-spidermonkey-185-mode.patch +++ b/src/couch_quickjs/patches/01-spidermonkey-185-mode.patch @@ -1,6 +1,6 @@ ---- quickjs-master/quickjs.c 2025-04-22 13:18:16 -+++ quickjs/quickjs.c 2025-04-22 14:32:08 -@@ -29541,10 +29541,24 @@ +--- quickjs-master/quickjs.c 2025-04-26 06:30:26 ++++ quickjs/quickjs.c 2025-04-26 19:32:38 +@@ -29636,10 +29636,24 @@ if (s->token.val == TOK_FUNCTION || (token_is_pseudo_keyword(s, JS_ATOM_async) && peek_token(s, TRUE) == TOK_FUNCTION)) { diff --git a/src/couch_quickjs/quickjs/Changelog b/src/couch_quickjs/quickjs/Changelog index 77805c084..7cc33993d 100644 --- a/src/couch_quickjs/quickjs/Changelog +++ b/src/couch_quickjs/quickjs/Changelog @@ -1,9 +1,17 @@ +2025-04-26: + - removed the bignum extensions and qjscalc - new BigInt implementation optimized for small numbers - added WeakRef, FinalizationRegistry and symbols as weakrefs - added builtin float64 printing and parsing functions for more correctness - faster repeated string concatenation - qjs: promise unhandled rejections are fatal errors by default +- added column number in debug information +- removed the "use strip" extension +- qjs: added -s and --strip-source options +- qjsc: added -s and --keep-source options +- added JS_GetAnyOpaque() +- added more callbacks for exotic objects in JSClassExoticMethods - misc bug fixes 2024-01-13: diff --git a/src/couch_quickjs/quickjs/Makefile b/src/couch_quickjs/quickjs/Makefile index d9aaad173..3b1c74594 100644 --- a/src/couch_quickjs/quickjs/Makefile +++ b/src/couch_quickjs/quickjs/Makefile @@ -423,10 +423,13 @@ build_doc: $(DOCS) clean_doc: rm -f $(DOCS) -doc/%.pdf: doc/%.texi +doc/version.texi: VERSION + @echo "@set VERSION `cat $<`" > $@ + +doc/%.pdf: doc/%.texi doc/version.texi texi2pdf --clean -o $@ -q $< -doc/%.html.pre: doc/%.texi +doc/%.html.pre: doc/%.texi doc/version.texi makeinfo --html --no-headers --no-split --number-sections -o $@ $< doc/%.html: doc/%.html.pre diff --git a/src/couch_quickjs/quickjs/VERSION b/src/couch_quickjs/quickjs/VERSION index e32e065c9..c76e76d1f 100644 --- a/src/couch_quickjs/quickjs/VERSION +++ b/src/couch_quickjs/quickjs/VERSION @@ -1 +1 @@ -2024-02-14 +2025-04-26 diff --git a/src/couch_quickjs/quickjs/quickjs.c b/src/couch_quickjs/quickjs/quickjs.c index 470161a62..a78615782 100644 --- a/src/couch_quickjs/quickjs/quickjs.c +++ b/src/couch_quickjs/quickjs/quickjs.c @@ -1149,13 +1149,8 @@ static JSProperty *add_property(JSContext *ctx, static int JS_ToBigInt64Free(JSContext *ctx, int64_t *pres, JSValue val); JSValue JS_ThrowOutOfMemory(JSContext *ctx); static JSValue JS_ThrowTypeErrorRevokedProxy(JSContext *ctx); -static JSValue js_proxy_getPrototypeOf(JSContext *ctx, JSValueConst obj); -static int js_proxy_setPrototypeOf(JSContext *ctx, JSValueConst obj, - JSValueConst proto_val, BOOL throw_flag); static int js_resolve_proxy(JSContext *ctx, JSValueConst *pval, int throw_exception); -static int js_proxy_isExtensible(JSContext *ctx, JSValueConst obj); -static int js_proxy_preventExtensions(JSContext *ctx, JSValueConst obj); static int JS_CreateProperty(JSContext *ctx, JSObject *p, JSAtom prop, JSValueConst val, JSValueConst getter, JSValueConst setter, @@ -7194,7 +7189,8 @@ static inline __exception int js_poll_interrupts(JSContext *ctx) } } -/* return -1 (exception) or TRUE/FALSE */ +/* Return -1 (exception) or TRUE/FALSE. 'throw_flag' = FALSE indicates + that it is called from Reflect.setPrototypeOf(). */ static int JS_SetPrototypeInternal(JSContext *ctx, JSValueConst obj, JSValueConst proto_val, BOOL throw_flag) @@ -7225,8 +7221,20 @@ static int JS_SetPrototypeInternal(JSContext *ctx, JSValueConst obj, if (throw_flag && JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT) return TRUE; - if (unlikely(p->class_id == JS_CLASS_PROXY)) - return js_proxy_setPrototypeOf(ctx, obj, proto_val, throw_flag); + if (unlikely(p->is_exotic)) { + const JSClassExoticMethods *em = ctx->rt->class_array[p->class_id].exotic; + int ret; + if (em && em->set_prototype) { + ret = em->set_prototype(ctx, obj, proto_val); + if (ret == 0 && throw_flag) { + JS_ThrowTypeError(ctx, "proxy: bad prototype"); + return -1; + } else { + return ret; + } + } + } + sh = p->shape; if (sh->proto == proto) return TRUE; @@ -7303,22 +7311,24 @@ static JSValueConst JS_GetPrototypePrimitive(JSContext *ctx, JSValueConst val) return val; } -/* Return an Object, JS_NULL or JS_EXCEPTION in case of Proxy object. */ +/* Return an Object, JS_NULL or JS_EXCEPTION in case of exotic object. */ JSValue JS_GetPrototype(JSContext *ctx, JSValueConst obj) { JSValue val; if (JS_VALUE_GET_TAG(obj) == JS_TAG_OBJECT) { JSObject *p; p = JS_VALUE_GET_OBJ(obj); - if (unlikely(p->class_id == JS_CLASS_PROXY)) { - val = js_proxy_getPrototypeOf(ctx, obj); - } else { - p = p->shape->proto; - if (!p) - val = JS_NULL; - else - val = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p)); + if (unlikely(p->is_exotic)) { + const JSClassExoticMethods *em = ctx->rt->class_array[p->class_id].exotic; + if (em && em->get_prototype) { + return em->get_prototype(ctx, obj); + } } + p = p->shape->proto; + if (!p) + val = JS_NULL; + else + val = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, p)); } else { val = JS_DupValue(ctx, JS_GetPrototypePrimitive(ctx, obj)); } @@ -7365,8 +7375,8 @@ static int JS_OrdinaryIsInstanceOf(JSContext *ctx, JSValueConst val, for(;;) { proto1 = p->shape->proto; if (!proto1) { - /* slow case if proxy in the prototype chain */ - if (unlikely(p->class_id == JS_CLASS_PROXY)) { + /* slow case if exotic object in the prototype chain */ + if (unlikely(p->is_exotic && !p->fast_array)) { JSValue obj1; obj1 = JS_DupValue(ctx, JS_MKPTR(JS_TAG_OBJECT, (JSObject *)p)); for(;;) { @@ -8170,7 +8180,7 @@ int JS_GetOwnProperty(JSContext *ctx, JSPropertyDescriptor *desc, return JS_GetOwnPropertyInternal(ctx, desc, JS_VALUE_GET_OBJ(obj), prop); } -/* return -1 if exception (Proxy object only) or TRUE/FALSE */ +/* return -1 if exception (exotic object only) or TRUE/FALSE */ int JS_IsExtensible(JSContext *ctx, JSValueConst obj) { JSObject *p; @@ -8178,13 +8188,16 @@ int JS_IsExtensible(JSContext *ctx, JSValueConst obj) if (unlikely(JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)) return FALSE; p = JS_VALUE_GET_OBJ(obj); - if (unlikely(p->class_id == JS_CLASS_PROXY)) - return js_proxy_isExtensible(ctx, obj); - else - return p->extensible; + if (unlikely(p->is_exotic)) { + const JSClassExoticMethods *em = ctx->rt->class_array[p->class_id].exotic; + if (em && em->is_extensible) { + return em->is_extensible(ctx, obj); + } + } + return p->extensible; } -/* return -1 if exception (Proxy object only) or TRUE/FALSE */ +/* return -1 if exception (exotic object only) or TRUE/FALSE */ int JS_PreventExtensions(JSContext *ctx, JSValueConst obj) { JSObject *p; @@ -8192,8 +8205,12 @@ int JS_PreventExtensions(JSContext *ctx, JSValueConst obj) if (unlikely(JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)) return FALSE; p = JS_VALUE_GET_OBJ(obj); - if (unlikely(p->class_id == JS_CLASS_PROXY)) - return js_proxy_preventExtensions(ctx, obj); + if (unlikely(p->is_exotic)) { + const JSClassExoticMethods *em = ctx->rt->class_array[p->class_id].exotic; + if (em && em->prevent_extensions) { + return em->prevent_extensions(ctx, obj); + } + } p->extensible = FALSE; return TRUE; } @@ -16302,6 +16319,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, { JSValue val; + sf->cur_pc = pc; val = JS_GetProperty(ctx, sp[-1], JS_ATOM_length); if (unlikely(JS_IsException(val))) goto exception; @@ -16654,6 +16672,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, int magic; magic = get_u16(pc); pc += 2; + sf->cur_pc = pc; ret_val = js_function_apply(ctx, sp[-3], 2, (JSValueConst *)&sp[-2], magic); if (unlikely(JS_IsException(ret_val))) @@ -16800,6 +16819,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, scope_idx = get_u16(pc) + ARG_SCOPE_END; pc += 2; + sf->cur_pc = pc; tab = build_arg_list(ctx, &len, sp[-1]); if (!tab) goto exception; @@ -16835,6 +16855,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, CASE(OP_get_super): { JSValue proto; + sf->cur_pc = pc; proto = JS_GetPrototype(ctx, sp[-1]); if (JS_IsException(proto)) goto exception; @@ -16846,6 +16867,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, CASE(OP_import): { JSValue val; + sf->cur_pc = pc; val = js_dynamic_import(ctx, sp[-1]); if (JS_IsException(val)) goto exception; @@ -16860,6 +16882,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, JSAtom atom; atom = get_u32(pc); pc += 4; + sf->cur_pc = pc; ret = JS_CheckGlobalVar(ctx, atom); if (ret < 0) @@ -16875,6 +16898,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, JSAtom atom; atom = get_u32(pc); pc += 4; + sf->cur_pc = pc; val = JS_GetGlobalVar(ctx, atom, opcode - OP_get_var_undef); if (unlikely(JS_IsException(val))) @@ -16890,6 +16914,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, JSAtom atom; atom = get_u32(pc); pc += 4; + sf->cur_pc = pc; ret = JS_SetGlobalVar(ctx, atom, sp[-1], opcode - OP_put_var); sp--; @@ -16904,6 +16929,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, JSAtom atom; atom = get_u32(pc); pc += 4; + sf->cur_pc = pc; /* sp[-2] is JS_TRUE or JS_FALSE */ if (unlikely(!JS_VALUE_GET_INT(sp[-2]))) { @@ -16924,6 +16950,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, atom = get_u32(pc); flags = pc[4]; pc += 5; + sf->cur_pc = pc; if (JS_CheckDefineGlobalVar(ctx, atom, flags)) goto exception; } @@ -16935,6 +16962,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, atom = get_u32(pc); flags = pc[4]; pc += 5; + sf->cur_pc = pc; if (JS_DefineGlobalVar(ctx, atom, flags)) goto exception; } @@ -16946,6 +16974,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, atom = get_u32(pc); flags = pc[4]; pc += 5; + sf->cur_pc = pc; if (JS_DefineGlobalFunction(ctx, atom, sp[-1], flags)) goto exception; JS_FreeValue(ctx, sp[-1]); @@ -17224,6 +17253,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, JSAtom atom; atom = get_u32(pc); pc += 4; + sf->cur_pc = pc; if (JS_GetGlobalVarRef(ctx, atom, sp)) goto exception; @@ -17369,15 +17399,18 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, BREAK; CASE(OP_for_in_start): + sf->cur_pc = pc; if (js_for_in_start(ctx, sp)) goto exception; BREAK; CASE(OP_for_in_next): + sf->cur_pc = pc; if (js_for_in_next(ctx, sp)) goto exception; sp += 2; BREAK; CASE(OP_for_of_start): + sf->cur_pc = pc; if (js_for_of_start(ctx, sp, FALSE)) goto exception; sp += 1; @@ -17387,23 +17420,27 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, { int offset = -3 - pc[0]; pc += 1; + sf->cur_pc = pc; if (js_for_of_next(ctx, sp, offset)) goto exception; sp += 2; } BREAK; CASE(OP_for_await_of_next): + sf->cur_pc = pc; if (js_for_await_of_next(ctx, sp)) goto exception; sp++; BREAK; CASE(OP_for_await_of_start): + sf->cur_pc = pc; if (js_for_of_start(ctx, sp, TRUE)) goto exception; sp += 1; *sp++ = JS_NewCatchOffset(ctx, 0); BREAK; CASE(OP_iterator_get_value_done): + sf->cur_pc = pc; if (js_iterator_get_value_done(ctx, sp)) goto exception; sp += 1; @@ -17421,6 +17458,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, JS_FreeValue(ctx, sp[-1]); /* drop the next method */ sp--; if (!JS_IsUndefined(sp[-1])) { + sf->cur_pc = pc; if (JS_IteratorClose(ctx, sp[-1], FALSE)) goto exception; JS_FreeValue(ctx, sp[-1]); @@ -17449,6 +17487,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, /* stack: iter_obj next catch_offset val */ { JSValue ret; + sf->cur_pc = pc; ret = JS_Call(ctx, sp[-3], sp[-4], 1, (JSValueConst *)(sp - 1)); if (JS_IsException(ret)) @@ -17465,6 +17504,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, BOOL ret_flag; int flags; flags = *pc++; + sf->cur_pc = pc; method = JS_GetProperty(ctx, sp[-4], (flags & 1) ? JS_ATOM_throw : JS_ATOM_return); if (JS_IsException(method)) @@ -17513,6 +17553,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, atom = get_u32(pc); pc += 4; + sf->cur_pc = pc; val = JS_GetProperty(ctx, sp[-1], atom); if (unlikely(JS_IsException(val))) goto exception; @@ -17528,6 +17569,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, atom = get_u32(pc); pc += 4; + sf->cur_pc = pc; val = JS_GetProperty(ctx, sp[-1], atom); if (unlikely(JS_IsException(val))) goto exception; @@ -17541,6 +17583,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, JSAtom atom; atom = get_u32(pc); pc += 4; + sf->cur_pc = pc; ret = JS_SetPropertyInternal(ctx, sp[-2], atom, sp[-1], sp[-2], JS_PROP_THROW_STRICT); @@ -17640,6 +17683,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, CASE(OP_set_proto): { JSValue proto; + sf->cur_pc = pc; proto = sp[-1]; if (JS_IsObject(proto) || JS_IsNull(proto)) { if (JS_SetPrototypeInternal(ctx, sp[-2], proto, TRUE) < 0) @@ -17732,6 +17776,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, { JSValue val; + sf->cur_pc = pc; val = JS_GetPropertyValue(ctx, sp[-2], sp[-1]); JS_FreeValue(ctx, sp[-2]); sp[-2] = val; @@ -17745,6 +17790,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, { JSValue val; + sf->cur_pc = pc; val = JS_GetPropertyValue(ctx, sp[-2], sp[-1]); sp[-1] = val; if (unlikely(JS_IsException(val))) @@ -17758,6 +17804,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, JSAtom atom; int ret; + sf->cur_pc = pc; atom = JS_ValueToAtom(ctx, sp[-1]); if (atom == JS_ATOM_NULL) goto exception; @@ -17793,6 +17840,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, { JSValue val; JSAtom atom; + sf->cur_pc = pc; atom = JS_ValueToAtom(ctx, sp[-1]); if (unlikely(atom == JS_ATOM_NULL)) goto exception; @@ -17812,6 +17860,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, { int ret; + sf->cur_pc = pc; ret = JS_SetPropertyValue(ctx, sp[-3], sp[-2], sp[-1], JS_PROP_THROW_STRICT); JS_FreeValue(ctx, sp[-3]); sp -= 3; @@ -17824,6 +17873,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, { int ret; JSAtom atom; + sf->cur_pc = pc; atom = JS_ValueToAtom(ctx, sp[-2]); if (unlikely(atom == JS_ATOM_NULL)) goto exception; @@ -17862,6 +17912,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, { int ret; JSAtom atom; + sf->cur_pc = pc; if (JS_VALUE_GET_TAG(sp[-3]) != JS_TAG_OBJECT) { JS_ThrowTypeErrorNotAnObject(ctx); goto exception; @@ -17894,6 +17945,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, CASE(OP_append): /* array pos enumobj -- array pos */ { + sf->cur_pc = pc; if (js_append_enumerate(ctx, sp)) goto exception; JS_FreeValue(ctx, *--sp); @@ -17909,6 +17961,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, int mask; mask = *pc++; + sf->cur_pc = pc; if (JS_CopyDataProperties(ctx, sp[-1 - (mask & 3)], sp[-1 - ((mask >> 2) & 7)], sp[-1 - ((mask >> 5) & 7)], 0)) @@ -17939,6 +17992,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, goto exception; } else { add_slow: + sf->cur_pc = pc; if (js_add_slow(ctx, sp)) goto exception; sp--; @@ -17968,6 +18022,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, sp--; } else if (JS_VALUE_GET_TAG(*pv) == JS_TAG_STRING) { sp--; + sf->cur_pc = pc; op2 = JS_ToPrimitiveFree(ctx, op2, HINT_NONE); if (JS_IsException(op2)) goto exception; @@ -17984,6 +18039,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, add_loc_slow: /* In case of exception, js_add_slow frees ops[0] and ops[1], so we must duplicate *pv */ + sf->cur_pc = pc; ops[0] = JS_DupValue(ctx, *pv); ops[1] = op2; sp--; @@ -18086,6 +18142,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, BREAK; CASE(OP_pow): binary_arith_slow: + sf->cur_pc = pc; if (js_binary_arith_slow(ctx, sp, opcode)) goto exception; sp--; @@ -18099,6 +18156,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, tag = JS_VALUE_GET_TAG(op1); if (tag == JS_TAG_INT || JS_TAG_IS_FLOAT64(tag)) { } else { + sf->cur_pc = pc; if (js_unary_arith_slow(ctx, sp, opcode)) goto exception; } @@ -18129,6 +18187,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, neg_fp_res: sp[-1] = __JS_NewFloat64(ctx, d); } else { + sf->cur_pc = pc; if (js_unary_arith_slow(ctx, sp, opcode)) goto exception; } @@ -18146,6 +18205,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, sp[-1] = JS_NewInt32(ctx, val + 1); } else { inc_slow: + sf->cur_pc = pc; if (js_unary_arith_slow(ctx, sp, opcode)) goto exception; } @@ -18163,6 +18223,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, sp[-1] = JS_NewInt32(ctx, val - 1); } else { dec_slow: + sf->cur_pc = pc; if (js_unary_arith_slow(ctx, sp, opcode)) goto exception; } @@ -18170,6 +18231,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, BREAK; CASE(OP_post_inc): CASE(OP_post_dec): + sf->cur_pc = pc; if (js_post_inc_slow(ctx, sp, opcode)) goto exception; sp++; @@ -18190,6 +18252,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, var_buf[idx] = JS_NewInt32(ctx, val + 1); } else { inc_loc_slow: + sf->cur_pc = pc; /* must duplicate otherwise the variable value may be destroyed before JS code accesses it */ op1 = JS_DupValue(ctx, op1); @@ -18215,6 +18278,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, var_buf[idx] = JS_NewInt32(ctx, val - 1); } else { dec_loc_slow: + sf->cur_pc = pc; /* must duplicate otherwise the variable value may be destroyed before JS code accesses it */ op1 = JS_DupValue(ctx, op1); @@ -18231,6 +18295,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, if (JS_VALUE_GET_TAG(op1) == JS_TAG_INT) { sp[-1] = JS_NewInt32(ctx, ~JS_VALUE_GET_INT(op1)); } else { + sf->cur_pc = pc; if (js_not_slow(ctx, sp)) goto exception; } @@ -18250,6 +18315,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, sp[-2] = JS_NewInt32(ctx, v1 << v2); sp--; } else { + sf->cur_pc = pc; if (js_binary_logic_slow(ctx, sp, opcode)) goto exception; sp--; @@ -18270,6 +18336,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, v2); sp--; } else { + sf->cur_pc = pc; if (js_shr_slow(ctx, sp)) goto exception; sp--; @@ -18289,6 +18356,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, (int)JS_VALUE_GET_INT(op1) >> v2); sp--; } else { + sf->cur_pc = pc; if (js_binary_logic_slow(ctx, sp, opcode)) goto exception; sp--; @@ -18306,6 +18374,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, JS_VALUE_GET_INT(op2)); sp--; } else { + sf->cur_pc = pc; if (js_binary_logic_slow(ctx, sp, opcode)) goto exception; sp--; @@ -18323,6 +18392,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, JS_VALUE_GET_INT(op2)); sp--; } else { + sf->cur_pc = pc; if (js_binary_logic_slow(ctx, sp, opcode)) goto exception; sp--; @@ -18340,6 +18410,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, JS_VALUE_GET_INT(op2)); sp--; } else { + sf->cur_pc = pc; if (js_binary_logic_slow(ctx, sp, opcode)) goto exception; sp--; @@ -18358,6 +18429,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, sp[-2] = JS_NewBool(ctx, JS_VALUE_GET_INT(op1) binary_op JS_VALUE_GET_INT(op2)); \ sp--; \ } else { \ + sf->cur_pc = pc; \ if (slow_call) \ goto exception; \ sp--; \ @@ -18375,16 +18447,19 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, OP_CMP(OP_strict_neq, !=, js_strict_eq_slow(ctx, sp, 1)); CASE(OP_in): + sf->cur_pc = pc; if (js_operator_in(ctx, sp)) goto exception; sp--; BREAK; CASE(OP_private_in): + sf->cur_pc = pc; if (js_operator_private_in(ctx, sp)) goto exception; sp--; BREAK; CASE(OP_instanceof): + sf->cur_pc = pc; if (js_operator_instanceof(ctx, sp)) goto exception; sp--; @@ -18401,6 +18476,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, } BREAK; CASE(OP_delete): + sf->cur_pc = pc; if (js_operator_delete(ctx, sp)) goto exception; sp--; @@ -18412,6 +18488,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, atom = get_u32(pc); pc += 4; + sf->cur_pc = pc; ret = JS_DeleteProperty(ctx, ctx->global_obj, atom, 0); if (unlikely(ret < 0)) @@ -18422,6 +18499,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, CASE(OP_to_object): if (JS_VALUE_GET_TAG(sp[-1]) != JS_TAG_OBJECT) { + sf->cur_pc = pc; ret_val = JS_ToObject(ctx, sp[-1]); if (JS_IsException(ret_val)) goto exception; @@ -18437,6 +18515,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, case JS_TAG_SYMBOL: break; default: + sf->cur_pc = pc; ret_val = JS_ToPropertyKey(ctx, sp[-1]); if (JS_IsException(ret_val)) goto exception; @@ -18458,6 +18537,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, case JS_TAG_SYMBOL: break; default: + sf->cur_pc = pc; ret_val = JS_ToPropertyKey(ctx, sp[-1]); if (JS_IsException(ret_val)) goto exception; @@ -18491,6 +18571,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, diff = get_u32(pc + 4); is_with = pc[8]; pc += 9; + sf->cur_pc = pc; obj = sp[-1]; ret = JS_HasProperty(ctx, obj, atom); @@ -24692,14 +24773,13 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) case TOK_IDENT: { JSAtom name; + const uint8_t *source_ptr; if (s->token.u.ident.is_reserved) { return js_parse_error_reserved_identifier(s); } + source_ptr = s->token.ptr; if (token_is_pseudo_keyword(s, JS_ATOM_async) && peek_token(s, TRUE) != '\n') { - const uint8_t *source_ptr; - - source_ptr = s->token.ptr; if (next_token(s)) return -1; if (s->token.val == TOK_FUNCTION) { @@ -24718,11 +24798,12 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags) return -1; } name = JS_DupAtom(s->ctx, s->token.u.ident.atom); - if (next_token(s)) { /* update line number before emitting code */ + if (next_token(s)) { JS_FreeAtom(s->ctx, name); return -1; } do_get_var: + emit_source_pos(s, source_ptr); emit_op(s, OP_scope_get_var); emit_u32(s, name); emit_u16(s, s->cur_func->scope_level); @@ -25315,6 +25396,7 @@ static __exception int js_parse_delete(JSParseState *s) static __exception int js_parse_unary(JSParseState *s, int parse_flags) { int op; + const uint8_t *op_token_ptr; switch(s->token.val) { case '+': @@ -25322,6 +25404,7 @@ static __exception int js_parse_unary(JSParseState *s, int parse_flags) case '!': case '~': case TOK_VOID: + op_token_ptr = s->token.ptr; op = s->token.val; if (next_token(s)) return -1; @@ -25329,15 +25412,18 @@ static __exception int js_parse_unary(JSParseState *s, int parse_flags) return -1; switch(op) { case '-': + emit_source_pos(s, op_token_ptr); emit_op(s, OP_neg); break; case '+': + emit_source_pos(s, op_token_ptr); emit_op(s, OP_plus); break; case '!': emit_op(s, OP_lnot); break; case '~': + emit_source_pos(s, op_token_ptr); emit_op(s, OP_not); break; case TOK_VOID: @@ -25355,12 +25441,14 @@ static __exception int js_parse_unary(JSParseState *s, int parse_flags) int opcode, op, scope, label; JSAtom name; op = s->token.val; + op_token_ptr = s->token.ptr; if (next_token(s)) return -1; if (js_parse_unary(s, 0)) return -1; if (get_lvalue(s, &opcode, &scope, &name, &label, NULL, TRUE, op)) return -1; + emit_source_pos(s, op_token_ptr); emit_op(s, OP_dec + op - TOK_DEC); put_lvalue(s, opcode, scope, name, label, PUT_LVALUE_KEEP_TOP, FALSE); @@ -25409,8 +25497,10 @@ static __exception int js_parse_unary(JSParseState *s, int parse_flags) int opcode, op, scope, label; JSAtom name; op = s->token.val; + op_token_ptr = s->token.ptr; if (get_lvalue(s, &opcode, &scope, &name, &label, NULL, TRUE, op)) return -1; + emit_source_pos(s, op_token_ptr); emit_op(s, OP_post_dec + op - TOK_DEC); put_lvalue(s, opcode, scope, name, label, PUT_LVALUE_KEEP_SECOND, FALSE); @@ -25430,10 +25520,12 @@ static __exception int js_parse_unary(JSParseState *s, int parse_flags) JS_ThrowSyntaxError(s->ctx, "unparenthesized unary expression can't appear on the left-hand side of '**'"); return -1; } + op_token_ptr = s->token.ptr; if (next_token(s)) return -1; if (js_parse_unary(s, PF_POW_ALLOWED)) return -1; + emit_source_pos(s, op_token_ptr); emit_op(s, OP_pow); } } @@ -25903,6 +25995,8 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags) op = s->token.val; if (op == '=' || (op >= TOK_MUL_ASSIGN && op <= TOK_POW_ASSIGN)) { int label; + const uint8_t *op_token_ptr; + op_token_ptr = s->token.ptr; if (next_token(s)) return -1; if (get_lvalue(s, &opcode, &scope, &name, &label, NULL, (op != '='), op) < 0) @@ -25924,6 +26018,7 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags) OP_pow, }; op = assign_opcodes[op - TOK_MUL_ASSIGN]; + emit_source_pos(s, op_token_ptr); emit_op(s, op); } put_lvalue(s, opcode, scope, name, label, PUT_LVALUE_KEEP_TOP, FALSE); @@ -45976,7 +46071,7 @@ static JSProxyData *get_proxy_method(JSContext *ctx, JSValue *pmethod, return s; } -static JSValue js_proxy_getPrototypeOf(JSContext *ctx, JSValueConst obj) +static JSValue js_proxy_get_prototype(JSContext *ctx, JSValueConst obj) { JSProxyData *s; JSValue method, ret, proto1; @@ -46017,8 +46112,8 @@ static JSValue js_proxy_getPrototypeOf(JSContext *ctx, JSValueConst obj) return ret; } -static int js_proxy_setPrototypeOf(JSContext *ctx, JSValueConst obj, - JSValueConst proto_val, BOOL throw_flag) +static int js_proxy_set_prototype(JSContext *ctx, JSValueConst obj, + JSValueConst proto_val) { JSProxyData *s; JSValue method, ret, proto1; @@ -46030,21 +46125,15 @@ static int js_proxy_setPrototypeOf(JSContext *ctx, JSValueConst obj, if (!s) return -1; if (JS_IsUndefined(method)) - return JS_SetPrototypeInternal(ctx, s->target, proto_val, throw_flag); + return JS_SetPrototypeInternal(ctx, s->target, proto_val, FALSE); args[0] = s->target; args[1] = proto_val; ret = JS_CallFree(ctx, method, s->handler, 2, args); if (JS_IsException(ret)) return -1; res = JS_ToBoolFree(ctx, ret); - if (!res) { - if (throw_flag) { - JS_ThrowTypeError(ctx, "proxy: bad prototype"); - return -1; - } else { - return FALSE; - } - } + if (!res) + return FALSE; res2 = JS_IsExtensible(ctx, s->target); if (res2 < 0) return -1; @@ -46062,7 +46151,7 @@ static int js_proxy_setPrototypeOf(JSContext *ctx, JSValueConst obj, return TRUE; } -static int js_proxy_isExtensible(JSContext *ctx, JSValueConst obj) +static int js_proxy_is_extensible(JSContext *ctx, JSValueConst obj) { JSProxyData *s; JSValue method, ret; @@ -46088,7 +46177,7 @@ static int js_proxy_isExtensible(JSContext *ctx, JSValueConst obj) return res; } -static int js_proxy_preventExtensions(JSContext *ctx, JSValueConst obj) +static int js_proxy_prevent_extensions(JSContext *ctx, JSValueConst obj) { JSProxyData *s; JSValue method, ret; @@ -46796,6 +46885,10 @@ static const JSClassExoticMethods js_proxy_exotic_methods = { .has_property = js_proxy_has, .get_property = js_proxy_get, .set_property = js_proxy_set, + .get_prototype = js_proxy_get_prototype, + .set_prototype = js_proxy_set_prototype, + .is_extensible = js_proxy_is_extensible, + .prevent_extensions = js_proxy_prevent_extensions, }; static JSValue js_proxy_constructor(JSContext *ctx, JSValueConst this_val, diff --git a/src/couch_quickjs/quickjs/quickjs.h b/src/couch_quickjs/quickjs/quickjs.h index a75d990fd..881422260 100644 --- a/src/couch_quickjs/quickjs/quickjs.h +++ b/src/couch_quickjs/quickjs/quickjs.h @@ -501,6 +501,17 @@ typedef struct JSClassExoticMethods { /* return < 0 if exception or TRUE/FALSE */ int (*set_property)(JSContext *ctx, JSValueConst obj, JSAtom atom, JSValueConst value, JSValueConst receiver, int flags); + + /* To get a consistent object behavior when get_prototype != NULL, + get_property, set_property and set_prototype must be != NULL + and the object must be created with a JS_NULL prototype. */ + JSValue (*get_prototype)(JSContext *ctx, JSValueConst obj); + /* return < 0 if exception or TRUE/FALSE */ + int (*set_prototype)(JSContext *ctx, JSValueConst obj, JSValueConst proto_val); + /* return < 0 if exception or TRUE/FALSE */ + int (*is_extensible)(JSContext *ctx, JSValueConst obj); + /* return < 0 if exception or TRUE/FALSE */ + int (*prevent_extensions)(JSContext *ctx, JSValueConst obj); } JSClassExoticMethods; typedef void JSClassFinalizer(JSRuntime *rt, JSValue val); diff --git a/src/couch_quickjs/update_and_apply_patches.sh b/src/couch_quickjs/update_and_apply_patches.sh index 121ca20ce..92fbb6355 100755 --- a/src/couch_quickjs/update_and_apply_patches.sh +++ b/src/couch_quickjs/update_and_apply_patches.sh @@ -40,6 +40,8 @@ rm quickjs/unicode_download.sh rm quickjs/repl.js rm quickjs/qjs.c rm quickjs/TODO +rm quickjs/readme-cosmo.txt + echo echo " * apply patches" find patches -name "*.patch" -print0 | sort -z | xargs -t -0 -n 1 patch -p0 -i
