From d168361207f84fa52ff93a3577dfa62d0cc0d86e Mon Sep 17 00:00:00 2001 From: Tyler Rockwood Date: Wed, 21 Feb 2024 11:47:59 -0600 Subject: [PATCH] Add documentation for promise APIs Signed-off-by: Tyler Rockwood --- quickjs.c | 2 +- quickjs.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/quickjs.c b/quickjs.c index f0372eb..bce0fd6 100644 --- a/quickjs.c +++ b/quickjs.c @@ -45114,7 +45114,7 @@ JSPromiseStateEnum JS_PromiseState(JSContext *ctx, JSValue promise) { JSPromiseData *s = JS_GetOpaque(promise, JS_CLASS_PROMISE); if (!s) - return -1; + return JS_INVALID_PROMISE_STATE; return s->promise_state; } diff --git a/quickjs.h b/quickjs.h index 453e03d..96414c8 100644 --- a/quickjs.h +++ b/quickjs.h @@ -977,13 +977,17 @@ JS_EXTERN int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m, /* Promise */ +#define JS_INVALID_PROMISE_STATE -1 + typedef enum JSPromiseStateEnum { JS_PROMISE_PENDING, JS_PROMISE_FULFILLED, JS_PROMISE_REJECTED, } JSPromiseStateEnum; +/* Returns JSPromiseReactionEnum for the promise or JS_INVALID_PROMISE_STATE if the value is not a promise. */ JS_EXTERN JSPromiseStateEnum JS_PromiseState(JSContext *ctx, JSValue promise); +/* Return the result of the promise if the promise's state is in the FULFILLED or REJECTED state. Otherwise returns JS_UNDEFINED. */ JS_EXTERN JSValue JS_PromiseResult(JSContext *ctx, JSValue promise); /* Version */