|
20 | 20 | namespace v8 { |
21 | 21 | namespace internal { |
22 | 22 |
|
23 | | -using Node = compiler::Node; |
24 | | -using IteratorRecord = TorqueStructIteratorRecord; |
25 | | -using PromiseResolvingFunctions = TorqueStructPromiseResolvingFunctions; |
26 | | - |
27 | | -TNode<JSPromise> PromiseBuiltinsAssembler::AllocateJSPromise( |
28 | | - TNode<Context> context) { |
29 | | - const TNode<NativeContext> native_context = LoadNativeContext(context); |
30 | | - const TNode<JSFunction> promise_fun = |
31 | | - CAST(LoadContextElement(native_context, Context::PROMISE_FUNCTION_INDEX)); |
32 | | - CSA_ASSERT(this, IsFunctionWithPrototypeSlotMap(LoadMap(promise_fun))); |
33 | | - const TNode<Map> promise_map = LoadObjectField<Map>( |
34 | | - promise_fun, JSFunction::kPrototypeOrInitialMapOffset); |
35 | | - const TNode<HeapObject> promise = |
36 | | - Allocate(JSPromise::kSizeWithEmbedderFields); |
37 | | - StoreMapNoWriteBarrier(promise, promise_map); |
38 | | - StoreObjectFieldRoot(promise, JSPromise::kPropertiesOrHashOffset, |
39 | | - RootIndex::kEmptyFixedArray); |
40 | | - StoreObjectFieldRoot(promise, JSPromise::kElementsOffset, |
41 | | - RootIndex::kEmptyFixedArray); |
42 | | - return CAST(promise); |
43 | | -} |
44 | | - |
45 | | -void PromiseBuiltinsAssembler::PromiseInit(TNode<JSPromise> promise) { |
46 | | - STATIC_ASSERT(v8::Promise::kPending == 0); |
47 | | - StoreObjectFieldNoWriteBarrier(promise, JSPromise::kReactionsOrResultOffset, |
48 | | - SmiConstant(Smi::zero())); |
49 | | - StoreObjectFieldNoWriteBarrier(promise, JSPromise::kFlagsOffset, |
50 | | - SmiConstant(Smi::zero())); |
| 23 | +void PromiseBuiltinsAssembler::ZeroOutEmbedderOffsets( |
| 24 | + TNode<JSPromise> promise) { |
51 | 25 | for (int offset = JSPromise::kHeaderSize; |
52 | 26 | offset < JSPromise::kSizeWithEmbedderFields; offset += kTaggedSize) { |
53 | 27 | StoreObjectFieldNoWriteBarrier(promise, offset, SmiConstant(Smi::zero())); |
54 | 28 | } |
55 | 29 | } |
56 | 30 |
|
57 | | -TNode<JSPromise> PromiseBuiltinsAssembler::AllocateAndInitJSPromise( |
| 31 | +TNode<HeapObject> PromiseBuiltinsAssembler::AllocatePromiseReactionJobTask( |
58 | 32 | TNode<Context> context) { |
59 | | - return AllocateAndInitJSPromise(context, UndefinedConstant()); |
60 | | -} |
61 | | - |
62 | | -TNode<JSPromise> PromiseBuiltinsAssembler::AllocateAndInitJSPromise( |
63 | | - TNode<Context> context, TNode<Object> parent) { |
64 | | - const TNode<JSPromise> instance = AllocateJSPromise(context); |
65 | | - PromiseInit(instance); |
66 | | - |
67 | | - Label out(this); |
68 | | - GotoIfNot(IsPromiseHookEnabledOrHasAsyncEventDelegate(), &out); |
69 | | - CallRuntime(Runtime::kPromiseHookInit, context, instance, parent); |
70 | | - Goto(&out); |
71 | | - |
72 | | - BIND(&out); |
73 | | - return instance; |
74 | | -} |
75 | | - |
76 | | -TNode<JSPromise> PromiseBuiltinsAssembler::AllocateAndSetJSPromise( |
77 | | - TNode<Context> context, v8::Promise::PromiseState status, |
78 | | - TNode<Object> result) { |
79 | | - DCHECK_NE(Promise::kPending, status); |
80 | | - |
81 | | - const TNode<JSPromise> instance = AllocateJSPromise(context); |
82 | | - StoreObjectFieldNoWriteBarrier(instance, JSPromise::kReactionsOrResultOffset, |
83 | | - result); |
84 | | - STATIC_ASSERT(JSPromise::kStatusShift == 0); |
85 | | - StoreObjectFieldNoWriteBarrier(instance, JSPromise::kFlagsOffset, |
86 | | - SmiConstant(status)); |
87 | | - for (int offset = JSPromise::kHeaderSize; |
88 | | - offset < JSPromise::kSizeWithEmbedderFields; offset += kTaggedSize) { |
89 | | - StoreObjectFieldNoWriteBarrier(instance, offset, SmiConstant(0)); |
90 | | - } |
91 | | - |
92 | | - Label out(this); |
93 | | - GotoIfNot(IsPromiseHookEnabledOrHasAsyncEventDelegate(), &out); |
94 | | - CallRuntime(Runtime::kPromiseHookInit, context, instance, |
95 | | - UndefinedConstant()); |
96 | | - Goto(&out); |
97 | | - |
98 | | - BIND(&out); |
99 | | - return instance; |
100 | | -} |
101 | | - |
102 | | -TNode<BoolT> PromiseBuiltinsAssembler::PromiseHasHandler( |
103 | | - TNode<JSPromise> promise) { |
104 | | - const TNode<Smi> flags = |
105 | | - LoadObjectField<Smi>(promise, JSPromise::kFlagsOffset); |
106 | | - return IsSetWord(SmiUntag(flags), 1 << JSPromise::kHasHandlerBit); |
107 | | -} |
108 | | - |
109 | | -TNode<PromiseReaction> PromiseBuiltinsAssembler::AllocatePromiseReaction( |
110 | | - TNode<Object> next, TNode<HeapObject> promise_or_capability, |
111 | | - TNode<HeapObject> fulfill_handler, TNode<HeapObject> reject_handler) { |
112 | | - const TNode<HeapObject> reaction = Allocate(PromiseReaction::kSize); |
113 | | - StoreMapNoWriteBarrier(reaction, RootIndex::kPromiseReactionMap); |
114 | | - StoreObjectFieldNoWriteBarrier(reaction, PromiseReaction::kNextOffset, next); |
115 | | - StoreObjectFieldNoWriteBarrier(reaction, |
116 | | - PromiseReaction::kPromiseOrCapabilityOffset, |
117 | | - promise_or_capability); |
118 | | - StoreObjectFieldNoWriteBarrier( |
119 | | - reaction, PromiseReaction::kFulfillHandlerOffset, fulfill_handler); |
120 | | - StoreObjectFieldNoWriteBarrier( |
121 | | - reaction, PromiseReaction::kRejectHandlerOffset, reject_handler); |
122 | | - return CAST(reaction); |
123 | | -} |
124 | | - |
125 | | -TNode<PromiseReactionJobTask> |
126 | | -PromiseBuiltinsAssembler::AllocatePromiseReactionJobTask( |
127 | | - TNode<Map> map, TNode<Context> context, TNode<Object> argument, |
128 | | - TNode<HeapObject> handler, TNode<HeapObject> promise_or_capability) { |
129 | | - const TNode<HeapObject> microtask = |
130 | | - Allocate(PromiseReactionJobTask::kSizeOfAllPromiseReactionJobTasks); |
131 | | - StoreMapNoWriteBarrier(microtask, map); |
132 | | - StoreObjectFieldNoWriteBarrier( |
133 | | - microtask, PromiseReactionJobTask::kArgumentOffset, argument); |
134 | | - StoreObjectFieldNoWriteBarrier( |
135 | | - microtask, PromiseReactionJobTask::kContextOffset, context); |
136 | | - StoreObjectFieldNoWriteBarrier( |
137 | | - microtask, PromiseReactionJobTask::kHandlerOffset, handler); |
138 | | - StoreObjectFieldNoWriteBarrier( |
139 | | - microtask, PromiseReactionJobTask::kPromiseOrCapabilityOffset, |
140 | | - promise_or_capability); |
141 | | - return CAST(microtask); |
142 | | -} |
143 | | - |
144 | | -TNode<PromiseResolveThenableJobTask> |
145 | | -PromiseBuiltinsAssembler::AllocatePromiseResolveThenableJobTask( |
146 | | - TNode<JSPromise> promise_to_resolve, TNode<JSReceiver> then, |
147 | | - TNode<JSReceiver> thenable, TNode<Context> context) { |
148 | | - const TNode<HeapObject> microtask = |
149 | | - Allocate(PromiseResolveThenableJobTask::kSize); |
150 | | - StoreMapNoWriteBarrier(microtask, |
151 | | - RootIndex::kPromiseResolveThenableJobTaskMap); |
152 | | - StoreObjectFieldNoWriteBarrier( |
153 | | - microtask, PromiseResolveThenableJobTask::kContextOffset, context); |
154 | | - StoreObjectFieldNoWriteBarrier( |
155 | | - microtask, PromiseResolveThenableJobTask::kPromiseToResolveOffset, |
156 | | - promise_to_resolve); |
157 | | - StoreObjectFieldNoWriteBarrier( |
158 | | - microtask, PromiseResolveThenableJobTask::kThenOffset, then); |
159 | | - StoreObjectFieldNoWriteBarrier( |
160 | | - microtask, PromiseResolveThenableJobTask::kThenableOffset, thenable); |
161 | | - return CAST(microtask); |
162 | | -} |
163 | | - |
164 | | -void PromiseBuiltinsAssembler::BranchIfPromiseResolveLookupChainIntact( |
165 | | - TNode<NativeContext> native_context, TNode<Object> constructor, |
166 | | - Label* if_fast, Label* if_slow) { |
167 | | - GotoIfForceSlowPath(if_slow); |
168 | | - TNode<Object> promise_fun = |
169 | | - LoadContextElement(native_context, Context::PROMISE_FUNCTION_INDEX); |
170 | | - GotoIfNot(TaggedEqual(promise_fun, constructor), if_slow); |
171 | | - Branch(IsPromiseResolveProtectorCellInvalid(), if_slow, if_fast); |
172 | | -} |
173 | | - |
174 | | -void PromiseBuiltinsAssembler::GotoIfNotPromiseResolveLookupChainIntact( |
175 | | - TNode<NativeContext> native_context, TNode<Object> constructor, |
176 | | - Label* if_slow) { |
177 | | - Label if_fast(this); |
178 | | - BranchIfPromiseResolveLookupChainIntact(native_context, constructor, &if_fast, |
179 | | - if_slow); |
180 | | - BIND(&if_fast); |
181 | | -} |
182 | | - |
183 | | -void PromiseBuiltinsAssembler::BranchIfPromiseSpeciesLookupChainIntact( |
184 | | - TNode<NativeContext> native_context, TNode<Map> promise_map, Label* if_fast, |
185 | | - Label* if_slow) { |
186 | | - TNode<Object> promise_prototype = |
187 | | - LoadContextElement(native_context, Context::PROMISE_PROTOTYPE_INDEX); |
188 | | - GotoIfForceSlowPath(if_slow); |
189 | | - GotoIfNot(TaggedEqual(LoadMapPrototype(promise_map), promise_prototype), |
190 | | - if_slow); |
191 | | - Branch(IsPromiseSpeciesProtectorCellInvalid(), if_slow, if_fast); |
| 33 | + return Allocate(PromiseReactionJobTask::kSizeOfAllPromiseReactionJobTasks); |
192 | 34 | } |
193 | 35 |
|
194 | | -void PromiseBuiltinsAssembler::BranchIfPromiseThenLookupChainIntact( |
195 | | - TNode<NativeContext> native_context, TNode<Map> receiver_map, |
196 | | - Label* if_fast, Label* if_slow) { |
197 | | - GotoIfForceSlowPath(if_slow); |
198 | | - GotoIfNot(IsJSPromiseMap(receiver_map), if_slow); |
199 | | - const TNode<Object> promise_prototype = |
200 | | - LoadContextElement(native_context, Context::PROMISE_PROTOTYPE_INDEX); |
201 | | - GotoIfNot(TaggedEqual(LoadMapPrototype(receiver_map), promise_prototype), |
202 | | - if_slow); |
203 | | - Branch(IsPromiseThenProtectorCellInvalid(), if_slow, if_fast); |
204 | | -} |
205 | | - |
206 | | -void PromiseBuiltinsAssembler::BranchIfAccessCheckFailed( |
207 | | - TNode<Context> context, TNode<Context> native_context, |
208 | | - TNode<Object> promise_constructor, TNode<Object> executor, |
209 | | - Label* if_noaccess) { |
210 | | - TVARIABLE(HeapObject, var_executor); |
211 | | - var_executor = CAST(executor); |
212 | | - Label has_access(this), call_runtime(this, Label::kDeferred); |
213 | | - |
214 | | - // If executor is a bound function, load the bound function until we've |
215 | | - // reached an actual function. |
216 | | - Label found_function(this), loop_over_bound_function(this, &var_executor); |
217 | | - Goto(&loop_over_bound_function); |
218 | | - BIND(&loop_over_bound_function); |
219 | | - { |
220 | | - TNode<Uint16T> executor_type = LoadInstanceType(var_executor.value()); |
221 | | - GotoIf(InstanceTypeEqual(executor_type, JS_FUNCTION_TYPE), &found_function); |
222 | | - GotoIfNot(InstanceTypeEqual(executor_type, JS_BOUND_FUNCTION_TYPE), |
223 | | - &call_runtime); |
224 | | - var_executor = LoadObjectField<HeapObject>( |
225 | | - var_executor.value(), JSBoundFunction::kBoundTargetFunctionOffset); |
226 | | - Goto(&loop_over_bound_function); |
227 | | - } |
228 | | - |
229 | | - // Load the context from the function and compare it to the Promise |
230 | | - // constructor's context. If they match, everything is fine, otherwise, bail |
231 | | - // out to the runtime. |
232 | | - BIND(&found_function); |
233 | | - { |
234 | | - TNode<Context> function_context = LoadObjectField<Context>( |
235 | | - var_executor.value(), JSFunction::kContextOffset); |
236 | | - TNode<NativeContext> native_function_context = |
237 | | - LoadNativeContext(function_context); |
238 | | - Branch(TaggedEqual(native_context, native_function_context), &has_access, |
239 | | - &call_runtime); |
240 | | - } |
241 | | - |
242 | | - BIND(&call_runtime); |
243 | | - { |
244 | | - Branch(TaggedEqual(CallRuntime(Runtime::kAllowDynamicFunction, context, |
245 | | - promise_constructor), |
246 | | - TrueConstant()), |
247 | | - &has_access, if_noaccess); |
248 | | - } |
249 | | - |
250 | | - BIND(&has_access); |
| 36 | +TNode<HeapObject> PromiseBuiltinsAssembler::AllocateJSPromise( |
| 37 | + TNode<Context> context) { |
| 38 | + return Allocate(JSPromise::kSizeWithEmbedderFields); |
251 | 39 | } |
252 | 40 |
|
253 | 41 | } // namespace internal |
|
0 commit comments