From b9a22f9bdd4d9cd08476e3c64437968efa5b1de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Thu, 24 Oct 2024 16:40:05 +0200 Subject: [PATCH] Implement Iterator.prototype.every --- quickjs.c | 52 +++++++++++++++++++++++++++++++++++++++++++++- test262_errors.txt | 52 ---------------------------------------------- 2 files changed, 51 insertions(+), 53 deletions(-) diff --git a/quickjs.c b/quickjs.c index ce6d85a3..9ac9992c 100644 --- a/quickjs.c +++ b/quickjs.c @@ -39916,7 +39916,57 @@ static JSValue js_iterator_proto_drop(JSContext *ctx, JSValue this_val, static JSValue js_iterator_proto_every(JSContext *ctx, JSValue this_val, int argc, JSValue *argv) { - return JS_ThrowInternalError(ctx, "TODO implement Iterator.prototype.every"); + JSValue item, method, ret, func, index_val, r; + JSValue args[2]; + int64_t idx; + BOOL done; + + if (!JS_IsObject(this_val)) + return JS_ThrowTypeError(ctx, "Iterator.prototype.every called on non-object"); + if (check_function(ctx, argv[0])) + return JS_EXCEPTION; + func = js_dup(argv[0]); + method = JS_GetProperty(ctx, this_val, JS_ATOM_next); + if (JS_IsException(method)) + goto exception; + r = JS_TRUE; + for (idx = 0; /*empty*/; idx++) { + item = JS_IteratorNext(ctx, this_val, method, 0, NULL, &done); + if (JS_IsException(item)) + goto exception; + if (done) + break; + index_val = JS_NewInt64(ctx, idx); + if (JS_IsException(index_val)) { + JS_FreeValue(ctx, item); + goto exception; + } + args[0] = item; + args[1] = index_val; + ret = JS_Call(ctx, func, JS_UNDEFINED, countof(args), args); + JS_FreeValue(ctx, item); + JS_FreeValue(ctx, index_val); + if (JS_IsException(ret)) + goto exception; + if (!JS_ToBoolFree(ctx, ret)) { + if (JS_IteratorClose(ctx, this_val, FALSE) < 0) + r = JS_EXCEPTION; + else + r = JS_FALSE; + break; + } + index_val = JS_UNDEFINED; + ret = JS_UNDEFINED; + item = JS_UNDEFINED; + } + JS_FreeValue(ctx, func); + JS_FreeValue(ctx, method); + return r; +exception: + JS_IteratorClose(ctx, this_val, TRUE); + JS_FreeValue(ctx, func); + JS_FreeValue(ctx, method); + return JS_EXCEPTION; } static JSValue js_iterator_proto_filter(JSContext *ctx, JSValue this_val, diff --git a/test262_errors.txt b/test262_errors.txt index f764e701..e8864ae9 100644 --- a/test262_errors.txt +++ b/test262_errors.txt @@ -78,58 +78,6 @@ test262/test/built-ins/Iterator/prototype/drop/underlying-iterator-closed-in-par test262/test/built-ins/Iterator/prototype/drop/underlying-iterator-closed-in-parallel.js:19: strict mode: InternalError: TODO implement Iterator.prototype.drop test262/test/built-ins/Iterator/prototype/drop/underlying-iterator-closed.js:21: InternalError: TODO implement Iterator.prototype.drop test262/test/built-ins/Iterator/prototype/drop/underlying-iterator-closed.js:21: strict mode: InternalError: TODO implement Iterator.prototype.drop -test262/test/built-ins/Iterator/prototype/every/argument-effect-order.js:16: Test262Error: Expected a TypeError but got a InternalError -test262/test/built-ins/Iterator/prototype/every/argument-effect-order.js:16: strict mode: Test262Error: Expected a TypeError but got a InternalError -test262/test/built-ins/Iterator/prototype/every/callable.js:10: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/callable.js:10: strict mode: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/get-next-method-only-once.js:35: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/get-next-method-only-once.js:35: strict mode: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/get-next-method-throws.js:17: Test262Error: Expected a Test262Error but got a InternalError -test262/test/built-ins/Iterator/prototype/every/get-next-method-throws.js:17: strict mode: Test262Error: Expected a Test262Error but got a InternalError -test262/test/built-ins/Iterator/prototype/every/get-return-method-throws.js:23: Test262Error: Expected a Test262Error but got a InternalError -test262/test/built-ins/Iterator/prototype/every/get-return-method-throws.js:23: strict mode: Test262Error: Expected a Test262Error but got a InternalError -test262/test/built-ins/Iterator/prototype/every/iterator-already-exhausted.js:22: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/iterator-already-exhausted.js:22: strict mode: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/iterator-has-no-return.js:17: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/iterator-has-no-return.js:17: strict mode: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/iterator-return-method-throws.js:23: Test262Error: Expected a Test262Error but got a InternalError -test262/test/built-ins/Iterator/prototype/every/iterator-return-method-throws.js:23: strict mode: Test262Error: Expected a Test262Error but got a InternalError -test262/test/built-ins/Iterator/prototype/every/next-method-returns-non-object.js:23: Test262Error: Expected a TypeError but got a InternalError -test262/test/built-ins/Iterator/prototype/every/next-method-returns-non-object.js:23: strict mode: Test262Error: Expected a TypeError but got a InternalError -test262/test/built-ins/Iterator/prototype/every/next-method-returns-throwing-done.js:19: Test262Error: Expected a Test262Error but got a InternalError -test262/test/built-ins/Iterator/prototype/every/next-method-returns-throwing-done.js:19: strict mode: Test262Error: Expected a Test262Error but got a InternalError -test262/test/built-ins/Iterator/prototype/every/next-method-returns-throwing-value-done.js:30: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/next-method-returns-throwing-value-done.js:30: strict mode: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/next-method-returns-throwing-value.js:20: Test262Error: Expected a Test262Error but got a InternalError -test262/test/built-ins/Iterator/prototype/every/next-method-returns-throwing-value.js:20: strict mode: Test262Error: Expected a Test262Error but got a InternalError -test262/test/built-ins/Iterator/prototype/every/next-method-throws.js:17: Test262Error: Expected a Test262Error but got a InternalError -test262/test/built-ins/Iterator/prototype/every/next-method-throws.js:17: strict mode: Test262Error: Expected a Test262Error but got a InternalError -test262/test/built-ins/Iterator/prototype/every/non-callable-predicate.js:20: Test262Error: Expected a TypeError but got a InternalError -test262/test/built-ins/Iterator/prototype/every/non-callable-predicate.js:20: strict mode: Test262Error: Expected a TypeError but got a InternalError -test262/test/built-ins/Iterator/prototype/every/predicate-args.js:40: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/predicate-args.js:40: strict mode: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/predicate-returns-falsey.js:26: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/predicate-returns-falsey.js:26: strict mode: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/predicate-returns-non-boolean.js:27: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/predicate-returns-non-boolean.js:27: strict mode: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/predicate-returns-truthy-then-falsey.js:27: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/predicate-returns-truthy-then-falsey.js:27: strict mode: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/predicate-returns-truthy.js:23: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/predicate-returns-truthy.js:23: strict mode: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/predicate-this.js:30: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/predicate-this.js:30: strict mode: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/predicate-throws-then-closing-iterator-also-throws.js:33: Test262Error: Expected a Test262Error but got a InternalError -test262/test/built-ins/Iterator/prototype/every/predicate-throws-then-closing-iterator-also-throws.js:33: strict mode: Test262Error: Expected a Test262Error but got a InternalError -test262/test/built-ins/Iterator/prototype/every/predicate-throws.js:35: Test262Error: Expected a Test262Error but got a InternalError -test262/test/built-ins/Iterator/prototype/every/predicate-throws.js:35: strict mode: Test262Error: Expected a Test262Error but got a InternalError -test262/test/built-ins/Iterator/prototype/every/result-is-boolean.js:11: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/result-is-boolean.js:11: strict mode: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/this-non-callable-next.js:15: Test262Error: Expected a TypeError but got a InternalError -test262/test/built-ins/Iterator/prototype/every/this-non-callable-next.js:15: strict mode: Test262Error: Expected a TypeError but got a InternalError -test262/test/built-ins/Iterator/prototype/every/this-non-object.js:21: Test262Error: Expected a TypeError but got a InternalError -test262/test/built-ins/Iterator/prototype/every/this-non-object.js:21: strict mode: Test262Error: Expected a TypeError but got a InternalError -test262/test/built-ins/Iterator/prototype/every/this-plain-iterator.js:29: InternalError: TODO implement Iterator.prototype.every -test262/test/built-ins/Iterator/prototype/every/this-plain-iterator.js:29: strict mode: InternalError: TODO implement Iterator.prototype.every test262/test/built-ins/Iterator/prototype/filter/argument-effect-order.js:16: Test262Error: Expected a TypeError but got a InternalError test262/test/built-ins/Iterator/prototype/filter/argument-effect-order.js:16: strict mode: Test262Error: Expected a TypeError but got a InternalError test262/test/built-ins/Iterator/prototype/filter/callable.js:10: InternalError: TODO implement Iterator.prototype.filter