Skip to content

Commit 8381245

Browse files
author
Fabrice Bellard
committed
added JS_AtomToCStringLen()
1 parent 2f167bb commit 8381245

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

quickjs.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3205,15 +3205,18 @@ static BOOL JS_AtomSymbolHasDescription(JSContext *ctx, JSAtom v)
32053205
}
32063206

32073207
/* free with JS_FreeCString() */
3208-
const char *JS_AtomToCString(JSContext *ctx, JSAtom atom)
3208+
const char *JS_AtomToCStringLen(JSContext *ctx, size_t *plen, JSAtom atom)
32093209
{
32103210
JSValue str;
32113211
const char *cstr;
32123212

32133213
str = JS_AtomToString(ctx, atom);
3214-
if (JS_IsException(str))
3214+
if (JS_IsException(str)) {
3215+
if (plen)
3216+
*plen = 0;
32153217
return NULL;
3216-
cstr = JS_ToCString(ctx, str);
3218+
}
3219+
cstr = JS_ToCStringLen(ctx, plen, str);
32173220
JS_FreeValue(ctx, str);
32183221
return cstr;
32193222
}

quickjs.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,11 @@ void JS_FreeAtom(JSContext *ctx, JSAtom v);
456456
void JS_FreeAtomRT(JSRuntime *rt, JSAtom v);
457457
JSValue JS_AtomToValue(JSContext *ctx, JSAtom atom);
458458
JSValue JS_AtomToString(JSContext *ctx, JSAtom atom);
459-
const char *JS_AtomToCString(JSContext *ctx, JSAtom atom);
459+
const char *JS_AtomToCStringLen(JSContext *ctx, size_t *plen, JSAtom atom);
460+
static inline const char *JS_AtomToCString(JSContext *ctx, JSAtom atom)
461+
{
462+
return JS_AtomToCStringLen(ctx, NULL, atom);
463+
}
460464
JSAtom JS_ValueToAtom(JSContext *ctx, JSValueConst val);
461465

462466
/* object class support */

0 commit comments

Comments
 (0)