Chromium Code Reviews

Unified Diff: src/builtins/builtins-promise.cc

Issue 2572623002: PromiseHandle port to TF (Closed)
Patch Set: create TFS Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
« no previous file with comments | « src/builtins/builtins.h ('k') | src/code-factory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins/builtins-promise.cc
diff --git a/src/builtins/builtins-promise.cc b/src/builtins/builtins-promise.cc
index aa38002218e744fd87a221fe753230a78487f337..ec88e203c969a2b110ab9b3c8a33c7bcf3251277 100644
--- a/src/builtins/builtins-promise.cc
+++ b/src/builtins/builtins-promise.cc
@@ -892,5 +892,131 @@ void Builtins::Generate_ResolvePromise(compiler::CodeAssemblerState* state) {
a.Return(a.UndefinedConstant());
}
+void Builtins::Generate_PromiseHandleReject(
Benedikt Meurer 2016/12/13 06:20:52 Why do you need to put this into a separate builti
+ compiler::CodeAssemblerState* state) {
+ CodeStubAssembler a(state);
+ typedef compiler::Node Node;
+ typedef CodeStubAssembler::Label Label;
+ typedef CodeStubAssembler::Variable Variable;
+
+ Node* const promise = a.Parameter(1);
+ Node* const on_reject = a.Parameter(2);
+ Node* const exception = a.Parameter(3);
+ Node* const context = a.Parameter(6);
+ Isolate* isolate = a.isolate();
+
+ Callable call_callable = CodeFactory::Call(isolate);
+ Variable var_unused(&a, MachineRepresentation::kTagged);
+
+ Label out(&a), if_internalhandler(&a), if_customhandler(&a, Label::kDeferred);
+ a.Branch(a.IsUndefined(on_reject), &if_internalhandler, &if_customhandler);
+
+ a.Bind(&if_internalhandler);
+ {
+ a.CallRuntime(Runtime::kPromiseReject, context, promise, exception,
+ a.FalseConstant());
+ a.Goto(&out);
+ }
+
+ a.Bind(&if_customhandler);
+ {
+ Node* const maybe_exception = a.CallJS(call_callable, context, on_reject,
+ a.UndefinedConstant(), exception);
+ // This doesn't do anything
+ a.GotoIfException(maybe_exception, &out, &var_unused);
+ a.Goto(&out);
+ }
+
+ a.Bind(&out);
+ a.Return(a.UndefinedConstant());
+}
+
+void Builtins::Generate_PromiseHandle(compiler::CodeAssemblerState* state) {
+ CodeStubAssembler a(state);
+ typedef compiler::Node Node;
+ typedef CodeStubAssembler::Label Label;
+ typedef CodeStubAssembler::Variable Variable;
+
+ Node* const value = a.Parameter(1);
+ Node* const handler = a.Parameter(2);
+ Node* const deferred = a.Parameter(3);
+ Node* const context = a.Parameter(6);
+ Isolate* isolate = a.isolate();
+
+ // Get promise from deferred
+ Callable getproperty_callable = CodeFactory::GetProperty(isolate);
+ Node* const key =
+ a.HeapConstant(isolate->factory()->NewStringFromAsciiChecked("promise"));
+ Node* const promise =
+ a.CallStub(getproperty_callable, context, deferred, key);
+
+ Variable var_reason(&a, MachineRepresentation::kTagged);
+
+ Node* const is_debug_active = a.IsDebugActive();
+ Label run_handler(&a), if_rejectpromise(&a), debug_push(&a, Label::kDeferred),
+ debug_pop(&a, Label::kDeferred);
+ a.Branch(is_debug_active, &debug_push, &run_handler);
+
+ a.Bind(&debug_push);
+ {
+ a.CallRuntime(Runtime::kDebugPushPromise, context, promise);
+ a.Goto(&run_handler);
+ }
+
+ a.Bind(&run_handler);
+ {
+ Callable call_callable = CodeFactory::Call(isolate);
+
+ Node* const result =
+ a.CallJS(call_callable, context, handler, a.UndefinedConstant(), value);
+
+ a.GotoIfException(result, &if_rejectpromise, &var_reason);
+
+ Node* const key = a.HeapConstant(
+ isolate->factory()->NewStringFromAsciiChecked("resolve"));
+ Node* const on_resolve =
+ a.CallStub(getproperty_callable, context, deferred, key);
+
+ Label if_internalhandler(&a), if_customhandler(&a, Label::kDeferred);
+ a.Branch(a.IsUndefined(on_resolve), &if_internalhandler, &if_customhandler);
+
+ a.Bind(&if_internalhandler);
+ InternalResolvePromise(&a, context, promise, result, &debug_pop);
+
+ a.Bind(&if_customhandler);
+ {
+ Node* const maybe_exception = a.CallJS(call_callable, context, on_resolve,
+ a.UndefinedConstant(), result);
+ a.GotoIfException(maybe_exception, &if_rejectpromise, &var_reason);
+ a.Goto(&debug_pop);
+ }
+ }
+
+ a.Bind(&if_rejectpromise);
+ {
+ Node* const key =
+ a.HeapConstant(isolate->factory()->NewStringFromAsciiChecked("reject"));
+ Node* const on_reject =
+ a.CallStub(getproperty_callable, context, deferred, key);
+
+ Callable promise_handle_reject = CodeFactory::PromiseHandleReject(isolate);
+ a.CallStub(promise_handle_reject, context, promise, on_reject,
+ var_reason.value());
+ a.Goto(&debug_pop);
+ }
+
+ a.Bind(&debug_pop);
+ {
+ Label out(&a);
+
+ a.GotoUnless(is_debug_active, &out);
+ a.CallRuntime(Runtime::kDebugPopPromise, context);
+ a.Goto(&out);
+
+ a.Bind(&out);
+ a.Return(a.UndefinedConstant());
+ }
+}
+
} // namespace internal
} // namespace v8
« no previous file with comments | « src/builtins/builtins.h ('k') | src/code-factory.h » ('j') | no next file with comments »

Powered by Google App Engine