Skip to content

Commit eb8756d

Browse files
author
DarcJC
committed
Apply quickjspp patches on latest QuickJS
1 parent 67723c9 commit eb8756d

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

quickjs.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ struct JSRuntime {
277277

278278
JSHostPromiseRejectionTracker *host_promise_rejection_tracker;
279279
void *host_promise_rejection_tracker_opaque;
280+
281+
JSHostPromiseRejectionTracker *host_unhandled_promise_rejection_tracker;
282+
void *host_unhandled_promise_rejection_tracker_opaque;
280283

281284
struct list_head job_list; /* list of JSJobEntry.link */
282285

@@ -3398,6 +3401,16 @@ JSClassID JS_NewClassID(JSClassID *pclass_id)
33983401
return class_id;
33993402
}
34003403

3404+
JSClassID JS_GetClassID(JSValueConst v)
3405+
{
3406+
JSObject* obj;
3407+
if (JS_VALUE_GET_TAG(v) != JS_TAG_OBJECT)
3408+
return 0;
3409+
obj = JS_VALUE_GET_OBJ(v);
3410+
assert(obj != NULL);
3411+
return obj->class_id;
3412+
}
3413+
34013414
BOOL JS_IsRegisteredClass(JSRuntime *rt, JSClassID class_id)
34023415
{
34033416
return (class_id < rt->class_count &&
@@ -7898,6 +7911,9 @@ static JSValue JS_GetPropertyValue(JSContext *ctx, JSValueConst this_obj,
78987911
uint32_t idx;
78997912
/* fast path for array access */
79007913
p = JS_VALUE_GET_OBJ(this_obj);
7914+
if (unlikely(p->fast_array)) {
7915+
goto slow_path;
7916+
}
79017917
idx = JS_VALUE_GET_INT(prop);
79027918
switch(p->class_id) {
79037919
case JS_CLASS_ARRAY:
@@ -47663,6 +47679,7 @@ typedef struct JSPromiseData {
4766347679
struct list_head promise_reactions[2];
4766447680
BOOL is_handled; /* Note: only useful to debug */
4766547681
JSValue promise_result;
47682+
JSContext *ctx;
4766647683
} JSPromiseData;
4766747684

4766847685
typedef struct JSPromiseFunctionDataResolved {
@@ -47759,6 +47776,12 @@ void JS_SetHostPromiseRejectionTracker(JSRuntime *rt,
4775947776
rt->host_promise_rejection_tracker_opaque = opaque;
4776047777
}
4776147778

47779+
void JS_SetHostUnhandledPromiseRejectionTracker(JSRuntime * rt, JSHostPromiseRejectionTracker * cb, void * opaque)
47780+
{
47781+
rt->host_unhandled_promise_rejection_tracker = cb;
47782+
rt->host_unhandled_promise_rejection_tracker_opaque = opaque;
47783+
}
47784+
4776247785
static void fulfill_or_reject_promise(JSContext *ctx, JSValueConst promise,
4776347786
JSValueConst value, BOOL is_reject)
4776447787
{
@@ -47963,6 +47986,11 @@ static void js_promise_finalizer(JSRuntime *rt, JSValue val)
4796347986

4796447987
if (!s)
4796547988
return;
47989+
if (s->promise_state == JS_PROMISE_REJECTED && !s->is_handled) {
47990+
if (rt->host_unhandled_promise_rejection_tracker) {
47991+
rt->host_unhandled_promise_rejection_tracker(s->ctx, val, s->promise_result, FALSE, rt->host_unhandled_promise_rejection_tracker_opaque);
47992+
}
47993+
}
4796647994
for(i = 0; i < 2; i++) {
4796747995
list_for_each_safe(el, el1, &s->promise_reactions[i]) {
4796847996
JSPromiseReactionData *rd =
@@ -48013,6 +48041,7 @@ static JSValue js_promise_constructor(JSContext *ctx, JSValueConst new_target,
4801348041
s = js_mallocz(ctx, sizeof(*s));
4801448042
if (!s)
4801548043
goto fail;
48044+
s->ctx = ctx;
4801648045
s->promise_state = JS_PROMISE_PENDING;
4801748046
s->is_handled = FALSE;
4801848047
for(i = 0; i < 2; i++)

quickjs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ typedef struct JSClassDef {
500500
} JSClassDef;
501501

502502
JSClassID JS_NewClassID(JSClassID *pclass_id);
503+
JSClassID JS_GetClassID(JSValueConst v);
503504
int JS_NewClass(JSRuntime *rt, JSClassID class_id, const JSClassDef *class_def);
504505
int JS_IsRegisteredClass(JSRuntime *rt, JSClassID class_id);
505506

@@ -849,6 +850,7 @@ typedef void JSHostPromiseRejectionTracker(JSContext *ctx, JSValueConst promise,
849850
JSValueConst reason,
850851
JS_BOOL is_handled, void *opaque);
851852
void JS_SetHostPromiseRejectionTracker(JSRuntime *rt, JSHostPromiseRejectionTracker *cb, void *opaque);
853+
void JS_SetHostUnhandledPromiseRejectionTracker(JSRuntime *rt, JSHostPromiseRejectionTracker *cb, void *opaque);
852854

853855
/* return != 0 if the JS code needs to be interrupted */
854856
typedef int JSInterruptHandler(JSRuntime *rt, void *opaque);

0 commit comments

Comments
 (0)