Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(482)

Side by Side Diff: src/builtins/builtins-promise.cc

Issue 2567033003: [promises] Port CreateResolvingFunctions to TF (Closed)
Patch Set: fix nits Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/builtins/builtins-promise.h ('k') | src/code-stub-assembler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 4
5 #include "src/builtins/builtins-promise.h" 5 #include "src/builtins/builtins-promise.h"
6 #include "src/builtins/builtins-utils.h" 6 #include "src/builtins/builtins-utils.h"
7 #include "src/builtins/builtins.h" 7 #include "src/builtins/builtins.h"
8 #include "src/code-factory.h" 8 #include "src/code-factory.h"
9 #include "src/code-stub-assembler.h" 9 #include "src/code-stub-assembler.h"
10 #include "src/promise-utils.h" 10 #include "src/promise-utils.h"
11 11
12 namespace v8 { 12 namespace v8 {
13 namespace internal { 13 namespace internal {
14 14
15 typedef compiler::Node Node; 15 typedef compiler::Node Node;
16 typedef CodeStubAssembler::ParameterMode ParameterMode; 16 typedef CodeStubAssembler::ParameterMode ParameterMode;
17 typedef compiler::CodeAssemblerState CodeAssemblerState; 17 typedef compiler::CodeAssemblerState CodeAssemblerState;
18 18
19 Node* PromiseBuiltinsAssembler::CreatePromiseResolvingFunctionsContext(
20 Node* promise, Node* debug_event, Node* native_context) {
21 Node* const context =
22 Allocate(FixedArray::SizeFor(PromiseUtils::kPromiseContextLength));
23 StoreMapNoWriteBarrier(context, Heap::kFunctionContextMapRootIndex);
24 StoreObjectFieldNoWriteBarrier(
25 context, FixedArray::kLengthOffset,
26 SmiConstant(PromiseUtils::kPromiseContextLength));
27
28 Node* const empty_fn =
29 LoadContextElement(native_context, Context::CLOSURE_INDEX);
30 StoreContextElementNoWriteBarrier(context, Context::CLOSURE_INDEX, empty_fn);
31 StoreContextElementNoWriteBarrier(context, Context::PREVIOUS_INDEX,
32 UndefinedConstant());
33 StoreContextElementNoWriteBarrier(context, Context::EXTENSION_INDEX,
34 TheHoleConstant());
35 StoreContextElementNoWriteBarrier(context, Context::NATIVE_CONTEXT_INDEX,
36 native_context);
37 StoreContextElementNoWriteBarrier(context, PromiseUtils::kAlreadyVisitedSlot,
38 SmiConstant(0));
39 StoreContextElementNoWriteBarrier(context, PromiseUtils::kPromiseSlot,
40 promise);
41 StoreContextElementNoWriteBarrier(context, PromiseUtils::kDebugEventSlot,
42 debug_event);
43 return context;
44 }
45
46 std::pair<Node*, Node*>
47 PromiseBuiltinsAssembler::CreatePromiseResolvingFunctions(
48 Node* promise, Node* debug_event, Node* native_context) {
49 Node* const promise_context = CreatePromiseResolvingFunctionsContext(
50 promise, debug_event, native_context);
51 Node* const map = LoadContextElement(
52 native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
53 Node* const resolve_info =
54 LoadContextElement(native_context, Context::PROMISE_RESOLVE_SHARED_FUN);
55 Node* const resolve =
56 AllocateFunctionWithMapAndContext(map, resolve_info, promise_context);
57 Node* const reject_info =
58 LoadContextElement(native_context, Context::PROMISE_REJECT_SHARED_FUN);
59 Node* const reject =
60 AllocateFunctionWithMapAndContext(map, reject_info, promise_context);
61
62 return std::make_pair(resolve, reject);
63 }
64
19 Node* PromiseBuiltinsAssembler::ThrowIfNotJSReceiver( 65 Node* PromiseBuiltinsAssembler::ThrowIfNotJSReceiver(
20 Node* context, Node* value, MessageTemplate::Template msg_template) { 66 Node* context, Node* value, MessageTemplate::Template msg_template) {
21 Label out(this), throw_exception(this, Label::kDeferred); 67 Label out(this), throw_exception(this, Label::kDeferred);
22 Variable var_value_map(this, MachineRepresentation::kTagged); 68 Variable var_value_map(this, MachineRepresentation::kTagged);
23 69
24 GotoIf(TaggedIsSmi(value), &throw_exception); 70 GotoIf(TaggedIsSmi(value), &throw_exception);
25 71
26 // Load the instance type of the {value}. 72 // Load the instance type of the {value}.
27 var_value_map.Bind(LoadMap(value)); 73 var_value_map.Bind(LoadMap(value));
28 Node* const value_instance_type = LoadMapInstanceType(var_value_map.value()); 74 Node* const value_instance_type = LoadMapInstanceType(var_value_map.value());
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 Handle<Object> argv[] = {promise, value, debug_event}; 552 Handle<Object> argv[] = {promise, value, debug_event};
507 RETURN_FAILURE_ON_EXCEPTION( 553 RETURN_FAILURE_ON_EXCEPTION(
508 isolate, Execution::Call(isolate, isolate->promise_internal_reject(), 554 isolate, Execution::Call(isolate, isolate->promise_internal_reject(),
509 isolate->factory()->undefined_value(), 555 isolate->factory()->undefined_value(),
510 arraysize(argv), argv)); 556 arraysize(argv), argv));
511 return isolate->heap()->undefined_value(); 557 return isolate->heap()->undefined_value();
512 } 558 }
513 559
514 // ES#sec-createresolvingfunctions 560 // ES#sec-createresolvingfunctions
515 // CreateResolvingFunctions ( promise ) 561 // CreateResolvingFunctions ( promise )
516 BUILTIN(CreateResolvingFunctions) { 562 TF_BUILTIN(CreateResolvingFunctions, PromiseBuiltinsAssembler) {
517 HandleScope scope(isolate); 563 Node* const promise = Parameter(1);
518 DCHECK_EQ(3, args.length()); 564 Node* const debug_event = Parameter(2);
565 Node* const context = Parameter(5);
566 Node* const native_context = LoadNativeContext(context);
519 567
520 Handle<JSObject> promise = args.at<JSObject>(1); 568 Node* resolve = nullptr;
521 Handle<Object> debug_event = args.at<Object>(2); 569 Node* reject = nullptr;
522 Handle<JSFunction> resolve, reject;
523 570
524 PromiseUtils::CreateResolvingFunctions(isolate, promise, debug_event, 571 std::tie(resolve, reject) =
525 &resolve, &reject); 572 CreatePromiseResolvingFunctions(promise, debug_event, native_context);
526 573
527 Handle<FixedArray> result = isolate->factory()->NewFixedArray(2); 574 Node* const kSize = IntPtrConstant(2);
528 result->set(0, *resolve); 575 const ElementsKind kind = FAST_ELEMENTS;
529 result->set(1, *reject); 576 const WriteBarrierMode barrier_mode = SKIP_WRITE_BARRIER;
577 const ParameterMode parameter_mode = INTPTR_PARAMETERS;
578 Node* const arr = AllocateFixedArray(kind, kSize, parameter_mode);
579 StoreFixedArrayElement(arr, 0, resolve, barrier_mode);
580 StoreFixedArrayElement(arr, 1, reject, barrier_mode);
530 581
531 return *isolate->factory()->NewJSArrayWithElements(result, FAST_ELEMENTS, 2, 582 Node* const array_map = LoadJSArrayElementsMap(kind, native_context);
532 NOT_TENURED); 583 Node* const length = SmiTag(kSize);
584 Node* const result = AllocateUninitializedJSArrayWithoutElements(
585 kind, array_map, length, nullptr);
586
587 StoreObjectField(result, JSObject::kElementsOffset, arr);
588 Return(result);
533 } 589 }
534 590
535 TF_BUILTIN(PromiseConstructor, PromiseBuiltinsAssembler) { 591 TF_BUILTIN(PromiseConstructor, PromiseBuiltinsAssembler) {
536 Node* const executor = Parameter(1); 592 Node* const executor = Parameter(1);
537 Node* const new_target = Parameter(2); 593 Node* const new_target = Parameter(2);
538 Node* const context = Parameter(4); 594 Node* const context = Parameter(4);
539 Isolate* isolate = this->isolate(); 595 Isolate* isolate = this->isolate();
540 596
541 Label if_targetisundefined(this, Label::kDeferred); 597 Label if_targetisundefined(this, Label::kDeferred);
542 598
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 Bind(&debug_push); 649 Bind(&debug_push);
594 { 650 {
595 CallRuntime(Runtime::kDebugPushPromise, context, var_result.value()); 651 CallRuntime(Runtime::kDebugPushPromise, context, var_result.value());
596 Goto(&run_executor); 652 Goto(&run_executor);
597 } 653 }
598 654
599 Bind(&run_executor); 655 Bind(&run_executor);
600 { 656 {
601 Label out(this), if_rejectpromise(this), debug_pop(this, Label::kDeferred); 657 Label out(this), if_rejectpromise(this), debug_pop(this, Label::kDeferred);
602 658
603 // TODO(gsathya): Move this to TF. 659 Node *resolve, *reject;
604 Node* const resolving_functions = CallRuntime( 660 std::tie(resolve, reject) = CreatePromiseResolvingFunctions(
605 Runtime::kCreateResolvingFunctions, context, var_result.value()); 661 var_result.value(), TrueConstant(), native_context);
606 Node* const resolve =
607 LoadFixedArrayElement(resolving_functions, IntPtrConstant(0));
608 Node* const reject =
609 LoadFixedArrayElement(resolving_functions, IntPtrConstant(1));
610 Callable call_callable = CodeFactory::Call(isolate); 662 Callable call_callable = CodeFactory::Call(isolate);
611 663
612 Node* const maybe_exception = CallJS(call_callable, context, executor, 664 Node* const maybe_exception = CallJS(call_callable, context, executor,
613 UndefinedConstant(), resolve, reject); 665 UndefinedConstant(), resolve, reject);
614 666
615 GotoIfException(maybe_exception, &if_rejectpromise, &var_reason); 667 GotoIfException(maybe_exception, &if_rejectpromise, &var_reason);
616 Branch(is_debug_active, &debug_pop, &out); 668 Branch(is_debug_active, &debug_pop, &out);
617 669
618 Bind(&if_rejectpromise); 670 Bind(&if_rejectpromise);
619 { 671 {
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 CallRuntime(Runtime::kDebugPopPromise, context); 985 CallRuntime(Runtime::kDebugPopPromise, context);
934 Goto(&out); 986 Goto(&out);
935 987
936 Bind(&out); 988 Bind(&out);
937 Return(UndefinedConstant()); 989 Return(UndefinedConstant());
938 } 990 }
939 } 991 }
940 992
941 } // namespace internal 993 } // namespace internal
942 } // namespace v8 994 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins/builtins-promise.h ('k') | src/code-stub-assembler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698