Skip to content

Commit

Permalink
Implement Iterator.prototype.map
Browse files Browse the repository at this point in the history
  • Loading branch information
saghul committed Nov 13, 2024
1 parent 4933e17 commit 17a8772
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 59 deletions.
36 changes: 35 additions & 1 deletion quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -40328,7 +40328,13 @@ static JSValue js_iterator_proto_forEach(JSContext *ctx, JSValue this_val,
static JSValue js_iterator_proto_map(JSContext *ctx, JSValue this_val,
int argc, JSValue *argv)
{
return JS_ThrowInternalError(ctx, "TODO implement Iterator.prototype.map");
JSValue func;
if (!JS_IsObject(this_val))
return JS_ThrowTypeError(ctx, "Iterator.prototype.map called on non-object");
func = argv[0];
if (check_function(ctx, func))
return JS_EXCEPTION;
return js_create_iterator_helper(ctx, this_val, JS_ITERATOR_HELPER_KIND_MAP, func, 0);
}

static JSValue js_iterator_proto_reduce(JSContext *ctx, JSValue this_val,
Expand Down Expand Up @@ -40687,6 +40693,34 @@ static JSValue js_iterator_helper_next(JSContext *ctx, JSValue this_val,
goto filter_again;
}
break;
case JS_ITERATOR_HELPER_KIND_MAP:
{
JSValue item, method, index_val, args[2];
if (magic == GEN_MAGIC_NEXT) {
method = js_dup(it->next);
} else {
method = JS_GetProperty(ctx, it->obj, JS_ATOM_return);
if (JS_IsException(method))
goto fail;
}
item = JS_IteratorNext(ctx, it->obj, method, 0, NULL, pdone);
JS_FreeValue(ctx, method);
if (JS_IsException(item))
goto fail;
if (*pdone || magic == GEN_MAGIC_RETURN) {
ret = item;
goto done;
}
index_val = js_int64(it->count++);
args[0] = item;
args[1] = index_val;
ret = JS_Call(ctx, it->func, JS_UNDEFINED, countof(args), args);
JS_FreeValue(ctx, index_val);
if (JS_IsException(ret))
goto fail;
goto done;
}
break;
case JS_ITERATOR_HELPER_KIND_TAKE:
{
JSValue item, method;
Expand Down
58 changes: 0 additions & 58 deletions test262_errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,64 +98,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/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
test262/test/built-ins/Iterator/prototype/map/callable.js:10: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/exhaustion-does-not-call-return.js:31: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/exhaustion-does-not-call-return.js:31: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/get-next-method-only-once.js:38: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/get-next-method-only-once.js:38: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/get-next-method-throws.js:17: Test262Error: Expected a Test262Error but got a InternalError
test262/test/built-ins/Iterator/prototype/map/get-next-method-throws.js:17: strict mode: Test262Error: Expected a Test262Error but got a InternalError
test262/test/built-ins/Iterator/prototype/map/get-return-method-throws.js:25: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/get-return-method-throws.js:25: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/iterator-already-exhausted.js:19: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/iterator-already-exhausted.js:19: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/iterator-return-method-throws.js:25: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/iterator-return-method-throws.js:25: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/mapper-args.js:24: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/mapper-args.js:24: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/mapper-this.js:26: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/mapper-this.js:26: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/mapper-throws-then-closing-iterator-also-throws.js:30: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/mapper-throws-then-closing-iterator-also-throws.js:30: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/mapper-throws.js:31: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/mapper-throws.js:31: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/next-method-returns-non-object.js:19: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/next-method-returns-non-object.js:19: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/next-method-returns-throwing-done.js:27: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/next-method-returns-throwing-done.js:27: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/next-method-returns-throwing-value-done.js:27: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/next-method-returns-throwing-value-done.js:27: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/next-method-returns-throwing-value.js:27: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/next-method-returns-throwing-value.js:27: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/next-method-throws.js:19: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/next-method-throws.js:19: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/non-callable-mapper.js:18: Test262Error: Expected a TypeError but got a InternalError
test262/test/built-ins/Iterator/prototype/map/non-callable-mapper.js:18: strict mode: Test262Error: Expected a TypeError but got a InternalError
test262/test/built-ins/Iterator/prototype/map/result-is-iterator.js:11: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/result-is-iterator.js:11: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/return-is-forwarded-to-underlying-iterator.js:28: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/return-is-forwarded-to-underlying-iterator.js:28: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/return-is-not-forwarded-after-exhaustion.js:27: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/return-is-not-forwarded-after-exhaustion.js:27: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/returned-iterator-yields-mapper-return-values.js:23: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/returned-iterator-yields-mapper-return-values.js:23: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/this-non-callable-next.js:13: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/this-non-callable-next.js:13: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/this-non-object.js:21: Test262Error: Expected a TypeError but got a InternalError
test262/test/built-ins/Iterator/prototype/map/this-non-object.js:21: strict mode: Test262Error: Expected a TypeError but got a InternalError
test262/test/built-ins/Iterator/prototype/map/this-plain-iterator.js:24: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/this-plain-iterator.js:24: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/throws-typeerror-when-generator-is-running.js:39: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/throws-typeerror-when-generator-is-running.js:39: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/underlying-iterator-advanced-in-parallel.js:19: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/underlying-iterator-advanced-in-parallel.js:19: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/underlying-iterator-closed-in-parallel.js:19: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/underlying-iterator-closed-in-parallel.js:19: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/underlying-iterator-closed.js:21: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/Iterator/prototype/map/underlying-iterator-closed.js:21: strict mode: InternalError: TODO implement Iterator.prototype.map
test262/test/built-ins/RegExp/property-escapes/generated/Alphabetic.js:16: Test262Error: `\P{Alphabetic}` should match U+000363 (`ͣ`)
test262/test/built-ins/RegExp/property-escapes/generated/Alphabetic.js:16: strict mode: Test262Error: `\P{Alphabetic}` should match U+000363 (`ͣ`)
test262/test/built-ins/RegExp/property-escapes/generated/Assigned.js:16: Test262Error: `\P{Assigned}` should match U+001B7F (`᭿`)
Expand Down

0 comments on commit 17a8772

Please sign in to comment.