builtins-iterator-gen.h 3.44 KB
Newer Older
1 2 3 4
// Copyright 2017 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.

5 6 7
#ifndef V8_BUILTINS_BUILTINS_ITERATOR_GEN_H_
#define V8_BUILTINS_BUILTINS_ITERATOR_GEN_H_

8
#include "src/codegen/code-stub-assembler.h"
9 10 11 12 13 14

namespace v8 {
namespace internal {

using compiler::Node;

15
class IteratorBuiltinsAssembler : public CodeStubAssembler {
16 17
 public:
  explicit IteratorBuiltinsAssembler(compiler::CodeAssemblerState* state)
18 19 20
      : CodeStubAssembler(state) {}

  using IteratorRecord = TorqueStructIteratorRecord;
21

22
  // Returns object[Symbol.iterator].
23
  TNode<Object> GetIteratorMethod(Node* context, Node* object);
24

25 26
  // https://tc39.github.io/ecma262/#sec-getiterator --- never used for
  // @@asyncIterator.
27 28 29 30 31 32
  IteratorRecord GetIterator(Node* context, Node* object,
                             Label* if_exception = nullptr,
                             Variable* exception = nullptr);
  IteratorRecord GetIterator(Node* context, Node* object, Node* method,
                             Label* if_exception = nullptr,
                             Variable* exception = nullptr);
33 34

  // https://tc39.github.io/ecma262/#sec-iteratorstep
35 36
  // If the iterator is done, goto {if_done}, otherwise returns an iterator
  // result.
37 38
  // `fast_iterator_result_map` refers to the map for the JSIteratorResult
  // object, loaded from the native context.
39 40 41 42 43 44 45 46
  TNode<JSReceiver> IteratorStep(
      TNode<Context> context, const IteratorRecord& iterator, Label* if_done,
      base::Optional<TNode<Map>> fast_iterator_result_map = base::nullopt,
      Label* if_exception = nullptr, Variable* exception = nullptr);

  TNode<JSReceiver> IteratorStep(
      TNode<Context> context, const IteratorRecord& iterator,
      base::Optional<TNode<Map>> fast_iterator_result_map, Label* if_done) {
47 48
    return IteratorStep(context, iterator, if_done, fast_iterator_result_map);
  }
49 50 51 52 53

  // https://tc39.github.io/ecma262/#sec-iteratorvalue
  // Return the `value` field from an iterator.
  // `fast_iterator_result_map` refers to the map for the JSIteratorResult
  // object, loaded from the native context.
54 55 56 57
  TNode<Object> IteratorValue(
      TNode<Context> context, TNode<JSReceiver> result,
      base::Optional<TNode<Map>> fast_iterator_result_map = base::nullopt,
      Label* if_exception = nullptr, Variable* exception = nullptr);
58 59

  // https://tc39.github.io/ecma262/#sec-iteratorclose
60 61 62 63
  void IteratorCloseOnException(Node* context, const IteratorRecord& iterator,
                                Label* if_exception, Variable* exception);
  void IteratorCloseOnException(Node* context, const IteratorRecord& iterator,
                                TNode<Object> exception);
64

65 66 67
  // #sec-iterabletolist
  // Build a JSArray by iterating over {iterable} using {iterator_fn},
  // following the ECMAscript operation with the same name.
68 69
  TNode<JSArray> IterableToList(TNode<Context> context, TNode<Object> iterable,
                                TNode<Object> iterator_fn);
70

71 72 73 74 75
  // Currently at https://tc39.github.io/proposal-intl-list-format/
  // #sec-createstringlistfromiterable
  TNode<JSArray> StringListFromIterable(TNode<Context> context,
                                        TNode<Object> iterable);

76 77
  void FastIterableToList(TNode<Context> context, TNode<Object> iterable,
                          TVariable<Object>* var_result, Label* slow);
78 79 80 81
};

}  // namespace internal
}  // namespace v8
82 83

#endif  // V8_BUILTINS_BUILTINS_ITERATOR_GEN_H_