V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
builtins-array-gen.h
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_ARRAY_GEN_H_
6 #define V8_BUILTINS_BUILTINS_ARRAY_GEN_H_
7 
8 #include "src/code-stub-assembler.h"
9 
10 namespace v8 {
11 namespace internal {
12 
14  public:
16 
17  typedef std::function<void(ArrayBuiltinsAssembler* masm)>
18  BuiltinResultGenerator;
19 
20  typedef std::function<Node*(ArrayBuiltinsAssembler* masm, Node* k_value,
21  Node* k)>
22  CallResultProcessor;
23 
24  typedef std::function<void(ArrayBuiltinsAssembler* masm)> PostLoopAction;
25 
26  enum class MissingPropertyMode { kSkip, kUseUndefined };
27 
28  void FindResultGenerator();
29 
30  Node* FindProcessor(Node* k_value, Node* k);
31 
32  void FindIndexResultGenerator();
33 
34  Node* FindIndexProcessor(Node* k_value, Node* k);
35 
36  void ForEachResultGenerator();
37 
38  Node* ForEachProcessor(Node* k_value, Node* k);
39 
40  void SomeResultGenerator();
41 
42  Node* SomeProcessor(Node* k_value, Node* k);
43 
44  void EveryResultGenerator();
45 
46  Node* EveryProcessor(Node* k_value, Node* k);
47 
48  void ReduceResultGenerator();
49 
50  Node* ReduceProcessor(Node* k_value, Node* k);
51 
52  void ReducePostLoopAction();
53 
54  void FilterResultGenerator();
55 
56  Node* FilterProcessor(Node* k_value, Node* k);
57 
58  void MapResultGenerator();
59 
60  void TypedArrayMapResultGenerator();
61 
62  Node* SpecCompliantMapProcessor(Node* k_value, Node* k);
63 
64  Node* FastMapProcessor(Node* k_value, Node* k);
65 
66  // See tc39.github.io/ecma262/#sec-%typedarray%.prototype.map.
67  Node* TypedArrayMapProcessor(Node* k_value, Node* k);
68 
69  void NullPostLoopAction();
70 
71  // Uses memset to effectively initialize the given FixedArray with Smi zeroes.
72  void FillFixedArrayWithSmiZero(TNode<FixedArray> array,
73  TNode<Smi> smi_length);
74 
75  TNode<String> CallJSArrayArrayJoinConcatToSequentialString(
76  TNode<FixedArray> fixed_array, TNode<IntPtrT> length, TNode<String> sep,
77  TNode<String> dest) {
78  TNode<ExternalReference> func = ExternalConstant(
79  ExternalReference::jsarray_array_join_concat_to_sequential_string());
80  TNode<ExternalReference> isolate_ptr =
81  ExternalConstant(ExternalReference::isolate_address(isolate()));
82  return UncheckedCast<String>(
83  CallCFunction5(MachineType::AnyTagged(), // <return> String
84  MachineType::Pointer(), // Isolate*
85  MachineType::AnyTagged(), // FixedArray fixed_array
86  MachineType::IntPtr(), // intptr_t length
87  MachineType::AnyTagged(), // String sep
88  MachineType::AnyTagged(), // String dest
89  func, isolate_ptr, fixed_array, length, sep, dest));
90  }
91 
92  protected:
93  TNode<Context> context() { return context_; }
94  TNode<Object> receiver() { return receiver_; }
95  TNode<IntPtrT> argc() { return argc_; }
96  TNode<JSReceiver> o() { return o_; }
97  TNode<Number> len() { return len_; }
98  Node* callbackfn() { return callbackfn_; }
99  Node* this_arg() { return this_arg_; }
100  TNode<Number> k() { return CAST(k_.value()); }
101  Node* a() { return a_.value(); }
102 
103  void ReturnFromBuiltin(Node* value);
104 
105  void InitIteratingArrayBuiltinBody(TNode<Context> context,
106  TNode<Object> receiver, Node* callbackfn,
107  Node* this_arg, TNode<IntPtrT> argc);
108 
109  void GenerateIteratingArrayBuiltinBody(
110  const char* name, const BuiltinResultGenerator& generator,
111  const CallResultProcessor& processor, const PostLoopAction& action,
112  const Callable& slow_case_continuation,
113  MissingPropertyMode missing_property_mode,
114  ForEachDirection direction = ForEachDirection::kForward);
115  void InitIteratingArrayBuiltinLoopContinuation(
116  TNode<Context> context, TNode<Object> receiver, Node* callbackfn,
117  Node* this_arg, Node* a, TNode<JSReceiver> o, Node* initial_k,
118  TNode<Number> len, Node* to);
119 
120  void GenerateIteratingTypedArrayBuiltinBody(
121  const char* name, const BuiltinResultGenerator& generator,
122  const CallResultProcessor& processor, const PostLoopAction& action,
123  ForEachDirection direction = ForEachDirection::kForward);
124 
125  void GenerateIteratingArrayBuiltinLoopContinuation(
126  const CallResultProcessor& processor, const PostLoopAction& action,
127  MissingPropertyMode missing_property_mode,
128  ForEachDirection direction = ForEachDirection::kForward);
129 
130  void TailCallArrayConstructorStub(
131  const Callable& callable, TNode<Context> context,
132  TNode<JSFunction> target, TNode<HeapObject> allocation_site_or_undefined,
133  TNode<Int32T> argc);
134 
135  void GenerateDispatchToArrayStub(
136  TNode<Context> context, TNode<JSFunction> target, TNode<Int32T> argc,
137  AllocationSiteOverrideMode mode,
138  TNode<AllocationSite> allocation_site = TNode<AllocationSite>());
139 
140  void CreateArrayDispatchNoArgument(
141  TNode<Context> context, TNode<JSFunction> target, TNode<Int32T> argc,
142  AllocationSiteOverrideMode mode,
143  TNode<AllocationSite> allocation_site = TNode<AllocationSite>());
144 
145  void CreateArrayDispatchSingleArgument(
146  TNode<Context> context, TNode<JSFunction> target, TNode<Int32T> argc,
147  AllocationSiteOverrideMode mode,
148  TNode<AllocationSite> allocation_site = TNode<AllocationSite>());
149 
150  void GenerateConstructor(Node* context, Node* array_function, Node* array_map,
151  Node* array_size, Node* allocation_site,
152  ElementsKind elements_kind, AllocationSiteMode mode);
153  void GenerateArrayNoArgumentConstructor(ElementsKind kind,
154  AllocationSiteOverrideMode mode);
155  void GenerateArraySingleArgumentConstructor(ElementsKind kind,
156  AllocationSiteOverrideMode mode);
157  void GenerateArrayNArgumentsConstructor(
158  TNode<Context> context, TNode<JSFunction> target,
159  TNode<Object> new_target, TNode<Int32T> argc,
160  TNode<HeapObject> maybe_allocation_site);
161 
162  void GenerateInternalArrayNoArgumentConstructor(ElementsKind kind);
163  void GenerateInternalArraySingleArgumentConstructor(ElementsKind kind);
164 
165  private:
166  static ElementsKind ElementsKindForInstanceType(InstanceType type);
167 
168  void VisitAllTypedArrayElements(Node* array_buffer,
169  const CallResultProcessor& processor,
170  Label* detached, ForEachDirection direction,
171  TNode<JSTypedArray> typed_array);
172 
173  void VisitAllFastElementsOneKind(ElementsKind kind,
174  const CallResultProcessor& processor,
175  Label* array_changed, ParameterMode mode,
176  ForEachDirection direction,
177  MissingPropertyMode missing_property_mode,
178  TNode<Smi> length);
179 
180  void HandleFastElements(const CallResultProcessor& processor,
181  const PostLoopAction& action, Label* slow,
182  ForEachDirection direction,
183  MissingPropertyMode missing_property_mode);
184 
185  // Perform ArraySpeciesCreate (ES6 #sec-arrayspeciescreate).
186  // This version is specialized to create a zero length array
187  // of the elements kind of the input array.
188  void GenerateArraySpeciesCreate();
189 
190  // Perform ArraySpeciesCreate (ES6 #sec-arrayspeciescreate).
191  void GenerateArraySpeciesCreate(TNode<Number> len);
192 
193  Node* callbackfn_ = nullptr;
195  Node* this_arg_ = nullptr;
196  TNode<Number> len_;
197  TNode<Context> context_;
198  TNode<Object> receiver_;
199  TNode<IntPtrT> argc_;
200  Node* fast_typed_array_target_ = nullptr;
201  const char* name_ = nullptr;
202  Variable k_;
203  Variable a_;
204  Variable to_;
205  Label fully_spec_compliant_;
206  ElementsKind source_elements_kind_ = ElementsKind::NO_ELEMENTS;
207 };
208 
209 } // namespace internal
210 } // namespace v8
211 
212 #endif // V8_BUILTINS_BUILTINS_ARRAY_GEN_H_
Definition: libplatform.h:13