Skip to content

Commit 428204b

Browse files
committed
Align JS_SetOpaque with other similar APIs
Returns < 0 on failure. Also document it in the header file. Fixes: #695
1 parent 18b0b9a commit 428204b

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

quickjs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10096,7 +10096,7 @@ void JS_ResetUncatchableError(JSContext *ctx)
1009610096
JS_SetUncatchableError(ctx, ctx->rt->current_exception, FALSE);
1009710097
}
1009810098

10099-
JS_BOOL JS_SetOpaque(JSValue obj, void *opaque)
10099+
int JS_SetOpaque(JSValue obj, void *opaque)
1010010100
{
1010110101
JSObject *p;
1010210102
if (JS_VALUE_GET_TAG(obj) == JS_TAG_OBJECT) {
@@ -10108,7 +10108,7 @@ JS_BOOL JS_SetOpaque(JSValue obj, void *opaque)
1010810108
}
1010910109
}
1011010110

10111-
return 1;
10111+
return -1;
1011210112
}
1011310113

1011410114
/* |obj| must be a JSObject of an internal class. */

quickjs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,8 @@ JS_EXTERN int JS_DefinePropertyValueStr(JSContext *ctx, JSValue this_obj,
755755
JS_EXTERN int JS_DefinePropertyGetSet(JSContext *ctx, JSValue this_obj,
756756
JSAtom prop, JSValue getter, JSValue setter,
757757
int flags);
758-
JS_EXTERN JS_BOOL JS_SetOpaque(JSValue obj, void *opaque);
758+
/* Only supported for custom classes, returns 0 on success < 0 otherwise. */
759+
JS_EXTERN int JS_SetOpaque(JSValue obj, void *opaque);
759760
JS_EXTERN void *JS_GetOpaque(JSValue obj, JSClassID class_id);
760761
JS_EXTERN void *JS_GetOpaque2(JSContext *ctx, JSValue obj, JSClassID class_id);
761762
JS_EXTERN void *JS_GetAnyOpaque(JSValue obj, JSClassID *class_id);

0 commit comments

Comments
 (0)