Skip to content

Commit df62328

Browse files
committed
Version 3.5.0 (2023-05):
1. `[QuickJs]` add support for QuickJs 2024-01-13
1 parent 582d1c5 commit df62328

File tree

8 files changed

+104
-10
lines changed

8 files changed

+104
-10
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
Version 3.5.0 (2023-05):
2+
1. `[QuickJs]` add support for QuickJs 2024-01-13
13

24
Version 3.4.0 (2023-05):
35
1. `[V8]` **BEHAVIOR CHANGE:** `V8Platform` now being a singleton, not ref-counted by `V8Engine`s any more.

README-zh.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ScriptX的术语中,"前端"指对外的C++ API,"后端"则指不同的底
2323
| V8 | JavaScript | 7.4+ | done |
2424
| JavaScriptCore | JavaScript | 7604.1.38.0.7+<br>(iOS 10+/macOS10.12+) | done |
2525
| Node.js | JavaScript | 14.x+ | done |
26-
| QuickJs | JavaScript | 2021-03-27 | done |
26+
| QuickJs | JavaScript | 2024-01-13 | done |
2727
| WebAssembly | JavaScript | Emscripten-2.0.5+ | done |
2828
| Lua | Lua | 5.4+ | done |
2929
| CPython | Python | | todo |

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ In ScriptX terminology, "front-end" refers to the external C++ API, and "back-en
2222
| V8 | JavaScript | 7.4+ | done |
2323
| JavaScriptCore | JavaScript | 7604.1.38.0.7+<br>(iOS 10+/macOS10.12+) | done |
2424
| Node.js | JavaScript | 14.x+ | done |
25-
| QuickJs | JavaScript | 2021-03-27 | done |
25+
| QuickJs | JavaScript | 2024-01-13 | done |
2626
| WebAssembly | JavaScript | Emscripten-2.0.5+ | done |
2727
| Lua | Lua | 5.4+ | done |
2828
| CPython | Python | | todo |

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.4.0
1+
3.5.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
From 8f4fa37cfbb34fdd314d9af831408993ba6f4d5a Mon Sep 17 00:00:00 2001
2+
From: landerlyoung <[email protected]>
3+
Date: Fri, 9 Feb 2024 03:49:37 +0800
4+
Subject: [PATCH] Add new APIs for ScriptX based on QuickJs version
5+
"2024-01-13" Changes: 1. add JS_StrictEqual 2. add JS_NewWeakRef 3. add
6+
JS_GetWeakRef
7+
8+
---
9+
quickjs.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
10+
quickjs.h | 5 +++++
11+
2 files changed, 51 insertions(+)
12+
13+
diff --git a/quickjs.c b/quickjs.c
14+
index 7958f81..b24873a 100644
15+
--- a/quickjs.c
16+
+++ b/quickjs.c
17+
@@ -1130,6 +1130,10 @@ typedef enum JSStrictEqModeEnum {
18+
static BOOL js_strict_eq2(JSContext *ctx, JSValue op1, JSValue op2,
19+
JSStrictEqModeEnum eq_mode);
20+
static BOOL js_strict_eq(JSContext *ctx, JSValue op1, JSValue op2);
21+
+int JS_StrictEqual(JSContext *ctx, JSValueConst op1, JSValueConst op2)
22+
+{
23+
+ return js_strict_eq(ctx, JS_DupValue(ctx, op1), JS_DupValue(ctx, op2));
24+
+}
25+
static BOOL js_same_value(JSContext *ctx, JSValueConst op1, JSValueConst op2);
26+
static BOOL js_same_value_zero(JSContext *ctx, JSValueConst op1, JSValueConst op2);
27+
static JSValue JS_ToObject(JSContext *ctx, JSValueConst val);
28+
@@ -55566,3 +55570,45 @@ void JS_AddIntrinsicTypedArrays(JSContext *ctx)
29+
JS_AddIntrinsicAtomics(ctx);
30+
#endif
31+
}
32+
+
33+
+
34+
+/************* WeakRef ***********/
35+
+JSValue JS_NewWeakRef(JSContext* ctx, JSValueConst v)
36+
+{
37+
+ if (JS_IsObject(v)) {
38+
+ JSValue map = js_map_constructor(ctx, JS_UNDEFINED, 0, NULL, MAGIC_SET | MAGIC_WEAK);
39+
+ if (JS_IsException(map)) return JS_EXCEPTION;
40+
+ // check
41+
+ JSValue ret = js_map_set(ctx, map, 1, &v, MAGIC_SET | MAGIC_WEAK);
42+
+ if (JS_IsException(ret)) return JS_EXCEPTION;
43+
+ JS_FreeValue(ctx, ret);
44+
+ return map;
45+
+ } else {
46+
+ return JS_DupValue(ctx, v);
47+
+ }
48+
+}
49+
+
50+
+static JSValue js_map_get_first_key(JSContext *ctx, JSValueConst this_val)
51+
+{
52+
+ JSMapState *s = JS_GetOpaque2(ctx, this_val, JS_CLASS_WEAKSET);
53+
+ JSMapRecord *mr;
54+
+ JSValueConst key = JS_UNDEFINED;
55+
+ struct list_head *el;
56+
+
57+
+ if (!s) return JS_EXCEPTION;
58+
+ el = s->records.next;
59+
+ if (el != &(s->records)) {
60+
+ mr = list_entry(el, JSMapRecord, link);
61+
+ key = mr->key;
62+
+ }
63+
+ return JS_DupValue(ctx, key);
64+
+}
65+
+
66+
+JSValue JS_GetWeakRef(JSContext* ctx, JSValueConst w)
67+
+{
68+
+ if (JS_IsObject(w)) {
69+
+ return js_map_get_first_key(ctx, w);
70+
+ } else {
71+
+ return JS_DupValue(ctx, w);
72+
+ }
73+
+}
74+
diff --git a/quickjs.h b/quickjs.h
75+
index 56bac64..0908325 100644
76+
--- a/quickjs.h
77+
+++ b/quickjs.h
78+
@@ -681,6 +681,11 @@ static inline JSValue JS_DupValueRT(JSRuntime *rt, JSValueConst v)
79+
return (JSValue)v;
80+
}
81+
82+
+#define QUICK_JS_HAS_SCRIPTX_PATCH
83+
+JSValue JS_NewWeakRef(JSContext* ctx, JSValueConst v);
84+
+JSValue JS_GetWeakRef(JSContext* ctx, JSValueConst w);
85+
+int JS_StrictEqual(JSContext *ctx, JSValueConst op1, JSValueConst op2);
86+
+
87+
int JS_ToBool(JSContext *ctx, JSValueConst val); /* return -1 for JS_EXCEPTION */
88+
int JS_ToInt32(JSContext *ctx, int32_t *pres, JSValueConst val);
89+
static inline int JS_ToUint32(JSContext *ctx, uint32_t *pres, JSValueConst val)
90+
--
91+
2.42.1
92+

