Skip to content

Commit 8b009e6

Browse files
committed
Fix crash in JS_NewSymbol when description is NULL
1 parent 3c05198 commit 8b009e6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

quickjs.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3404,6 +3404,15 @@ static JSValue JS_NewSymbolFromAtom(JSContext *ctx, JSAtom descr,
34043404
/* `description` may be pure ASCII or UTF-8 encoded */
34053405
JSValue JS_NewSymbol(JSContext *ctx, const char *description, bool is_global)
34063406
{
3407+
if (description == NULL) {
3408+
if (!is_global) {
3409+
/* Local symbol without description: Symbol() */
3410+
return JS_NewSymbolInternal(ctx, NULL, JS_ATOM_TYPE_SYMBOL);
3411+
}
3412+
/* Global symbol without description: Symbol.for()
3413+
Per ES spec, ToString(undefined) becomes "undefined" */
3414+
description = "undefined";
3415+
}
34073416
JSAtom atom = JS_NewAtom(ctx, description);
34083417
if (atom == JS_ATOM_NULL)
34093418
return JS_EXCEPTION;

0 commit comments

Comments
 (0)