Skip to content

Commit 12940d7

Browse files
authored
Add Set.prototype.isDisjointFrom (#528)
1 parent fb70e09 commit 12940d7

File tree

2 files changed

+71
-38
lines changed

2 files changed

+71
-38
lines changed

quickjs.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46292,6 +46292,76 @@ static int js_setlike_get_keys(JSContext *ctx, JSValue setlike, JSValue *pout)
4629246292
return 0;
4629346293
}
4629446294

46295+
static JSValue js_set_isDisjointFrom(JSContext *ctx, JSValue this_val,
46296+
int argc, JSValue *argv)
46297+
{
46298+
JSValue item, iter, keys, has, next, rv, rval;
46299+
BOOL done, found;
46300+
JSMapState *s;
46301+
int64_t size;
46302+
int ok;
46303+
46304+
has = JS_UNDEFINED;
46305+
iter = JS_UNDEFINED;
46306+
keys = JS_UNDEFINED;
46307+
next = JS_UNDEFINED;
46308+
rval = JS_EXCEPTION;
46309+
s = JS_GetOpaque2(ctx, this_val, JS_CLASS_SET);
46310+
if (!s)
46311+
goto exception;
46312+
// order matters!
46313+
if (js_setlike_get_size(ctx, argv[0], &size) < 0)
46314+
goto exception;
46315+
if (js_setlike_get_has(ctx, argv[0], &has) < 0)
46316+
goto exception;
46317+
if (js_setlike_get_keys(ctx, argv[0], &keys) < 0)
46318+
goto exception;
46319+
if (s->record_count > size) {
46320+
iter = JS_Call(ctx, keys, argv[0], 0, NULL);
46321+
if (JS_IsException(iter))
46322+
goto exception;
46323+
next = JS_GetProperty(ctx, iter, JS_ATOM_next);
46324+
if (JS_IsException(next))
46325+
goto exception;
46326+
found = FALSE;
46327+
do {
46328+
item = JS_IteratorNext(ctx, iter, next, 0, NULL, &done);
46329+
if (JS_IsException(item))
46330+
goto exception;
46331+
if (done) // item is JS_UNDEFINED
46332+
break;
46333+
item = map_normalize_key(ctx, item);
46334+
found = (NULL != map_find_record(ctx, s, item));
46335+
JS_FreeValue(ctx, item);
46336+
} while (!found);
46337+
} else {
46338+
iter = js_create_map_iterator(ctx, this_val, 0, NULL, MAGIC_SET);
46339+
if (JS_IsException(iter))
46340+
goto exception;
46341+
found = FALSE;
46342+
do {
46343+
item = js_map_iterator_next(ctx, iter, 0, NULL, &done, MAGIC_SET);
46344+
if (JS_IsException(item))
46345+
goto exception;
46346+
if (done) // item is JS_UNDEFINED
46347+
break;
46348+
rv = JS_Call(ctx, has, argv[0], 1, &item);
46349+
JS_FreeValue(ctx, item);
46350+
ok = JS_ToBoolFree(ctx, rv); // returns -1 if rv is JS_EXCEPTION
46351+
if (ok < 0)
46352+
goto exception;
46353+
found = (ok > 0);
46354+
} while (!found);
46355+
}
46356+
rval = !found ? JS_TRUE : JS_FALSE;
46357+
exception:
46358+
JS_FreeValue(ctx, has);
46359+
JS_FreeValue(ctx, keys);
46360+
JS_FreeValue(ctx, iter);
46361+
JS_FreeValue(ctx, next);
46362+
return rval;
46363+
}
46364+
4629546365
static JSValue js_set_intersection(JSContext *ctx, JSValue this_val,
4629646366
int argc, JSValue *argv)
4629746367
{
@@ -46668,6 +46738,7 @@ static const JSCFunctionListEntry js_set_proto_funcs[] = {
4666846738
JS_CFUNC_MAGIC_DEF("clear", 0, js_map_clear, MAGIC_SET ),
4666946739
JS_CGETSET_MAGIC_DEF("size", js_map_get_size, NULL, MAGIC_SET ),
4667046740
JS_CFUNC_MAGIC_DEF("forEach", 1, js_map_forEach, MAGIC_SET ),
46741+
JS_CFUNC_DEF("isDisjointFrom", 1, js_set_isDisjointFrom ),
4667146742
JS_CFUNC_DEF("intersection", 1, js_set_intersection ),
4667246743
JS_CFUNC_DEF("difference", 1, js_set_difference ),
4667346744
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
@@ -72,44 +72,6 @@ test262/test/built-ins/RegExp/property-escapes/generated/XID_Start.js:16: Test26
7272
test262/test/built-ins/RegExp/property-escapes/generated/XID_Start.js:16: strict mode: Test262Error: `\p{XID_Start}` should match U+02EBF0 (`𮯰`)
7373
test262/test/built-ins/RegExp/unicode_full_case_folding.js:20: Test262Error: \u0390 does not match \u1fd3
7474
test262/test/built-ins/RegExp/unicode_full_case_folding.js:20: strict mode: Test262Error: \u0390 does not match \u1fd3
75-
test262/test/built-ins/Set/prototype/isDisjointFrom/allows-set-like-class.js:30: TypeError: not a function
76-
test262/test/built-ins/Set/prototype/isDisjointFrom/allows-set-like-class.js:30: strict mode: TypeError: not a function
77-
test262/test/built-ins/Set/prototype/isDisjointFrom/allows-set-like-object.js:28: TypeError: not a function
78-
test262/test/built-ins/Set/prototype/isDisjointFrom/allows-set-like-object.js:28: strict mode: TypeError: not a function
79-
test262/test/built-ins/Set/prototype/isDisjointFrom/builtins.js:9: Test262Error: Built-in objects must be extensible. Expected SameValue(«false», «true») to be true
80-
test262/test/built-ins/Set/prototype/isDisjointFrom/builtins.js:9: strict mode: Test262Error: Built-in objects must be extensible. Expected SameValue(«false», «true») to be true
81-
test262/test/built-ins/Set/prototype/isDisjointFrom/compares-Map.js:15: TypeError: not a function
82-
test262/test/built-ins/Set/prototype/isDisjointFrom/compares-Map.js:15: strict mode: TypeError: not a function
83-
test262/test/built-ins/Set/prototype/isDisjointFrom/compares-empty-sets.js:12: TypeError: not a function
84-
test262/test/built-ins/Set/prototype/isDisjointFrom/compares-empty-sets.js:12: strict mode: TypeError: not a function
85-
test262/test/built-ins/Set/prototype/isDisjointFrom/compares-itself.js:11: TypeError: not a function
86-
test262/test/built-ins/Set/prototype/isDisjointFrom/compares-itself.js:11: strict mode: TypeError: not a function
87-
test262/test/built-ins/Set/prototype/isDisjointFrom/compares-same-sets.js:12: TypeError: not a function
88-
test262/test/built-ins/Set/prototype/isDisjointFrom/compares-same-sets.js:12: strict mode: TypeError: not a function
89-
test262/test/built-ins/Set/prototype/isDisjointFrom/compares-sets.js:12: TypeError: not a function
90-
test262/test/built-ins/Set/prototype/isDisjointFrom/compares-sets.js:12: strict mode: TypeError: not a function
91-
test262/test/built-ins/Set/prototype/isDisjointFrom/converts-negative-zero.js:22: TypeError: not a function
92-
test262/test/built-ins/Set/prototype/isDisjointFrom/converts-negative-zero.js:22: strict mode: TypeError: not a function
93-
test262/test/built-ins/Set/prototype/isDisjointFrom/isDisjointFrom.js:10: Test262Error: `typeof Set.prototype.isDisjointFrom` is `'function'` Expected SameValue(«undefined», «function») to be true
94-
test262/test/built-ins/Set/prototype/isDisjointFrom/isDisjointFrom.js:10: strict mode: Test262Error: `typeof Set.prototype.isDisjointFrom` is `'function'` Expected SameValue(«undefined», «function») to be true
95-
test262/test/built-ins/Set/prototype/isDisjointFrom/length.js:11: Test262Error: Expected SameValue(«undefined», «function») to be true
96-
test262/test/built-ins/Set/prototype/isDisjointFrom/length.js:11: strict mode: Test262Error: Expected SameValue(«undefined», «function») to be true
97-
test262/test/built-ins/Set/prototype/isDisjointFrom/name.js:11: Test262Error: Expected SameValue(«undefined», «function») to be true
98-
test262/test/built-ins/Set/prototype/isDisjointFrom/name.js:11: strict mode: Test262Error: Expected SameValue(«undefined», «function») to be true
99-
test262/test/built-ins/Set/prototype/isDisjointFrom/not-a-constructor.js:17: Test262Error: isConstructor invoked with a non-function value
100-
test262/test/built-ins/Set/prototype/isDisjointFrom/not-a-constructor.js:17: strict mode: Test262Error: isConstructor invoked with a non-function value
101-
test262/test/built-ins/Set/prototype/isDisjointFrom/require-internal-slot.js:17: Test262Error: Expected SameValue(«undefined», «function») to be true
102-
test262/test/built-ins/Set/prototype/isDisjointFrom/require-internal-slot.js:17: strict mode: Test262Error: Expected SameValue(«undefined», «function») to be true
103-
test262/test/built-ins/Set/prototype/isDisjointFrom/set-like-array.js:20: TypeError: not a function
104-
test262/test/built-ins/Set/prototype/isDisjointFrom/set-like-array.js:20: strict mode: TypeError: not a function
105-
test262/test/built-ins/Set/prototype/isDisjointFrom/set-like-class-mutation.js:34: TypeError: not a function
106-
test262/test/built-ins/Set/prototype/isDisjointFrom/set-like-class-mutation.js:34: strict mode: TypeError: not a function
107-
test262/test/built-ins/Set/prototype/isDisjointFrom/set-like-class-order.js:67: TypeError: not a function
108-
test262/test/built-ins/Set/prototype/isDisjointFrom/set-like-class-order.js:67: strict mode: TypeError: not a function
109-
test262/test/built-ins/Set/prototype/isDisjointFrom/size-is-a-number.js:24: Test262Error: GetSetRecord coerces size Expected SameValue(«0», «1») to be true
110-
test262/test/built-ins/Set/prototype/isDisjointFrom/size-is-a-number.js:24: strict mode: Test262Error: GetSetRecord coerces size Expected SameValue(«0», «1») to be true
111-
test262/test/built-ins/Set/prototype/isDisjointFrom/subclass-receiver-methods.js:32: TypeError: not a function
112-
test262/test/built-ins/Set/prototype/isDisjointFrom/subclass-receiver-methods.js:32: strict mode: TypeError: not a function
11375
test262/test/built-ins/Set/prototype/isSubsetOf/allows-set-like-class.js:31: TypeError: not a function
11476
test262/test/built-ins/Set/prototype/isSubsetOf/allows-set-like-class.js:31: strict mode: TypeError: not a function
11577
test262/test/built-ins/Set/prototype/isSubsetOf/allows-set-like-object.js:29: TypeError: not a function

0 commit comments

Comments
 (0)