diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d41c568..1da39c5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +Version 3.5.0 (2023-05): +1. `[QuickJs]` add support for QuickJs 2024-01-13 Version 3.4.0 (2023-05): 1. `[V8]` **BEHAVIOR CHANGE:** `V8Platform` now being a singleton, not ref-counted by `V8Engine`s any more. diff --git a/README-zh.md b/README-zh.md index ecffd7c4..7dc7e6e6 100644 --- a/README-zh.md +++ b/README-zh.md @@ -23,7 +23,7 @@ ScriptX的术语中,"前端"指对外的C++ API,"后端"则指不同的底 | V8 | JavaScript | 7.4+ | done | | JavaScriptCore | JavaScript | 7604.1.38.0.7+
(iOS 10+/macOS10.12+) | done | | Node.js | JavaScript | 14.x+ | done | -| QuickJs | JavaScript | 2021-03-27 | done | +| QuickJs | JavaScript | 2024-01-13 | done | | WebAssembly | JavaScript | Emscripten-2.0.5+ | done | | Lua | Lua | 5.4+ | done | | CPython | Python | | todo | diff --git a/README.md b/README.md index 586a9739..1c46d88a 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ In ScriptX terminology, "front-end" refers to the external C++ API, and "back-en | V8 | JavaScript | 7.4+ | done | | JavaScriptCore | JavaScript | 7604.1.38.0.7+
(iOS 10+/macOS10.12+) | done | | Node.js | JavaScript | 14.x+ | done | -| QuickJs | JavaScript | 2021-03-27 | done | +| QuickJs | JavaScript | 2024-01-13 | done | | WebAssembly | JavaScript | Emscripten-2.0.5+ | done | | Lua | Lua | 5.4+ | done | | CPython | Python | | todo | diff --git a/VERSION b/VERSION index fbcbf738..e5b82034 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.4.0 \ No newline at end of file +3.5.0 \ No newline at end of file diff --git a/backend/QuickJs/patch/0001-Add-new-APIs-for-ScriptX-for-QuickJs-2024-01-13.patch b/backend/QuickJs/patch/0001-Add-new-APIs-for-ScriptX-for-QuickJs-2024-01-13.patch new file mode 100644 index 00000000..1b5ed448 --- /dev/null +++ b/backend/QuickJs/patch/0001-Add-new-APIs-for-ScriptX-for-QuickJs-2024-01-13.patch @@ -0,0 +1,92 @@ +From 8f4fa37cfbb34fdd314d9af831408993ba6f4d5a Mon Sep 17 00:00:00 2001 +From: landerlyoung +Date: Fri, 9 Feb 2024 03:49:37 +0800 +Subject: [PATCH] Add new APIs for ScriptX based on QuickJs version + "2024-01-13" Changes: 1. add JS_StrictEqual 2. add JS_NewWeakRef 3. add + JS_GetWeakRef + +--- + quickjs.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ + quickjs.h | 5 +++++ + 2 files changed, 51 insertions(+) + +diff --git a/quickjs.c b/quickjs.c +index 7958f81..b24873a 100644 +--- a/quickjs.c ++++ b/quickjs.c +@@ -1130,6 +1130,10 @@ typedef enum JSStrictEqModeEnum { + static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2, + JSStrictEqModeEnum eq_mode); + static BOOL js_strict_eq(JSContext *ctx, JSValue op1, JSValue op2); ++int JS_StrictEqual(JSContext *ctx, JSValueConst op1, JSValueConst op2) ++{ ++ return js_strict_eq(ctx, JS_DupValue(ctx, op1), JS_DupValue(ctx, op2)); ++} + static BOOL js_same_value(JSContext *ctx, JSValueConst op1, JSValueConst op2); + static BOOL js_same_value_zero(JSContext *ctx, JSValueConst op1, JSValueConst op2); + static JSValue JS_ToObject(JSContext *ctx, JSValueConst val); +@@ -55566,3 +55570,45 @@ void JS_AddIntrinsicTypedArrays(JSContext *ctx) + JS_AddIntrinsicAtomics(ctx); + #endif + } ++ ++ ++/************* WeakRef ***********/ ++JSValue JS_NewWeakRef(JSContext* ctx, JSValueConst v) ++{ ++ if (JS_IsObject(v)) { ++ JSValue map = js_map_constructor(ctx, JS_UNDEFINED, 0, NULL, MAGIC_SET | MAGIC_WEAK); ++ if (JS_IsException(map)) return JS_EXCEPTION; ++ // check ++ JSValue ret = js_map_set(ctx, map, 1, &v, MAGIC_SET | MAGIC_WEAK); ++ if (JS_IsException(ret)) return JS_EXCEPTION; ++ JS_FreeValue(ctx, ret); ++ return map; ++ } else { ++ return JS_DupValue(ctx, v); ++ } ++} ++ ++static JSValue js_map_get_first_key(JSContext *ctx, JSValueConst this_val) ++{ ++ JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_WEAKSET); ++ JSMapRecord *mr; ++ JSValueConst key = JS_UNDEFINED; ++ struct list_head *el; ++ ++ if (!s) return JS_EXCEPTION; ++ el = s->records.next; ++ if (el != &(s->records)) { ++ mr = list_entry(el, JSMapRecord, link); ++ key = mr->key; ++ } ++ return JS_DupValue(ctx, key); ++} ++ ++JSValue JS_GetWeakRef(JSContext* ctx, JSValueConst w) ++{ ++ if (JS_IsObject(w)) { ++ return js_map_get_first_key(ctx, w); ++ } else { ++ return JS_DupValue(ctx, w); ++ } ++} +diff --git a/quickjs.h b/quickjs.h +index 56bac64..0908325 100644 +--- a/quickjs.h ++++ b/quickjs.h +@@ -681,6 +681,11 @@ static inline JSValue JS_DupValueRT(JSRuntime *rt, JSValueConst v) + return (JSValue)v; + } + ++#define QUICK_JS_HAS_SCRIPTX_PATCH ++JSValue JS_NewWeakRef(JSContext* ctx, JSValueConst v); ++JSValue JS_GetWeakRef(JSContext* ctx, JSValueConst w); ++int JS_StrictEqual(JSContext *ctx, JSValueConst op1, JSValueConst op2); ++ + int JS_ToBool(JSContext *ctx, JSValueConst val); /* return -1 for JS_EXCEPTION */ + int JS_ToInt32(JSContext *ctx, int32_t *pres, JSValueConst val); + static inline int JS_ToUint32(JSContext *ctx, uint32_t *pres, JSValueConst val) +-- +2.42.1 + diff --git a/docs/en/QuickJs.md b/docs/en/QuickJs.md index 866fb6e0..f3ae0a95 100644 --- a/docs/en/QuickJs.md +++ b/docs/en/QuickJs.md @@ -1,6 +1,6 @@ # QuickJs engine -Current support QuickJs version is 2021-03-27. +Current support QuickJs version is 2021-03-27 and 2024-01-13. Other version should be also supported. diff --git a/docs/zh/QuickJs.md b/docs/zh/QuickJs.md index 2d69874a..2ff34b92 100644 --- a/docs/zh/QuickJs.md +++ b/docs/zh/QuickJs.md @@ -1,15 +1,15 @@ # QuickJs 引擎 -目前支持的QuickJs引擎版本为2021-03-27,其他版本理论上也能支持。 +目前支持的QuickJs引擎版本为2021-03-27和2024-01-13,其他版本理论上也能支持。 -## 时间循环 +## 事件循环 QuickJs通过 JS_ExecutePendingJob 来执行promise相关的异步事件,ScriptX中提供了MessageQueue机制。 因此ScriptX内部会主动在合适的时机post事件来驱动执行 `JS_ExecutePendingJob`。 ## 关于补丁 由于QuickJs的C-API比较受限,ScriptX将部分需要的能力通过JS来实现。 -但是仍然有部分能力(如弱引用)在JS中也不受支持。这个情况下你需要QuickJs打一个ScriptX提供的补丁包[backend/QuickJs/patch](../../backend/QuickJs/patch),或直接使用笔者的 [fork](https://github.com/LanderlYoung/quickjs/tree/58ac957eee57e301ed0cc52b5de5495a7e1c1827) 。 +但是仍然有部分能力(如弱引用)在JS中也不受支持。这个情况下你需要QuickJs打一个ScriptX提供的补丁包[backend/QuickJs/patch](../../backend/QuickJs/patch),或直接使用笔者的 [fork](https://github.com/LanderlYoung/quickjs/) 。 目前这个补丁仅影响 `script::Weak` 的功能。 即使不打该补丁包,也仅仅是 `script::Weak` 表现为强引用即`script::Global`,除此之外无差别。 diff --git a/src/version.h b/src/version.h index 3a16fc5f..6797668c 100644 --- a/src/version.h +++ b/src/version.h @@ -1,6 +1,6 @@ /* * Tencent is pleased to support the open source community by making ScriptX available. - * Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. + * Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,9 @@ // ScriptX version config files // auto generated from the file VERSION -#define SCRIPTX_VERSION_STRING "3.4.0" +#define SCRIPTX_VERSION_STRING "3.5.0" #define SCRIPTX_VERSION_MAJOR 3 -#define SCRIPTX_VERSION_MINOR 4 +#define SCRIPTX_VERSION_MINOR 5 #define SCRIPTX_VERSION_PATCH 0 namespace script {