Skip to content

Commit 8557bd0

Browse files
authored
Add Set.prototype.isSupersetOf (#532)
1 parent f5c388d commit 8557bd0

File tree

2 files changed

+54
-38
lines changed

2 files changed

+54
-38
lines changed

quickjs.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46518,6 +46518,59 @@ static JSValue js_set_isSubsetOf(JSContext *ctx, JSValue this_val,
4651846518
return rval;
4651946519
}
4652046520

46521+
static JSValue js_set_isSupersetOf(JSContext *ctx, JSValue this_val,
46522+
int argc, JSValue *argv)
46523+
{
46524+
JSValue item, iter, keys, has, next, rval;
46525+
BOOL done, found;
46526+
JSMapState *s;
46527+
int64_t size;
46528+
46529+
has = JS_UNDEFINED;
46530+
iter = JS_UNDEFINED;
46531+
keys = JS_UNDEFINED;
46532+
next = JS_UNDEFINED;
46533+
rval = JS_EXCEPTION;
46534+
s = JS_GetOpaque2(ctx, this_val, JS_CLASS_SET);
46535+
if (!s)
46536+
goto exception;
46537+
// order matters!
46538+
if (js_setlike_get_size(ctx, argv[0], &size) < 0)
46539+
goto exception;
46540+
if (js_setlike_get_has(ctx, argv[0], &has) < 0)
46541+
goto exception;
46542+
if (js_setlike_get_keys(ctx, argv[0], &keys) < 0)
46543+
goto exception;
46544+
found = FALSE;
46545+
if (s->record_count < size)
46546+
goto fini;
46547+
iter = JS_Call(ctx, keys, argv[0], 0, NULL);
46548+
if (JS_IsException(iter))
46549+
goto exception;
46550+
next = JS_GetProperty(ctx, iter, JS_ATOM_next);
46551+
if (JS_IsException(next))
46552+
goto exception;
46553+
found = TRUE;
46554+
do {
46555+
item = JS_IteratorNext(ctx, iter, next, 0, NULL, &done);
46556+
if (JS_IsException(item))
46557+
goto exception;
46558+
if (done) // item is JS_UNDEFINED
46559+
break;
46560+
item = map_normalize_key(ctx, item);
46561+
found = (NULL != map_find_record(ctx, s, item));
46562+
JS_FreeValue(ctx, item);
46563+
} while (found);
46564+
fini:
46565+
rval = found ? JS_TRUE : JS_FALSE;
46566+
exception:
46567+
JS_FreeValue(ctx, has);
46568+
JS_FreeValue(ctx, keys);
46569+
JS_FreeValue(ctx, iter);
46570+
JS_FreeValue(ctx, next);
46571+
return rval;
46572+
}
46573+
4652146574
static JSValue js_set_intersection(JSContext *ctx, JSValue this_val,
4652246575
int argc, JSValue *argv)
4652346576
{
@@ -46896,6 +46949,7 @@ static const JSCFunctionListEntry js_set_proto_funcs[] = {
4689646949
JS_CFUNC_MAGIC_DEF("forEach", 1, js_map_forEach, MAGIC_SET ),
4689746950
JS_CFUNC_DEF("isDisjointFrom", 1, js_set_isDisjointFrom ),
4689846951
JS_CFUNC_DEF("isSubsetOf", 1, js_set_isSubsetOf ),
46952+
JS_CFUNC_DEF("isSupersetOf", 1, js_set_isSupersetOf ),
4689946953
JS_CFUNC_DEF("intersection", 1, js_set_intersection ),
4690046954
JS_CFUNC_DEF("difference", 1, js_set_difference ),
4690146955
JS_CFUNC_DEF("symmetricDifference", 1, js_set_symmetricDifference ),

test262_errors.txt

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -70,44 +70,6 @@ test262/test/built-ins/RegExp/property-escapes/generated/XID_Continue.js:16: Tes
7070
test262/test/built-ins/RegExp/property-escapes/generated/XID_Continue.js:16: strict mode: Test262Error: `\p{XID_Continue}` should match U+00200C (`‌`)
7171
test262/test/built-ins/RegExp/property-escapes/generated/XID_Start.js:16: Test262Error: `\p{XID_Start}` should match U+02EBF0 (`𮯰`)
7272
test262/test/built-ins/RegExp/property-escapes/generated/XID_Start.js:16: strict mode: Test262Error: `\p{XID_Start}` should match U+02EBF0 (`𮯰`)
73-
test262/test/built-ins/Set/prototype/isSupersetOf/allows-set-like-class.js:29: TypeError: not a function
74-
test262/test/built-ins/Set/prototype/isSupersetOf/allows-set-like-class.js:29: strict mode: TypeError: not a function
75-
test262/test/built-ins/Set/prototype/isSupersetOf/allows-set-like-object.js:27: TypeError: not a function
76-
test262/test/built-ins/Set/prototype/isSupersetOf/allows-set-like-object.js:27: strict mode: TypeError: not a function
77-
test262/test/built-ins/Set/prototype/isSupersetOf/builtins.js:9: Test262Error: Built-in objects must be extensible. Expected SameValue(«false», «true») to be true
78-
test262/test/built-ins/Set/prototype/isSupersetOf/builtins.js:9: strict mode: Test262Error: Built-in objects must be extensible. Expected SameValue(«false», «true») to be true
79-
test262/test/built-ins/Set/prototype/isSupersetOf/compares-Map.js:15: TypeError: not a function
80-
test262/test/built-ins/Set/prototype/isSupersetOf/compares-Map.js:15: strict mode: TypeError: not a function
81-
test262/test/built-ins/Set/prototype/isSupersetOf/compares-empty-sets.js:12: TypeError: not a function
82-
test262/test/built-ins/Set/prototype/isSupersetOf/compares-empty-sets.js:12: strict mode: TypeError: not a function
83-
test262/test/built-ins/Set/prototype/isSupersetOf/compares-itself.js:11: TypeError: not a function
84-
test262/test/built-ins/Set/prototype/isSupersetOf/compares-itself.js:11: strict mode: TypeError: not a function
85-
test262/test/built-ins/Set/prototype/isSupersetOf/compares-same-sets.js:12: TypeError: not a function
86-
test262/test/built-ins/Set/prototype/isSupersetOf/compares-same-sets.js:12: strict mode: TypeError: not a function
87-
test262/test/built-ins/Set/prototype/isSupersetOf/compares-sets.js:12: TypeError: not a function
88-
test262/test/built-ins/Set/prototype/isSupersetOf/compares-sets.js:12: strict mode: TypeError: not a function
89-
test262/test/built-ins/Set/prototype/isSupersetOf/converts-negative-zero.js:22: TypeError: not a function
90-
test262/test/built-ins/Set/prototype/isSupersetOf/converts-negative-zero.js:22: strict mode: TypeError: not a function
91-
test262/test/built-ins/Set/prototype/isSupersetOf/isSupersetOf.js:10: Test262Error: `typeof Set.prototype.isSupersetOf` is `'function'` Expected SameValue(«undefined», «function») to be true
92-
test262/test/built-ins/Set/prototype/isSupersetOf/isSupersetOf.js:10: strict mode: Test262Error: `typeof Set.prototype.isSupersetOf` is `'function'` Expected SameValue(«undefined», «function») to be true
93-
test262/test/built-ins/Set/prototype/isSupersetOf/length.js:11: Test262Error: Expected SameValue(«undefined», «function») to be true
94-
test262/test/built-ins/Set/prototype/isSupersetOf/length.js:11: strict mode: Test262Error: Expected SameValue(«undefined», «function») to be true
95-
test262/test/built-ins/Set/prototype/isSupersetOf/name.js:11: Test262Error: Expected SameValue(«undefined», «function») to be true
96-
test262/test/built-ins/Set/prototype/isSupersetOf/name.js:11: strict mode: Test262Error: Expected SameValue(«undefined», «function») to be true
97-
test262/test/built-ins/Set/prototype/isSupersetOf/not-a-constructor.js:17: Test262Error: isConstructor invoked with a non-function value
98-
test262/test/built-ins/Set/prototype/isSupersetOf/not-a-constructor.js:17: strict mode: Test262Error: isConstructor invoked with a non-function value
99-
test262/test/built-ins/Set/prototype/isSupersetOf/require-internal-slot.js:17: Test262Error: Expected SameValue(«undefined», «function») to be true
100-
test262/test/built-ins/Set/prototype/isSupersetOf/require-internal-slot.js:17: strict mode: Test262Error: Expected SameValue(«undefined», «function») to be true
101-
test262/test/built-ins/Set/prototype/isSupersetOf/set-like-array.js:21: TypeError: not a function
102-
test262/test/built-ins/Set/prototype/isSupersetOf/set-like-array.js:21: strict mode: TypeError: not a function
103-
test262/test/built-ins/Set/prototype/isSupersetOf/set-like-class-mutation.js:26: TypeError: not a function
104-
test262/test/built-ins/Set/prototype/isSupersetOf/set-like-class-mutation.js:26: strict mode: TypeError: not a function
105-
test262/test/built-ins/Set/prototype/isSupersetOf/set-like-class-order.js:66: TypeError: not a function
106-
test262/test/built-ins/Set/prototype/isSupersetOf/set-like-class-order.js:66: strict mode: TypeError: not a function
107-
test262/test/built-ins/Set/prototype/isSupersetOf/size-is-a-number.js:24: Test262Error: GetSetRecord coerces size Expected SameValue(«0», «1») to be true
108-
test262/test/built-ins/Set/prototype/isSupersetOf/size-is-a-number.js:24: strict mode: Test262Error: GetSetRecord coerces size Expected SameValue(«0», «1») to be true
109-
test262/test/built-ins/Set/prototype/isSupersetOf/subclass-receiver-methods.js:32: TypeError: not a function
110-
test262/test/built-ins/Set/prototype/isSupersetOf/subclass-receiver-methods.js:32: strict mode: TypeError: not a function
11173
test262/test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-canonical-invalid-index-prototype-chain-set.js:35: Test262Error: value should not be coerced Expected SameValue(«22», «0») to be true
11274
test262/test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-canonical-invalid-index-prototype-chain-set.js:35: strict mode: Test262Error: value should not be coerced Expected SameValue(«22», «0») to be true
11375
test262/test/built-ins/TypedArrayConstructors/internals/Set/BigInt/key-is-canonical-invalid-index-reflect-set.js:35: Test262Error: value should not be coerced Expected SameValue(«32», «0») to be true

0 commit comments

Comments
 (0)