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/codegen/code-stub-assembler.h" 9 10 namespace v8 { 11 namespace internal { 12 13 using compiler::Node; 14 15 class GrowableFixedArray; 16 17 class IteratorBuiltinsAssembler : public CodeStubAssembler { 18 public: IteratorBuiltinsAssembler(compiler::CodeAssemblerState * state)19 explicit IteratorBuiltinsAssembler(compiler::CodeAssemblerState* state) 20 : CodeStubAssembler(state) {} 21 22 using IteratorRecord = TorqueStructIteratorRecord; 23 24 // Returns object[Symbol.iterator]. 25 TNode<Object> GetIteratorMethod(TNode<Context> context, TNode<Object>); 26 27 // https://tc39.github.io/ecma262/#sec-getiterator --- never used for 28 // @@asyncIterator. 29 IteratorRecord GetIterator(TNode<Context> context, TNode<Object> object); 30 IteratorRecord GetIterator(TNode<Context> context, TNode<Object> object, 31 TNode<Object> method); 32 33 // https://tc39.github.io/ecma262/#sec-iteratorstep 34 // If the iterator is done, goto {if_done}, otherwise returns an iterator 35 // result. 36 // `fast_iterator_result_map` refers to the map for the JSIteratorResult 37 // object, loaded from the native context. 38 TNode<JSReceiver> IteratorStep( 39 TNode<Context> context, const IteratorRecord& iterator, Label* if_done, 40 base::Optional<TNode<Map>> fast_iterator_result_map = base::nullopt); IteratorStep(TNode<Context> context,const IteratorRecord & iterator,base::Optional<TNode<Map>> fast_iterator_result_map,Label * if_done)41 TNode<JSReceiver> IteratorStep( 42 TNode<Context> context, const IteratorRecord& iterator, 43 base::Optional<TNode<Map>> fast_iterator_result_map, Label* if_done) { 44 return IteratorStep(context, iterator, if_done, fast_iterator_result_map); 45 } 46 47 // https://tc39.github.io/ecma262/#sec-iteratorvalue 48 // Return the `value` field from an iterator. 49 // `fast_iterator_result_map` refers to the map for the JSIteratorResult 50 // object, loaded from the native context. 51 TNode<Object> IteratorValue( 52 TNode<Context> context, TNode<JSReceiver> result, 53 base::Optional<TNode<Map>> fast_iterator_result_map = base::nullopt); 54 55 // #sec-iterabletolist 56 // Build a JSArray by iterating over {iterable} using {iterator_fn}, 57 // following the ECMAscript operation with the same name. 58 TNode<JSArray> IterableToList(TNode<Context> context, TNode<Object> iterable, 59 TNode<Object> iterator_fn); 60 61 TNode<FixedArray> IterableToFixedArray(TNode<Context> context, 62 TNode<Object> iterable, 63 TNode<Object> iterator_fn); 64 65 void FillFixedArrayFromIterable(TNode<Context> context, 66 TNode<Object> iterable, 67 TNode<Object> iterator_fn, 68 GrowableFixedArray* values); 69 70 // Currently at https://tc39.github.io/proposal-intl-list-format/ 71 // #sec-createstringlistfromiterable 72 TNode<JSArray> StringListFromIterable(TNode<Context> context, 73 TNode<Object> iterable); 74 75 void FastIterableToList(TNode<Context> context, TNode<Object> iterable, 76 TVariable<JSArray>* var_result, Label* slow); 77 TNode<JSArray> FastIterableToList(TNode<Context> context, 78 TNode<Object> iterable, Label* slow); 79 }; 80 81 } // namespace internal 82 } // namespace v8 83 84 #endif // V8_BUILTINS_BUILTINS_ITERATOR_GEN_H_ 85