blob: e662e4e75e5afef0d4788438daabdd077aee138f [file] [log] [blame]
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include 'src/builtins/builtins-iterator-gen.h'
namespace iterator {
// Returned from IteratorBuiltinsAssembler::GetIterator().
struct IteratorRecord {
// iteratorRecord.[[Iterator]]
object: JSReceiver;
// iteratorRecord.[[NextMethod]]
next: JSAny;
}
extern macro IteratorBuiltinsAssembler::GetIteratorMethod(
implicit context: Context)(JSAny): JSAny;
extern macro IteratorBuiltinsAssembler::GetIterator(
implicit context: Context)(JSAny): IteratorRecord;
extern macro IteratorBuiltinsAssembler::IteratorStep(
implicit context: Context)(IteratorRecord): JSReceiver
labels Done;
extern macro IteratorBuiltinsAssembler::IteratorStep(
implicit context: Context)(IteratorRecord, Map): JSReceiver
labels Done;
extern macro IteratorBuiltinsAssembler::IteratorValue(
implicit context: Context)(JSReceiver): JSAny;
extern macro IteratorBuiltinsAssembler::IteratorValue(
implicit context: Context)(JSReceiver, Map): JSAny;
extern macro IteratorBuiltinsAssembler::IteratorCloseOnException(
implicit context: Context)(IteratorRecord, JSAny): never;
extern macro IteratorBuiltinsAssembler::IterableToList(
implicit context: Context)(JSAny, JSAny): JSArray;
extern macro IteratorBuiltinsAssembler::StringListFromIterable(
implicit context: Context)(JSAny): JSArray;
extern builtin IterableToListMayPreserveHoles(implicit context:
Context)(JSAny, JSAny);
extern builtin IterableToListWithSymbolLookup(implicit context:
Context)(JSAny);
transitioning builtin GetIteratorWithFeedback(
context: Context, receiver: JSAny, loadSlot: Smi, callSlot: Smi,
feedback: Undefined | FeedbackVector): JSAny {
let iteratorMethod: JSAny;
typeswitch (feedback) {
case (Undefined): {
iteratorMethod = GetProperty(receiver, IteratorSymbolConstant());
}
case (feedback: FeedbackVector): {
iteratorMethod = LoadIC(
context, receiver, IteratorSymbolConstant(), loadSlot, feedback);
}
}
return CallIteratorWithFeedback(
context, receiver, iteratorMethod, callSlot, feedback);
}
transitioning builtin CallIteratorWithFeedback(
context: Context, receiver: JSAny, iteratorMethod: JSAny, callSlot: Smi,
feedback: Undefined | FeedbackVector): JSAny {
const callSlotUnTagged: uintptr = Unsigned(SmiUntag(callSlot));
CollectCallFeedback(iteratorMethod, context, feedback, callSlotUnTagged);
const iteratorCallable: Callable = Cast<Callable>(iteratorMethod)
otherwise ThrowCalledNonCallable(iteratorMethod);
const iterator: JSAny = Call(context, iteratorCallable, receiver);
typeswitch (iterator) {
case (JSReceiver): {
return iterator;
}
case (JSPrimitive): {
ThrowSymbolIteratorInvalid();
}
}
}
}