From 8557bd0a0a051d52d15a467a25b99bdc155d09a7 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sat, 14 Sep 2024 00:19:20 +0200 Subject: [PATCH] Add Set.prototype.isSupersetOf (#532) --- quickjs.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++ test262_errors.txt | 38 -------------------------------- 2 files changed, 54 insertions(+), 38 deletions(-) diff --git a/quickjs.c b/quickjs.c index 8eec8c0..c956460 100644 --- a/quickjs.c +++ b/quickjs.c @@ -46518,6 +46518,59 @@ exception: 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) { @@ -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 ), diff --git a/test262_errors.txt b/test262_errors.txt index 91ef5e4..930d217 100644 --- a/test262_errors.txt +++ b/test262_errors.txt @@ -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