diff --git a/.changeset/tame-humans-sleep.md b/.changeset/tame-humans-sleep.md new file mode 100644 index 00000000..38927327 --- /dev/null +++ b/.changeset/tame-humans-sleep.md @@ -0,0 +1,5 @@ +--- +'nxjs-runtime': patch +--- + +Use Promise introspection APIs from updated QuickJS fork diff --git a/source/main.c b/source/main.c index 85d0ae02..60ea400d 100644 --- a/source/main.c +++ b/source/main.c @@ -337,12 +337,12 @@ static JSValue js_env_to_object(JSContext *ctx, JSValueConst this_val, int argc, // Returns the internal state of a Promise instance. static JSValue js_get_internal_promise_state(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { - JSPromiseData *promise_data = JS_GetOpaque(argv[0], JS_CLASS_PROMISE); + JSPromiseStateEnum state = JS_GetPromiseState(ctx, argv[0]); JSValue arr = JS_NewArray(ctx); - JS_SetPropertyUint32(ctx, arr, 0, JS_NewInt32(ctx, promise_data->promise_state)); - if (promise_data->promise_state > 0) + JS_SetPropertyUint32(ctx, arr, 0, JS_NewUint32(ctx, state)); + if (state > JS_PROMISE_PENDING) { - JS_SetPropertyUint32(ctx, arr, 1, promise_data->promise_result); + JS_SetPropertyUint32(ctx, arr, 1, JS_GetPromiseResult(ctx, argv[0])); } else { diff --git a/source/types.h b/source/types.h index 5eda9a4d..db9da256 100644 --- a/source/types.h +++ b/source/types.h @@ -54,30 +54,3 @@ inline nx_context_t *nx_get_context(JSContext *ctx) { return JS_GetContextOpaque(ctx); } - -// DANGER: Internal Promise state from `quickjs.c`. -// Verify that this is still accurate if/when QuickJS -// ever gets updated. -#define JS_CLASS_PROMISE 49 - -struct list_head -{ - struct list_head *prev; - struct list_head *next; -}; - -typedef enum JSPromiseStateEnum -{ - JS_PROMISE_PENDING, - JS_PROMISE_FULFILLED, - JS_PROMISE_REJECTED, -} JSPromiseStateEnum; - -typedef struct JSPromiseData -{ - JSPromiseStateEnum promise_state; - /* 0=fulfill, 1=reject, list of JSPromiseReactionData.link */ - struct list_head promise_reactions[2]; - BOOL is_handled; /* Note: only useful to debug */ - JSValue promise_result; -} JSPromiseData;