Skip to content

Commit 109e541

Browse files
committed
Add Symbol key support to WeakMap
1 parent 7926755 commit 109e541

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

quickjs.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -43650,8 +43650,14 @@ static JSValue js_map_set(JSContext *ctx, JSValueConst this_val,
4365043650
if (!s)
4365143651
return JS_EXCEPTION;
4365243652
key = map_normalize_key(ctx, argv[0]);
43653-
if (s->is_weak && !JS_IsObject(key))
43654-
return JS_ThrowTypeErrorNotAnObject(ctx);
43653+
if (s->is_weak) {
43654+
if (magic & MAGIC_SET) {
43655+
if (!JS_IsObject(key))
43656+
return JS_ThrowTypeErrorNotAnObject(ctx);
43657+
} else if (!JS_IsObject(key) && !JS_IsSymbol(key)) {
43658+
return JS_ThrowTypeError(ctx, "key must be Objecty or Symbol");
43659+
}
43660+
}
4365543661
if (magic & MAGIC_SET)
4365643662
value = JS_UNDEFINED;
4365743663
else

0 commit comments

Comments
 (0)