Skip to content

Commit

Permalink
Use Promise introspection APIs from updated QuickJS fork
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Oct 6, 2023
1 parent 21b4414 commit a7c23d7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 31 deletions.
5 changes: 5 additions & 0 deletions .changeset/tame-humans-sleep.md
@@ -0,0 +1,5 @@
---
'nxjs-runtime': patch
---

Use Promise introspection APIs from updated QuickJS fork
8 changes: 4 additions & 4 deletions source/main.c
Expand Up @@ -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
{
Expand Down
27 changes: 0 additions & 27 deletions source/types.h
Expand Up @@ -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;

0 comments on commit a7c23d7

Please sign in to comment.