Don't share class functions across Set and Map

Map has groupBy and Set doesn't.

Fixes: https://github.com/quickjs-ng/quickjs/issues/714
This commit is contained in:
Saúl Ibarra Corretgé 2024-11-22 08:33:48 +01:00 committed by GitHub
parent 81e50f3cae
commit 4ca6d9bba0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -40204,7 +40204,7 @@ typedef struct JSIteratorHelperData {
JSValue func; // predicate (filter) or mapper (flatMap, map) JSValue func; // predicate (filter) or mapper (flatMap, map)
JSValue inner; // innerValue (flatMap) JSValue inner; // innerValue (flatMap)
int64_t count; // limit (drop, take) or counter (filter, map, flatMap) int64_t count; // limit (drop, take) or counter (filter, map, flatMap)
JSIteratorHelperKindEnum kind : 8; JSIteratorHelperKindEnum kind : 8;
uint8_t executing : 1; uint8_t executing : 1;
uint8_t done : 1; uint8_t done : 1;
} JSIteratorHelperData; } JSIteratorHelperData;
@ -48318,6 +48318,10 @@ static const JSCFunctionListEntry js_map_funcs[] = {
JS_CGETSET_DEF("[Symbol.species]", js_get_this, NULL ), JS_CGETSET_DEF("[Symbol.species]", js_get_this, NULL ),
}; };
static const JSCFunctionListEntry js_set_funcs[] = {
JS_CGETSET_DEF("[Symbol.species]", js_get_this, NULL ),
};
static const JSCFunctionListEntry js_map_proto_funcs[] = { static const JSCFunctionListEntry js_map_proto_funcs[] = {
JS_CFUNC_MAGIC_DEF("set", 2, js_map_set, 0 ), JS_CFUNC_MAGIC_DEF("set", 2, js_map_set, 0 ),
JS_CFUNC_MAGIC_DEF("get", 1, js_map_get, 0 ), JS_CFUNC_MAGIC_DEF("get", 1, js_map_get, 0 ),
@ -48406,17 +48410,19 @@ void JS_AddIntrinsicMapSet(JSContext *ctx)
for(i = 0; i < 4; i++) { for(i = 0; i < 4; i++) {
const char *name = JS_AtomGetStr(ctx, buf, sizeof(buf), const char *name = JS_AtomGetStr(ctx, buf, sizeof(buf),
JS_ATOM_Map + i); JS_ATOM_Map + i);
ctx->class_proto[JS_CLASS_MAP + i] = JS_NewObject(ctx); int class_id = JS_CLASS_MAP + i;
JS_SetPropertyFunctionList(ctx, ctx->class_proto[JS_CLASS_MAP + i], ctx->class_proto[class_id] = JS_NewObject(ctx);
JS_SetPropertyFunctionList(ctx, ctx->class_proto[class_id],
js_map_proto_funcs_ptr[i], js_map_proto_funcs_ptr[i],
js_map_proto_funcs_count[i]); js_map_proto_funcs_count[i]);
obj1 = JS_NewCFunctionMagic(ctx, js_map_constructor, name, 0, obj1 = JS_NewCFunctionMagic(ctx, js_map_constructor, name, 0,
JS_CFUNC_constructor_magic, i); JS_CFUNC_constructor_magic, i);
if (i < 2) { if (class_id == JS_CLASS_MAP)
JS_SetPropertyFunctionList(ctx, obj1, js_map_funcs, JS_SetPropertyFunctionList(ctx, obj1, js_map_funcs, countof(js_map_funcs));
countof(js_map_funcs)); else if (class_id == JS_CLASS_SET)
} JS_SetPropertyFunctionList(ctx, obj1, js_set_funcs, countof(js_set_funcs));
JS_NewGlobalCConstructor2(ctx, obj1, name, ctx->class_proto[JS_CLASS_MAP + i]);
JS_NewGlobalCConstructor2(ctx, obj1, name, ctx->class_proto[class_id]);
} }
for(i = 0; i < 2; i++) { for(i = 0; i < 2; i++) {