Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 #include "src/code-stub-assembler.h" | 4 #include "src/code-stub-assembler.h" |
| 5 #include "src/code-factory.h" | 5 #include "src/code-factory.h" |
| 6 #include "src/frames-inl.h" | 6 #include "src/frames-inl.h" |
| 7 #include "src/frames.h" | 7 #include "src/frames.h" |
| 8 #include "src/promise-utils.h" | |
| 8 | 9 |
| 9 namespace v8 { | 10 namespace v8 { |
| 10 namespace internal { | 11 namespace internal { |
| 11 | 12 |
| 12 using compiler::Node; | 13 using compiler::Node; |
| 13 | 14 |
| 14 void CodeStubAssembler::Assert(const NodeGenerator& codition_body, | 15 void CodeStubAssembler::Assert(const NodeGenerator& codition_body, |
| 15 const char* message, const char* file, | 16 const char* message, const char* file, |
| 16 int line) { | 17 int line) { |
| 17 #if defined(DEBUG) | 18 #if defined(DEBUG) |
| (...skipping 8197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8215 } | 8216 } |
| 8216 | 8217 |
| 8217 Node* CodeStubAssembler::IsPromiseHookEnabled() { | 8218 Node* CodeStubAssembler::IsPromiseHookEnabled() { |
| 8218 Node* const is_promisehook_enabled = | 8219 Node* const is_promisehook_enabled = |
| 8219 Load(MachineType::Uint8(), | 8220 Load(MachineType::Uint8(), |
| 8220 ExternalConstant( | 8221 ExternalConstant( |
| 8221 ExternalReference::is_promisehook_enabled_address(isolate()))); | 8222 ExternalReference::is_promisehook_enabled_address(isolate()))); |
| 8222 return WordNotEqual(is_promisehook_enabled, Int32Constant(0)); | 8223 return WordNotEqual(is_promisehook_enabled, Int32Constant(0)); |
| 8223 } | 8224 } |
| 8224 | 8225 |
| 8226 Node* CodeStubAssembler::AllocateFunctionWithMapAndContext(Node* map, | |
|
jgruber
2016/12/13 10:44:04
Wouldn't 'AllocateFunction' be simpler (since this
gsathya
2016/12/13 13:01:46
Seemed like there's precedent with AllocateHeapNum
jgruber
2016/12/13 13:20:52
Ok, let's wait and see what Igor says, CSA is his
gsathya
2016/12/13 13:29:33
Acknowledged.
Igor Sheludko
2016/12/13 23:42:34
Let this function be :)
| |
| 8227 Node* shared_info, | |
| 8228 Node* context) { | |
| 8229 Node* const code = | |
| 8230 LoadObjectField(shared_info, SharedFunctionInfo::kCodeOffset); | |
| 8231 Node* code_entry = | |
|
jgruber
2016/12/13 10:44:04
Why is this one not const? Same below - if you're
gsathya
2016/12/13 13:01:46
I guess. Changed
| |
| 8232 IntPtrAdd(code, IntPtrConstant(Code::kHeaderSize - kHeapObjectTag)); | |
| 8233 | |
| 8234 Node* fun = Allocate(JSFunction::kSize); | |
| 8235 StoreMapNoWriteBarrier(fun, map); | |
| 8236 StoreObjectFieldRoot(fun, JSObject::kPropertiesOffset, | |
| 8237 Heap::kEmptyFixedArrayRootIndex); | |
| 8238 StoreObjectFieldRoot(fun, JSObject::kElementsOffset, | |
| 8239 Heap::kEmptyFixedArrayRootIndex); | |
| 8240 StoreObjectFieldRoot(fun, JSFunction::kLiteralsOffset, | |
| 8241 Heap::kEmptyLiteralsArrayRootIndex); | |
| 8242 StoreObjectFieldRoot(fun, JSFunction::kPrototypeOrInitialMapOffset, | |
| 8243 Heap::kTheHoleValueRootIndex); | |
| 8244 StoreObjectFieldNoWriteBarrier(fun, JSFunction::kSharedFunctionInfoOffset, | |
| 8245 shared_info); | |
| 8246 StoreObjectFieldNoWriteBarrier(fun, JSFunction::kContextOffset, context); | |
| 8247 StoreObjectFieldNoWriteBarrier(fun, JSFunction::kCodeEntryOffset, code_entry); | |
| 8248 StoreObjectFieldRoot(fun, JSFunction::kNextFunctionLinkOffset, | |
| 8249 Heap::kUndefinedValueRootIndex); | |
| 8250 | |
| 8251 return fun; | |
| 8252 } | |
| 8253 | |
| 8254 Node* CodeStubAssembler::CreatePromiseResolvingFunctionsContext( | |
| 8255 Node* promise, Node* debug_event, Node* native_context) { | |
| 8256 Node* context = | |
| 8257 Allocate(FixedArray::SizeFor(PromiseUtils::kPromiseContextLength)); | |
| 8258 Node* map = HeapConstant(isolate()->factory()->function_context_map()); | |
| 8259 StoreMapNoWriteBarrier(context, map); | |
| 8260 StoreObjectFieldNoWriteBarrier( | |
| 8261 context, FixedArray::kLengthOffset, | |
| 8262 SmiConstant(PromiseUtils::kPromiseContextLength)); | |
| 8263 | |
| 8264 Node* empty_fn = LoadContextElement(native_context, Context::CLOSURE_INDEX); | |
| 8265 StoreContextElement(context, Context::CLOSURE_INDEX, empty_fn); | |
|
jgruber
2016/12/13 10:44:04
Perhaps this could be refactored to a more generic
gsathya
2016/12/13 13:01:47
All of these are pretty specific to promise
jgruber
2016/12/13 13:20:52
Really? Isn't this almost identical to Factory::Ne
gsathya
2016/12/13 13:29:33
Can't have the FUNCTION_SCOPE check, can't set pre
| |
| 8266 StoreContextElement(context, Context::PREVIOUS_INDEX, UndefinedConstant()); | |
| 8267 StoreContextElement(context, Context::EXTENSION_INDEX, TheHoleConstant()); | |
| 8268 StoreContextElement(context, Context::NATIVE_CONTEXT_INDEX, native_context); | |
| 8269 StoreContextElement(context, PromiseUtils::kAlreadyVisitedSlot, | |
| 8270 SmiConstant(0)); | |
| 8271 StoreContextElement(context, PromiseUtils::kPromiseSlot, promise); | |
| 8272 StoreContextElement(context, PromiseUtils::kDebugEventSlot, debug_event); | |
| 8273 return context; | |
| 8274 } | |
| 8275 | |
| 8276 std::pair<Node*, Node*> CodeStubAssembler::CreatePromiseResolvingFunctions( | |
|
jgruber
2016/12/13 10:44:05
This would probably be better as a member of the P
gsathya
2016/12/13 13:01:46
These will be used in other builtins I think. cait
Igor Sheludko
2016/12/13 23:42:34
+1. Maybe there should be an assembler class with
| |
| 8277 Node* promise, Node* debug_event, Node* native_context) { | |
| 8278 Node* promise_context = CreatePromiseResolvingFunctionsContext( | |
| 8279 promise, debug_event, native_context); | |
| 8280 Node* resolve_info = | |
| 8281 LoadContextElement(native_context, Context::PROMISE_RESOLVE_SHARED_FUN); | |
| 8282 Node* reject_info = | |
| 8283 LoadContextElement(native_context, Context::PROMISE_REJECT_SHARED_FUN); | |
| 8284 | |
| 8285 Node* const map = LoadContextElement( | |
| 8286 native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX); | |
| 8287 Node* const resolve = | |
| 8288 AllocateFunctionWithMapAndContext(map, resolve_info, promise_context); | |
| 8289 Node* const reject = | |
| 8290 AllocateFunctionWithMapAndContext(map, reject_info, promise_context); | |
| 8291 | |
| 8292 return std::make_pair(resolve, reject); | |
| 8293 } | |
| 8294 | |
| 8225 Node* CodeStubAssembler::AllocateJSPromise(Node* context) { | 8295 Node* CodeStubAssembler::AllocateJSPromise(Node* context) { |
| 8226 Node* const native_context = LoadNativeContext(context); | 8296 Node* const native_context = LoadNativeContext(context); |
| 8227 Node* const promise_fun = | 8297 Node* const promise_fun = |
| 8228 LoadContextElement(native_context, Context::PROMISE_FUNCTION_INDEX); | 8298 LoadContextElement(native_context, Context::PROMISE_FUNCTION_INDEX); |
| 8229 Node* const initial_map = | 8299 Node* const initial_map = |
| 8230 LoadObjectField(promise_fun, JSFunction::kPrototypeOrInitialMapOffset); | 8300 LoadObjectField(promise_fun, JSFunction::kPrototypeOrInitialMapOffset); |
| 8231 Node* const instance = AllocateJSObjectFromMap(initial_map); | 8301 Node* const instance = AllocateJSObjectFromMap(initial_map); |
| 8232 | 8302 |
| 8233 return instance; | 8303 return instance; |
| 8234 } | 8304 } |
| 8235 | 8305 |
| 8236 void CodeStubAssembler::PromiseInit(Node* promise) { | 8306 void CodeStubAssembler::PromiseInit(Node* promise) { |
| 8237 StoreObjectField(promise, JSPromise::kStatusOffset, | 8307 StoreObjectField(promise, JSPromise::kStatusOffset, |
| 8238 SmiConstant(kPromisePending)); | 8308 SmiConstant(kPromisePending)); |
| 8239 StoreObjectField(promise, JSPromise::kFlagsOffset, SmiConstant(0)); | 8309 StoreObjectField(promise, JSPromise::kFlagsOffset, SmiConstant(0)); |
| 8240 } | 8310 } |
| 8241 | 8311 |
| 8242 void CodeStubAssembler::PromiseSet(Node* promise, Node* status, Node* result) { | 8312 void CodeStubAssembler::PromiseSet(Node* promise, Node* status, Node* result) { |
| 8243 CSA_ASSERT(this, TaggedIsSmi(status)); | 8313 CSA_ASSERT(this, TaggedIsSmi(status)); |
| 8244 StoreObjectField(promise, JSPromise::kStatusOffset, status); | 8314 StoreObjectField(promise, JSPromise::kStatusOffset, status); |
| 8245 StoreObjectField(promise, JSPromise::kResultOffset, result); | 8315 StoreObjectField(promise, JSPromise::kResultOffset, result); |
| 8246 StoreObjectField(promise, JSPromise::kFlagsOffset, SmiConstant(0)); | 8316 StoreObjectField(promise, JSPromise::kFlagsOffset, SmiConstant(0)); |
| 8247 } | 8317 } |
| 8248 | 8318 |
| 8249 } // namespace internal | 8319 } // namespace internal |
| 8250 } // namespace v8 | 8320 } // namespace v8 |
| OLD | NEW |