Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3459,15 +3459,18 @@ static __maybe_unused void print_atom(JSContext *ctx, JSAtom atom)
}

/* free with JS_FreeCString() */
const char *JS_AtomToCString(JSContext *ctx, JSAtom atom)
const char *JS_AtomToCStringLen(JSContext *ctx, size_t *plen, JSAtom atom)
{
JSValue str;
const char *cstr;

str = JS_AtomToString(ctx, atom);
if (JS_IsException(str))
if (JS_IsException(str)) {
if (plen)
*plen = 0;
return NULL;
cstr = JS_ToCString(ctx, str);
}
cstr = JS_ToCStringLen(ctx, plen, str);
JS_FreeValue(ctx, str);
return cstr;
}
Expand Down
6 changes: 5 additions & 1 deletion quickjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,11 @@ JS_EXTERN void JS_FreeAtom(JSContext *ctx, JSAtom v);
JS_EXTERN void JS_FreeAtomRT(JSRuntime *rt, JSAtom v);
JS_EXTERN JSValue JS_AtomToValue(JSContext *ctx, JSAtom atom);
JS_EXTERN JSValue JS_AtomToString(JSContext *ctx, JSAtom atom);
JS_EXTERN const char *JS_AtomToCString(JSContext *ctx, JSAtom atom);
JS_EXTERN const char *JS_AtomToCStringLen(JSContext *ctx, size_t *plen, JSAtom atom);
static inline const char *JS_AtomToCString(JSContext *ctx, JSAtom atom)
{
return JS_AtomToCStringLen(ctx, NULL, atom);
}
JS_EXTERN JSAtom JS_ValueToAtom(JSContext *ctx, JSValueConst val);

/* object class support */
Expand Down
Loading