Skip to content

Commit

Permalink
Add Set.prototype.isSubsetOf (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis authored Sep 13, 2024
1 parent 9bb8a68 commit 0990875
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 42 deletions.
55 changes: 55 additions & 0 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -46362,6 +46362,60 @@ static JSValue js_set_isDisjointFrom(JSContext *ctx, JSValue this_val,
return rval;
}

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

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_create_map_iterator(ctx, this_val, 0, NULL, MAGIC_SET);
if (JS_IsException(iter))
goto exception;
found = TRUE;
do {
item = js_map_iterator_next(ctx, iter, 0, NULL, &done, MAGIC_SET);
if (JS_IsException(item))
goto exception;
if (done) // item is JS_UNDEFINED
break;
rv = JS_Call(ctx, has, argv[0], 1, &item);
JS_FreeValue(ctx, item);
ok = JS_ToBoolFree(ctx, rv); // returns -1 if rv is JS_EXCEPTION
if (ok < 0)
goto exception;
found = (ok > 0);
} 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 @@ -46739,6 +46793,7 @@ static const JSCFunctionListEntry js_set_proto_funcs[] = {
JS_CGETSET_MAGIC_DEF("size", js_map_get_size, NULL, MAGIC_SET ),
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("intersection", 1, js_set_intersection ),
JS_CFUNC_DEF("difference", 1, js_set_difference ),
JS_CFUNC_DEF("symmetricDifference", 1, js_set_symmetricDifference ),
Expand Down
42 changes: 0 additions & 42 deletions test262_errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,42 +72,6 @@ test262/test/built-ins/RegExp/property-escapes/generated/XID_Start.js:16: Test26
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/RegExp/unicode_full_case_folding.js:20: Test262Error: \u0390 does not match \u1fd3
test262/test/built-ins/RegExp/unicode_full_case_folding.js:20: strict mode: Test262Error: \u0390 does not match \u1fd3
test262/test/built-ins/Set/prototype/isSubsetOf/allows-set-like-class.js:31: TypeError: not a function
test262/test/built-ins/Set/prototype/isSubsetOf/allows-set-like-class.js:31: strict mode: TypeError: not a function
test262/test/built-ins/Set/prototype/isSubsetOf/allows-set-like-object.js:29: TypeError: not a function
test262/test/built-ins/Set/prototype/isSubsetOf/allows-set-like-object.js:29: strict mode: TypeError: not a function
test262/test/built-ins/Set/prototype/isSubsetOf/builtins.js:9: Test262Error: Built-in objects must be extensible. Expected SameValue(«false», «true») to be true
test262/test/built-ins/Set/prototype/isSubsetOf/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/isSubsetOf/compares-Map.js:15: TypeError: not a function
test262/test/built-ins/Set/prototype/isSubsetOf/compares-Map.js:15: strict mode: TypeError: not a function
test262/test/built-ins/Set/prototype/isSubsetOf/compares-empty-sets.js:12: TypeError: not a function
test262/test/built-ins/Set/prototype/isSubsetOf/compares-empty-sets.js:12: strict mode: TypeError: not a function
test262/test/built-ins/Set/prototype/isSubsetOf/compares-itself.js:11: TypeError: not a function
test262/test/built-ins/Set/prototype/isSubsetOf/compares-itself.js:11: strict mode: TypeError: not a function
test262/test/built-ins/Set/prototype/isSubsetOf/compares-same-sets.js:12: TypeError: not a function
test262/test/built-ins/Set/prototype/isSubsetOf/compares-same-sets.js:12: strict mode: TypeError: not a function
test262/test/built-ins/Set/prototype/isSubsetOf/compares-sets.js:12: TypeError: not a function
test262/test/built-ins/Set/prototype/isSubsetOf/compares-sets.js:12: strict mode: TypeError: not a function
test262/test/built-ins/Set/prototype/isSubsetOf/isSubsetOf.js:10: Test262Error: `typeof Set.prototype.isSubsetOf` is `'function'` Expected SameValue(«undefined», «function») to be true
test262/test/built-ins/Set/prototype/isSubsetOf/isSubsetOf.js:10: strict mode: Test262Error: `typeof Set.prototype.isSubsetOf` is `'function'` Expected SameValue(«undefined», «function») to be true
test262/test/built-ins/Set/prototype/isSubsetOf/length.js:11: Test262Error: Expected SameValue(«undefined», «function») to be true
test262/test/built-ins/Set/prototype/isSubsetOf/length.js:11: strict mode: Test262Error: Expected SameValue(«undefined», «function») to be true
test262/test/built-ins/Set/prototype/isSubsetOf/name.js:11: Test262Error: Expected SameValue(«undefined», «function») to be true
test262/test/built-ins/Set/prototype/isSubsetOf/name.js:11: strict mode: Test262Error: Expected SameValue(«undefined», «function») to be true
test262/test/built-ins/Set/prototype/isSubsetOf/not-a-constructor.js:17: Test262Error: isConstructor invoked with a non-function value
test262/test/built-ins/Set/prototype/isSubsetOf/not-a-constructor.js:17: strict mode: Test262Error: isConstructor invoked with a non-function value
test262/test/built-ins/Set/prototype/isSubsetOf/require-internal-slot.js:17: Test262Error: Expected SameValue(«undefined», «function») to be true
test262/test/built-ins/Set/prototype/isSubsetOf/require-internal-slot.js:17: strict mode: Test262Error: Expected SameValue(«undefined», «function») to be true
test262/test/built-ins/Set/prototype/isSubsetOf/set-like-array.js:21: TypeError: not a function
test262/test/built-ins/Set/prototype/isSubsetOf/set-like-array.js:21: strict mode: TypeError: not a function
test262/test/built-ins/Set/prototype/isSubsetOf/set-like-class-mutation.js:25: TypeError: not a function
test262/test/built-ins/Set/prototype/isSubsetOf/set-like-class-mutation.js:25: strict mode: TypeError: not a function
test262/test/built-ins/Set/prototype/isSubsetOf/set-like-class-order.js:43: TypeError: not a function
test262/test/built-ins/Set/prototype/isSubsetOf/set-like-class-order.js:43: strict mode: TypeError: not a function
test262/test/built-ins/Set/prototype/isSubsetOf/size-is-a-number.js:24: Test262Error: GetSetRecord coerces size Expected SameValue(«0», «1») to be true
test262/test/built-ins/Set/prototype/isSubsetOf/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/isSubsetOf/subclass-receiver-methods.js:32: TypeError: not a function
test262/test/built-ins/Set/prototype/isSubsetOf/subclass-receiver-methods.js:32: strict mode: TypeError: not a function
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
Expand Down Expand Up @@ -173,10 +137,4 @@ test262/test/language/expressions/member-expression/computed-reference-null-or-u
test262/test/language/expressions/optional-chaining/optional-call-preserves-this.js:21: TypeError: cannot read property 'c' of undefined
test262/test/language/expressions/optional-chaining/optional-call-preserves-this.js:16: strict mode: TypeError: cannot read property '_b' of undefined
test262/test/language/module-code/top-level-await/async-module-does-not-block-sibling-modules.js:13: SyntaxError: Could not find export 'check' in module 'test262/test/language/module-code/top-level-await/async-module-sync_FIXTURE.js'
test262/test/staging/set-is-subset-on-set-like.js:24: TypeError: not a function
test262/test/staging/set-is-subset-on-set-like.js:24: strict mode: TypeError: not a function
test262/test/staging/set-is-subset-table-receiver-cleared.js:25: TypeError: not a function
test262/test/staging/set-is-subset-table-receiver-cleared.js:25: strict mode: TypeError: not a function
test262/test/staging/set-is-subset-table-transition.js:28: TypeError: not a function
test262/test/staging/set-is-subset-table-transition.js:28: strict mode: TypeError: not a function
test262/test/staging/top-level-await/tla-hang-entry.js:10: TypeError: $DONE() not called

0 comments on commit 0990875

Please sign in to comment.