1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_BUILTINS_BUILTINS_ITERATOR_GEN_H_
6 #define V8_BUILTINS_BUILTINS_ITERATOR_GEN_H_
7 
8 #include "src/code-stub-assembler.h"
9 
10 namespace v8 {
11 namespace internal {
12 
13 using compiler::Node;
14 
15 class IteratorBuiltinsAssembler : public CodeStubAssembler {
16  public:
IteratorBuiltinsAssembler(compiler::CodeAssemblerState * state)17   explicit IteratorBuiltinsAssembler(compiler::CodeAssemblerState* state)
18       : CodeStubAssembler(state) {}
19 
20   // Returns object[Symbol.iterator].
21   TNode<Object> GetIteratorMethod(Node* context, Node* object);
22 
23   // https://tc39.github.io/ecma262/#sec-getiterator --- never used for
24   // @@asyncIterator.
25   IteratorRecord GetIterator(Node* context, Node* object,
26                              Label* if_exception = nullptr,
27                              Variable* exception = nullptr);
28   IteratorRecord GetIterator(Node* context, Node* object, Node* method,
29                              Label* if_exception = nullptr,
30                              Variable* exception = nullptr);
31 
32   // https://tc39.github.io/ecma262/#sec-iteratorstep
33   // Returns `false` if the iterator is done, otherwise returns an
34   // iterator result.
35   // `fast_iterator_result_map` refers to the map for the JSIteratorResult
36   // object, loaded from the native context.
37   Node* IteratorStep(Node* context, const IteratorRecord& iterator,
38                      Label* if_done, Node* fast_iterator_result_map = nullptr,
39                      Label* if_exception = nullptr,
40                      Variable* exception = nullptr);
41 
42   // https://tc39.github.io/ecma262/#sec-iteratorvalue
43   // Return the `value` field from an iterator.
44   // `fast_iterator_result_map` refers to the map for the JSIteratorResult
45   // object, loaded from the native context.
46   Node* IteratorValue(Node* context, Node* result,
47                       Node* fast_iterator_result_map = nullptr,
48                       Label* if_exception = nullptr,
49                       Variable* exception = nullptr);
50 
51   // https://tc39.github.io/ecma262/#sec-iteratorclose
52   void IteratorCloseOnException(Node* context, const IteratorRecord& iterator,
53                                 Label* if_exception, Variable* exception);
54   void IteratorCloseOnException(Node* context, const IteratorRecord& iterator,
55                                 Variable* exception);
56 
57   // /#sec-iterabletolist
58   TNode<JSArray> IterableToList(TNode<Context> context, TNode<Object> iterable,
59                                 TNode<Object> iterator_fn);
60   TNode<JSArray> IterableToList(TNode<Context> context, TNode<Object> iterable);
61 };
62 
63 }  // namespace internal
64 }  // namespace v8
65 
66 #endif  // V8_BUILTINS_BUILTINS_ITERATOR_GEN_H_
67