Skip to content

Commit d168361

Browse files
rockwotjsaghul
authored andcommitted
Add documentation for promise APIs
Signed-off-by: Tyler Rockwood <[email protected]>
1 parent 47e07b2 commit d168361

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

quickjs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45114,7 +45114,7 @@ JSPromiseStateEnum JS_PromiseState(JSContext *ctx, JSValue promise)
4511445114
{
4511545115
JSPromiseData *s = JS_GetOpaque(promise, JS_CLASS_PROMISE);
4511645116
if (!s)
45117-
return -1;
45117+
return JS_INVALID_PROMISE_STATE;
4511845118
return s->promise_state;
4511945119
}
4512045120

quickjs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,13 +977,17 @@ JS_EXTERN int JS_SetModuleExportList(JSContext *ctx, JSModuleDef *m,
977977

978978
/* Promise */
979979

980+
#define JS_INVALID_PROMISE_STATE -1
981+
980982
typedef enum JSPromiseStateEnum {
981983
JS_PROMISE_PENDING,
982984
JS_PROMISE_FULFILLED,
983985
JS_PROMISE_REJECTED,
984986
} JSPromiseStateEnum;
985987

988+
/* Returns JSPromiseReactionEnum for the promise or JS_INVALID_PROMISE_STATE if the value is not a promise. */
986989
JS_EXTERN JSPromiseStateEnum JS_PromiseState(JSContext *ctx, JSValue promise);
990+
/* Return the result of the promise if the promise's state is in the FULFILLED or REJECTED state. Otherwise returns JS_UNDEFINED. */
987991
JS_EXTERN JSValue JS_PromiseResult(JSContext *ctx, JSValue promise);
988992

989993
/* Version */

0 commit comments

Comments
 (0)