Skip to content

Commit

Permalink
[iterator-helpers] Remove IsCallable check
Browse files Browse the repository at this point in the history
In this CL, we remove IsCallable check from GetIteratorDirect. This
change is based on
tc39/proposal-iterator-helpers#274 and
discussion on May 2023 TC39.

Bug: v8:13558
Change-Id: I33f952391d49e3d4aa2e24e71897d3b97c252e44
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4545191
Reviewed-by: Shu-yu Guo <syg@chromium.org>
Commit-Queue: Rezvan Mahdavi Hezaveh <rezvan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#87741}
  • Loading branch information
rmahdav authored and V8 LUCI CQ committed May 17, 2023
1 parent f18865b commit ebbcb19
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 33 deletions.
10 changes: 3 additions & 7 deletions src/builtins/iterator-helpers.tq
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@ macro MarkIteratorHelperAsExhausted(helper: JSIteratorHelper): void {
transitioning macro GetIteratorDirect(implicit context: Context)(
obj: JSReceiver): IteratorRecord {
// 1. Let nextMethod be ? Get(obj, "next").
const nextProp = GetProperty(obj, kNextString);
const nextMethod = GetProperty(obj, kNextString);

// 2. If IsCallable(nextMethod) is false, throw a TypeError exception.
const nextMethod = Cast<Callable>(nextProp)
otherwise ThrowTypeError(MessageTemplate::kCalledNonCallable, 'next');

// 3. Let iteratorRecord be Record { [[Iterator]]: obj, [[NextMethod]]:
// 2. Let iteratorRecord be Record { [[Iterator]]: obj, [[NextMethod]]:
// nextMethod, [[Done]]: false }.
// 4. Return iteratorRecord.
// 3. Return iteratorRecord.
return IteratorRecord{object: obj, next: nextMethod};
}

Expand Down
20 changes: 20 additions & 0 deletions test/mjsunit/harmony/iterator-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,26 @@ function TestHelperPrototypeSurface(helper) {
assertEquals({value: undefined, done: true}, mapIter.next());
})();

(function TestMapNotCallableNext() {
const iterator = {
i: 1,
next() {
undefined;
},
return () {
return {};
},
};

Object.setPrototypeOf(iterator, Iterator.prototype);
const mapIter = iterator.map((x, i) => {
return x;
});
assertThrows(() => {
mapIter.next();
});
})();

// --- Test filter helper

(function TestFilter() {
Expand Down
52 changes: 26 additions & 26 deletions tools/v8heapconst.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,32 +580,32 @@
("old_space", 0x04d69): "StringSplitCache",
("old_space", 0x05171): "RegExpMultipleCache",
("old_space", 0x05579): "BuiltinsConstantsTable",
("old_space", 0x05add): "AsyncFunctionAwaitRejectSharedFun",
("old_space", 0x05b01): "AsyncFunctionAwaitResolveSharedFun",
("old_space", 0x05b25): "AsyncGeneratorAwaitRejectSharedFun",
("old_space", 0x05b49): "AsyncGeneratorAwaitResolveSharedFun",
("old_space", 0x05b6d): "AsyncGeneratorYieldWithAwaitResolveSharedFun",
("old_space", 0x05b91): "AsyncGeneratorReturnResolveSharedFun",
("old_space", 0x05bb5): "AsyncGeneratorReturnClosedRejectSharedFun",
("old_space", 0x05bd9): "AsyncGeneratorReturnClosedResolveSharedFun",
("old_space", 0x05bfd): "AsyncIteratorValueUnwrapSharedFun",
("old_space", 0x05c21): "ErrorStackGetterSharedFun",
("old_space", 0x05c69): "ErrorStackSetterSharedFun",
("old_space", 0x05cb1): "PromiseAllResolveElementSharedFun",
("old_space", 0x05cd5): "PromiseAllSettledResolveElementSharedFun",
("old_space", 0x05cf9): "PromiseAllSettledRejectElementSharedFun",
("old_space", 0x05d1d): "PromiseAnyRejectElementSharedFun",
("old_space", 0x05d41): "PromiseCapabilityDefaultRejectSharedFun",
("old_space", 0x05d65): "PromiseCapabilityDefaultResolveSharedFun",
("old_space", 0x05d89): "PromiseCatchFinallySharedFun",
("old_space", 0x05dad): "PromiseGetCapabilitiesExecutorSharedFun",
("old_space", 0x05dd1): "PromiseThenFinallySharedFun",
("old_space", 0x05df5): "PromiseThrowerFinallySharedFun",
("old_space", 0x05e19): "PromiseValueThunkFinallySharedFun",
("old_space", 0x05e3d): "ProxyRevokeSharedFun",
("old_space", 0x05e61): "ShadowRealmImportValueFulfilledSFI",
("old_space", 0x05e85): "SourceTextModuleExecuteAsyncModuleFulfilledSFI",
("old_space", 0x05ea9): "SourceTextModuleExecuteAsyncModuleRejectedSFI",
("old_space", 0x05ad9): "AsyncFunctionAwaitRejectSharedFun",
("old_space", 0x05afd): "AsyncFunctionAwaitResolveSharedFun",
("old_space", 0x05b21): "AsyncGeneratorAwaitRejectSharedFun",
("old_space", 0x05b45): "AsyncGeneratorAwaitResolveSharedFun",
("old_space", 0x05b69): "AsyncGeneratorYieldWithAwaitResolveSharedFun",
("old_space", 0x05b8d): "AsyncGeneratorReturnResolveSharedFun",
("old_space", 0x05bb1): "AsyncGeneratorReturnClosedRejectSharedFun",
("old_space", 0x05bd5): "AsyncGeneratorReturnClosedResolveSharedFun",
("old_space", 0x05bf9): "AsyncIteratorValueUnwrapSharedFun",
("old_space", 0x05c1d): "ErrorStackGetterSharedFun",
("old_space", 0x05c65): "ErrorStackSetterSharedFun",
("old_space", 0x05cad): "PromiseAllResolveElementSharedFun",
("old_space", 0x05cd1): "PromiseAllSettledResolveElementSharedFun",
("old_space", 0x05cf5): "PromiseAllSettledRejectElementSharedFun",
("old_space", 0x05d19): "PromiseAnyRejectElementSharedFun",
("old_space", 0x05d3d): "PromiseCapabilityDefaultRejectSharedFun",
("old_space", 0x05d61): "PromiseCapabilityDefaultResolveSharedFun",
("old_space", 0x05d85): "PromiseCatchFinallySharedFun",
("old_space", 0x05da9): "PromiseGetCapabilitiesExecutorSharedFun",
("old_space", 0x05dcd): "PromiseThenFinallySharedFun",
("old_space", 0x05df1): "PromiseThrowerFinallySharedFun",
("old_space", 0x05e15): "PromiseValueThunkFinallySharedFun",
("old_space", 0x05e39): "ProxyRevokeSharedFun",
("old_space", 0x05e5d): "ShadowRealmImportValueFulfilledSFI",
("old_space", 0x05e81): "SourceTextModuleExecuteAsyncModuleFulfilledSFI",
("old_space", 0x05ea5): "SourceTextModuleExecuteAsyncModuleRejectedSFI",
}

# Lower 32 bits of first page addresses for various heap spaces.
Expand Down

0 comments on commit ebbcb19

Please sign in to comment.