docs/en/QuickJs.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# QuickJs engine
22

3-
Current support QuickJs version is 2021-03-27.
3+
Current support QuickJs version is 2021-03-27 and 2024-01-13.
44

55
Other version should be also supported.
66

docs/zh/QuickJs.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# QuickJs 引擎
22

3-
目前支持的QuickJs引擎版本为2021-03-27,其他版本理论上也能支持。
3+
目前支持的QuickJs引擎版本为2021-03-27和2024-01-13,其他版本理论上也能支持。
44

5-
## 时间循环
5+
## 事件循环
66
QuickJs通过 JS_ExecutePendingJob 来执行promise相关的异步事件,ScriptX中提供了MessageQueue机制。
77
因此ScriptX内部会主动在合适的时机post事件来驱动执行 `JS_ExecutePendingJob`
88

99
## 关于补丁
1010
由于QuickJs的C-API比较受限,ScriptX将部分需要的能力通过JS来实现。
1111

12-
但是仍然有部分能力(如弱引用)在JS中也不受支持。这个情况下你需要QuickJs打一个ScriptX提供的补丁包[backend/QuickJs/patch](../../backend/QuickJs/patch),或直接使用笔者的 [fork](https://github.com/LanderlYoung/quickjs/tree/58ac957eee57e301ed0cc52b5de5495a7e1c1827)
12+
但是仍然有部分能力(如弱引用)在JS中也不受支持。这个情况下你需要QuickJs打一个ScriptX提供的补丁包[backend/QuickJs/patch](../../backend/QuickJs/patch),或直接使用笔者的 [fork](https://github.com/LanderlYoung/quickjs/)
1313

1414
目前这个补丁仅影响 `script::Weak<T>` 的功能。
1515
即使不打该补丁包,也仅仅是 `script::Weak<T>` 表现为强引用即`script::Global<T>`,除此之外无差别。

src/version.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Tencent is pleased to support the open source community by making ScriptX available.
3-
* Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
3+
* Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved.
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -19,9 +19,9 @@
1919

2020
// ScriptX version config files
2121
// auto generated from the file VERSION
22-
#define SCRIPTX_VERSION_STRING "3.4.0"
22+
#define SCRIPTX_VERSION_STRING "3.5.0"
2323
#define SCRIPTX_VERSION_MAJOR 3
24-
#define SCRIPTX_VERSION_MINOR 4
24+
#define SCRIPTX_VERSION_MINOR 5
2525
#define SCRIPTX_VERSION_PATCH 0
2626

2727
namespace script {

0 commit comments

Comments
 (0)