mirror of
https://github.com/DoneJS-Runtime/quickjs-done-nextgen.git
synced 2025-01-09 17:43:15 +00:00
Implement Iterator.prototype.forEach
This commit is contained in:
parent
b9a22f9bdd
commit
3339ef7137
2 changed files with 44 additions and 41 deletions
45
quickjs.c
45
quickjs.c
|
@ -39990,7 +39990,50 @@ static JSValue js_iterator_proto_flatMap(JSContext *ctx, JSValue this_val,
|
|||
static JSValue js_iterator_proto_forEach(JSContext *ctx, JSValue this_val,
|
||||
int argc, JSValue *argv)
|
||||
{
|
||||
return JS_ThrowInternalError(ctx, "TODO implement Iterator.prototype.forEach");
|
||||
JSValue item, method, ret, func, index_val;
|
||||
JSValue args[2];
|
||||
int64_t idx;
|
||||
BOOL done;
|
||||
|
||||
if (!JS_IsObject(this_val))
|
||||
return JS_ThrowTypeError(ctx, "Iterator.prototype.forEach 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;
|
||||
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;
|
||||
JS_FreeValue(ctx, ret);
|
||||
index_val = JS_UNDEFINED;
|
||||
ret = JS_UNDEFINED;
|
||||
item = JS_UNDEFINED;
|
||||
}
|
||||
JS_FreeValue(ctx, func);
|
||||
JS_FreeValue(ctx, method);
|
||||
return JS_UNDEFINED;
|
||||
exception:
|
||||
JS_IteratorClose(ctx, this_val, TRUE);
|
||||
JS_FreeValue(ctx, func);
|
||||
JS_FreeValue(ctx, method);
|
||||
return JS_EXCEPTION;
|
||||
}
|
||||
|
||||
static JSValue js_iterator_proto_map(JSContext *ctx, JSValue this_val,
|
||||
|
|
|
@ -262,46 +262,6 @@ test262/test/built-ins/Iterator/prototype/flatMap/underlying-iterator-closed-in-
|
|||
test262/test/built-ins/Iterator/prototype/flatMap/underlying-iterator-closed-in-parallel.js:19: strict mode: InternalError: TODO implement Iterator.prototype.flatMap
|
||||
test262/test/built-ins/Iterator/prototype/flatMap/underlying-iterator-closed.js:21: InternalError: TODO implement Iterator.prototype.flatMap
|
||||
test262/test/built-ins/Iterator/prototype/flatMap/underlying-iterator-closed.js:21: strict mode: InternalError: TODO implement Iterator.prototype.flatMap
|
||||
test262/test/built-ins/Iterator/prototype/forEach/argument-effect-order.js:21: Test262Error: Expected a TypeError but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/forEach/argument-effect-order.js:21: strict mode: Test262Error: Expected a TypeError but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/forEach/callable.js:10: InternalError: TODO implement Iterator.prototype.forEach
|
||||
test262/test/built-ins/Iterator/prototype/forEach/callable.js:10: strict mode: InternalError: TODO implement Iterator.prototype.forEach
|
||||
test262/test/built-ins/Iterator/prototype/forEach/fn-args.js:37: InternalError: TODO implement Iterator.prototype.forEach
|
||||
test262/test/built-ins/Iterator/prototype/forEach/fn-args.js:37: strict mode: InternalError: TODO implement Iterator.prototype.forEach
|
||||
test262/test/built-ins/Iterator/prototype/forEach/fn-called-for-each-yielded-value.js:26: InternalError: TODO implement Iterator.prototype.forEach
|
||||
test262/test/built-ins/Iterator/prototype/forEach/fn-called-for-each-yielded-value.js:26: strict mode: InternalError: TODO implement Iterator.prototype.forEach
|
||||
test262/test/built-ins/Iterator/prototype/forEach/fn-this.js:27: InternalError: TODO implement Iterator.prototype.forEach
|
||||
test262/test/built-ins/Iterator/prototype/forEach/fn-this.js:27: strict mode: InternalError: TODO implement Iterator.prototype.forEach
|
||||
test262/test/built-ins/Iterator/prototype/forEach/fn-throws-then-closing-iterator-also-throws.js:30: Test262Error: Expected a Test262Error but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/forEach/fn-throws-then-closing-iterator-also-throws.js:30: strict mode: Test262Error: Expected a Test262Error but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/forEach/fn-throws.js:32: Test262Error: Expected a Test262Error but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/forEach/fn-throws.js:32: strict mode: Test262Error: Expected a Test262Error but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/forEach/get-next-method-only-once.js:33: InternalError: TODO implement Iterator.prototype.forEach
|
||||
test262/test/built-ins/Iterator/prototype/forEach/get-next-method-only-once.js:33: strict mode: InternalError: TODO implement Iterator.prototype.forEach
|
||||
test262/test/built-ins/Iterator/prototype/forEach/get-next-method-throws.js:15: Test262Error: Expected a Test262Error but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/forEach/get-next-method-throws.js:15: strict mode: Test262Error: Expected a Test262Error but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/forEach/iterator-already-exhausted.js:21: InternalError: TODO implement Iterator.prototype.forEach
|
||||
test262/test/built-ins/Iterator/prototype/forEach/iterator-already-exhausted.js:21: strict mode: InternalError: TODO implement Iterator.prototype.forEach
|
||||
test262/test/built-ins/Iterator/prototype/forEach/next-method-returns-non-object.js:21: Test262Error: Expected a TypeError but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/forEach/next-method-returns-non-object.js:21: strict mode: Test262Error: Expected a TypeError but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/forEach/next-method-returns-throwing-done.js:17: Test262Error: Expected a Test262Error but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/forEach/next-method-returns-throwing-done.js:17: strict mode: Test262Error: Expected a Test262Error but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/forEach/next-method-returns-throwing-value-done.js:28: InternalError: TODO implement Iterator.prototype.forEach
|
||||
test262/test/built-ins/Iterator/prototype/forEach/next-method-returns-throwing-value-done.js:28: strict mode: InternalError: TODO implement Iterator.prototype.forEach
|
||||
test262/test/built-ins/Iterator/prototype/forEach/next-method-returns-throwing-value.js:18: Test262Error: Expected a Test262Error but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/forEach/next-method-returns-throwing-value.js:18: strict mode: Test262Error: Expected a Test262Error but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/forEach/next-method-throws.js:15: Test262Error: Expected a Test262Error but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/forEach/next-method-throws.js:15: strict mode: Test262Error: Expected a Test262Error but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/forEach/non-callable-predicate.js:18: Test262Error: Expected a TypeError but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/forEach/non-callable-predicate.js:18: strict mode: Test262Error: Expected a TypeError but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/forEach/result-is-undefined.js:12: InternalError: TODO implement Iterator.prototype.forEach
|
||||
test262/test/built-ins/Iterator/prototype/forEach/result-is-undefined.js:12: strict mode: InternalError: TODO implement Iterator.prototype.forEach
|
||||
test262/test/built-ins/Iterator/prototype/forEach/this-non-callable-next.js:13: Test262Error: Expected a TypeError but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/forEach/this-non-callable-next.js:13: strict mode: Test262Error: Expected a TypeError but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/forEach/this-non-object.js:19: Test262Error: Expected a TypeError but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/forEach/this-non-object.js:19: strict mode: Test262Error: Expected a TypeError but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/forEach/this-plain-iterator.js:26: InternalError: TODO implement Iterator.prototype.forEach
|
||||
test262/test/built-ins/Iterator/prototype/forEach/this-plain-iterator.js:26: strict mode: InternalError: TODO implement Iterator.prototype.forEach
|
||||
test262/test/built-ins/Iterator/prototype/map/argument-effect-order.js:21: Test262Error: Expected a TypeError but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/map/argument-effect-order.js:21: strict mode: Test262Error: Expected a TypeError but got a InternalError
|
||||
test262/test/built-ins/Iterator/prototype/map/callable.js:10: InternalError: TODO implement Iterator.prototype.map
|
||||
|
|
Loading…
Reference in a new issue