Index: src/builtins/builtins-async-await.cc |
diff --git a/src/builtins/builtins-async-await.cc b/src/builtins/builtins-async-await.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d8a11897fcf87df62761396e8c558ee475a8fd4f |
--- /dev/null |
+++ b/src/builtins/builtins-async-await.cc |
@@ -0,0 +1,69 @@ |
+// Copyright 2017 the V8 project authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "src/builtins/builtins-promise.h" |
+#include "src/builtins/builtins-utils.h" |
+#include "src/builtins/builtins.h" |
+#include "src/code-stub-assembler.h" |
+ |
+namespace v8 { |
+namespace internal { |
+ |
+typedef compiler::Node Node; |
+typedef CodeStubAssembler::ParameterMode ParameterMode; |
+typedef compiler::CodeAssemblerState CodeAssemblerState; |
+ |
+class AsyncAwaitBuiltinsAssembler : public PromiseBuiltinsAssembler { |
+ public: |
+ explicit AsyncAwaitBuiltinsAssembler(CodeAssemblerState* state) |
+ : PromiseBuiltinsAssembler(state) {} |
+}; |
+ |
+TF_BUILTIN(AsyncFunctionPromiseCreate, AsyncAwaitBuiltinsAssembler) { |
+ CSA_ASSERT_JS_ARGC_EQ(this, 0); |
+ Node* const context = Parameter(3); |
+ |
+ Node* const parent = UndefinedConstant(); |
+ Node* const promise = AllocateAndInitJSPromise(context, parent); |
gsathya
2017/01/18 18:58:42
You don't need the parent here, default is undefin
jgruber
2017/01/19 08:58:11
Done.
|
+ |
+ Label if_is_debug_active(this, Label::kDeferred); |
+ GotoIf(IsDebugActive(), &if_is_debug_active); |
+ |
+ // Early exit if debug is not active. |
+ Return(promise); |
+ |
+ Bind(&if_is_debug_active); |
+ { |
+ // Push the Promise under construction in an async function on |
+ // the catch prediction stack to handle exceptions thrown before |
+ // the first await. |
+ // Assign ID and create a recurring task to save stack for future |
+ // resumptions from await. |
+ CallRuntime(Runtime::kDebugAsyncFunctionPromiseCreated, context, promise); |
+ Return(promise); |
+ } |
+} |
+ |
+TF_BUILTIN(AsyncFunctionPromiseRelease, AsyncAwaitBuiltinsAssembler) { |
+ CSA_ASSERT_JS_ARGC_EQ(this, 1); |
+ Node* const promise = Parameter(1); |
+ Node* const context = Parameter(4); |
+ |
+ Label if_is_debug_active(this, Label::kDeferred); |
+ GotoIf(IsDebugActive(), &if_is_debug_active); |
+ |
+ // Early exit if debug is not active. |
+ Return(UndefinedConstant()); |
+ |
+ Bind(&if_is_debug_active); |
+ { |
+ // Pop the Promise under construction in an async function on |
+ // from catch prediction stack. |
+ CallRuntime(Runtime::kDebugPopPromise, context); |
+ Return(promise); |
+ } |
+} |
+ |
+} // namespace internal |
+} // namespace v8 |