Skip to content

Commit

Permalink
Add Set.prototype.isSupersetOf (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis authored Sep 13, 2024
1 parent f5c388d commit 8557bd0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 38 deletions.
54 changes: 54 additions & 0 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -46518,6 +46518,59 @@ static JSValue js_set_isSubsetOf(JSContext *ctx, JSValue this_val,
return rval;
}

static JSValue js_set_isSupersetOf(JSContext *ctx, JSValue this_val,
int argc, JSValue *argv)
{
JSValue item, iter, keys, has, next, rval;
BOOL done, found;
JSMapState *s;
int64_t size;

has = JS_UNDEFINED;
iter = JS_UNDEFINED;
keys = JS_UNDEFINED;
next = JS_UNDEFINED;
rval = JS_EXCEPTION;
s = JS_GetOpaque2(ctx, this_val, JS_CLASS_SET);
if (!s)
goto exception;
// order matters!
if (js_setlike_get_size(ctx, argv[0], &size) < 0)
goto exception;
if (js_setlike_get_has(ctx, argv[0], &has) < 0)
goto exception;
if (js_setlike_get_keys(ctx, argv[0], &keys) < 0)
goto exception;
found = FALSE;
if (s->record_count < size)
goto fini;
iter = JS_Call(ctx, keys, argv[0], 0, NULL);
if (JS_IsException(iter))
goto exception;
next = JS_GetProperty(ctx, iter, JS_ATOM_next);
if (JS_IsException(next))
goto exception;
found = TRUE;
do {
item = JS_IteratorNext(ctx, iter, next, 0, NULL, &done);
if (JS_IsException(item))
goto exception;
if (done) // item is JS_UNDEFINED
break;
item = map_normalize_key(ctx, item);
found = (NULL != map_find_record(ctx, s, item));
JS_FreeValue(ctx, item);
} while (found);
fini:
rval = found ? JS_TRUE : JS_FALSE;
exception:
JS_FreeValue(ctx, has);
JS_FreeValue(ctx, keys);
JS_FreeValue(ctx, iter);
JS_FreeValue(ctx, next);
return rval;
}

static JSValue js_set_intersection(JSContext *ctx, JSValue this_val,
int argc, JSValue *argv)
{
Expand Down Expand Up @@ -46896,6 +46949,7 @@ static const JSCFunctionListEntry js_set_proto_funcs[] = {
JS_CFUNC_MAGIC_DEF("forEach", 1, js_map_forEach, MAGIC_SET ),
JS_CFUNC_DEF("isDisjointFrom", 1, js_set_isDisjointFrom ),
JS_CFUNC_DEF("isSubsetOf", 1, js_set_isSubsetOf ),
JS_CFUNC_DEF("isSupersetOf", 1, js_set_isSupersetOf ),
JS_CFUNC_DEF("intersection", 1, js_set_intersection ),
JS_CFUNC_DEF("difference", 1, js_set_difference ),
JS_CFUNC_DEF("symmetricDifference", 1, js_set_symmetricDifference ),
Expand Down
38 changes: 0 additions & 38 deletions test262_errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,44 +70,6 @@ test262/test/built-ins/RegExp/property-escapes/generated/XID_Continue.js:16: Tes
test262/test/built-ins/RegExp/property-escapes/generated/XID_Continue.js:16: strict mode: Test262Error: `\p{XID_Continue}` should match U+00200C (`‌`)
test262/test/built-ins/RegExp/property-escapes/generated/XID_Start.js:16: Test262Error: `\p{XID_Start}` should match U+02EBF0 (`𮯰`)
test262/test/built-ins/RegExp/property-escapes/generated/XID_Start.js:16: strict mode: Test262Error: `\p{XID_Start}` should match U+02EBF0 (`𮯰`)
test262/test/built-ins/Set/prototype/isSupersetOf/allows-set-like-class.js:29: TypeError: not a function
test262/test/built-ins/Set/prototype/isSupersetOf/allows-set-like-class.js:29: strict mode: TypeError: not a function
test262/test/built-ins/Set/prototype/isSupersetOf/allows-set-like-object.js:27: TypeError: not a function
test262/test/built-ins/Set/prototype/isSupersetOf/allows-set-like-object.js:27: strict mode: TypeError: not a function
test262/test/built-ins/Set/prototype/isSupersetOf/builtins.js:9: Test262Error: Built-in objects must be extensible. Expected SameValue(«false», «true») to be true
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
test262/test/built-ins/Set/prototype/isSupersetOf/compares-Map.js:15: TypeError: not a function
test262/test/built-ins/Set/prototype/isSupersetOf/compares-Map.js:15: strict mode: TypeError: not a function
test262/test/built-ins/Set/prototype/isSupersetOf/compares-empty-sets.js:12: TypeError: not a function
test262/test/built-ins/Set/prototype/isSupersetOf/compares-empty-sets.js:12: strict mode: TypeError: not a function
test262/test/built-ins/Set/prototype/isSupersetOf/compares-itself.js:11: TypeError: not a function
test262/test/built-ins/Set/prototype/isSupersetOf/compares-itself.js:11: strict mode: TypeError: not a function
test262/test/built-ins/Set/prototype/isSupersetOf/compares-same-sets.js:12: TypeError: not a function
test262/test/built-ins/Set/prototype/isSupersetOf/compares-same-sets.js:12: strict mode: TypeError: not a function
test262/test/built-ins/Set/prototype/isSupersetOf/compares-sets.js:12: TypeError: not a function
test262/test/built-ins/Set/prototype/isSupersetOf/compares-sets.js:12: strict mode: TypeError: not a function
test262/test/built-ins/Set/prototype/isSupersetOf/converts-negative-zero.js:22: TypeError: not a function
test262/test/built-ins/Set/prototype/isSupersetOf/converts-negative-zero.js:22: strict mode: TypeError: not a function
test262/test/built-ins/Set/prototype/isSupersetOf/isSupersetOf.js:10: Test262Error: `typeof Set.prototype.isSupersetOf` is `'function'` Expected SameValue(«undefined», «function») to be true
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
test262/test/built-ins/Set/prototype/isSupersetOf/length.js:11: Test262Error: Expected SameValue(«undefined», «function») to be true
test262/test/built-ins/Set/prototype/isSupersetOf/length.js:11: strict mode: Test262Error: Expected SameValue(«undefined», «function») to be true
test262/test/built-ins/Set/prototype/isSupersetOf/name.js:11: Test262Error: Expected SameValue(«undefined», «function») to be true
test262/test/built-ins/Set/prototype/isSupersetOf/name.js:11: strict mode: Test262Error: Expected SameValue(«undefined», «function») to be true
test262/test/built-ins/Set/prototype/isSupersetOf/not-a-constructor.js:17: Test262Error: isConstructor invoked with a non-function value
test262/test/built-ins/Set/prototype/isSupersetOf/not-a-constructor.js:17: strict mode: Test262Error: isConstructor invoked with a non-function value
test262/test/built-ins/Set/prototype/isSupersetOf/require-internal-slot.js:17: Test262Error: Expected SameValue(«undefined», «function») to be true
test262/test/built-ins/Set/prototype/isSupersetOf/require-internal-slot.js:17: strict mode: Test262Error: Expected SameValue(«undefined», «function») to be true
test262/test/built-ins/Set/prototype/isSupersetOf/set-like-array.js:21: TypeError: not a function
test262/test/built-ins/Set/prototype/isSupersetOf/set-like-array.js:21: strict mode: TypeError: not a function
test262/test/built-ins/Set/prototype/isSupersetOf/set-like-class-mutation.js:26: TypeError: not a function
test262/test/built-ins/Set/prototype/isSupersetOf/set-like-class-mutation.js:26: strict mode: TypeError: not a function
test262/test/built-ins/Set/prototype/isSupersetOf/set-like-class-order.js:66: TypeError: not a function
test262/test/built-ins/Set/prototype/isSupersetOf/set-like-class-order.js:66: strict mode: TypeError: not a function
test262/test/built-ins/Set/prototype/isSupersetOf/size-is-a-number.js:24: Test262Error: GetSetRecord coerces size Expected SameValue(«0», «1») to be true
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
test262/test/built-ins/Set/prototype/isSupersetOf/subclass-receiver-methods.js:32: TypeError: not a function
test262/test/built-ins/Set/prototype/isSupersetOf/subclass-receiver-methods.js:32: strict mode: TypeError: not a function
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
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
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
Expand Down

0 comments on commit 8557bd0

Please sign in to comment.