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

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

Issue 2635353002: [builtins] introduce AsyncBuiltinsAssembler for ES2016 features and beyond (Closed)
Patch Set: add some comments to make it easier to read the code Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/builtins/builtins-async.h ('k') | src/builtins/builtins-promise.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins/builtins-async.cc
diff --git a/src/builtins/builtins-async.cc b/src/builtins/builtins-async.cc
new file mode 100644
index 0000000000000000000000000000000000000000..061ab535aa98a8c98f40d4e930ff7072664d4f76
--- /dev/null
+++ b/src/builtins/builtins-async.cc
@@ -0,0 +1,93 @@
+// Copyright 2016 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-async.h"
+#include "src/builtins/builtins-utils.h"
+#include "src/builtins/builtins.h"
+#include "src/code-factory.h"
+#include "src/code-stub-assembler.h"
+#include "src/frames-inl.h"
+
+namespace v8 {
+namespace internal {
+
+Node* AsyncBuiltinsAssembler::Await(
+ Node* context, Node* generator, Node* value, Node* outer_promise,
+ const NodeGenerator1& create_closure_context, int on_resolve_context_index,
+ int on_reject_context_index, bool is_catchable) {
+ // Let promiseCapability be ! NewPromiseCapability(%Promise%).
+ Node* const wrapped_value = AllocateAndInitJSPromise(context);
+
+ // Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »).
+ InternalResolvePromise(context, wrapped_value, value);
+
+ Node* const native_context = LoadNativeContext(context);
+
+ Node* const closure_context = create_closure_context(native_context);
+ Node* const map = LoadContextElement(
+ native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
+
+ // Load and allocate on_resolve closure
+ Node* const on_resolve_shared_fun =
+ LoadContextElement(native_context, on_resolve_context_index);
+ CSA_SLOW_ASSERT(
+ this, HasInstanceType(on_resolve_shared_fun, SHARED_FUNCTION_INFO_TYPE));
+ Node* const on_resolve = AllocateFunctionWithMapAndContext(
+ map, on_resolve_shared_fun, closure_context);
+
+ // Load and allocate on_reject closure
+ Node* const on_reject_shared_fun =
+ LoadContextElement(native_context, on_reject_context_index);
+ CSA_SLOW_ASSERT(
+ this, HasInstanceType(on_reject_shared_fun, SHARED_FUNCTION_INFO_TYPE));
+ Node* const on_reject = AllocateFunctionWithMapAndContext(
+ map, on_reject_shared_fun, closure_context);
+
+ Node* const throwaway_promise =
+ AllocateAndInitJSPromise(context, wrapped_value);
+
+ // The Promise will be thrown away and not handled, but it shouldn't trigger
+ // unhandled reject events as its work is done
+ PromiseSetHasHandler(throwaway_promise);
+
+ Label do_perform_promise_then(this);
+ GotoUnless(IsDebugActive(), &do_perform_promise_then);
+ {
+ Label common(this);
+ GotoUnless(HasInstanceType(value, JS_PROMISE_TYPE), &common);
+ {
+ // Mark the reject handler callback to be a forwarding edge, rather
+ // than a meaningful catch handler
+ Node* const key =
+ HeapConstant(factory()->promise_forwarding_handler_symbol());
+ CallRuntime(Runtime::kSetProperty, on_reject, key, TrueConstant(),
jgruber 2017/01/20 08:17:19 Just noticed that context is missing here as the s
+ SmiConstant(STRICT));
+
+ if (!is_catchable) {
+ PromiseSetHasHandler(value);
+ }
+ }
+
+ Goto(&common);
+ Bind(&common);
+ // Mark the dependency to outer Promise in case the throwaway Promise is
+ // found on the Promise stack
+ CSA_SLOW_ASSERT(this, HasInstanceType(outer_promise, JS_PROMISE_TYPE));
+
+ Node* const key = HeapConstant(factory()->promise_handled_by_symbol());
+ CallRuntime(Runtime::kSetProperty, throwaway_promise, key, outer_promise,
+ SmiConstant(STRICT));
+ }
+
+ Goto(&do_perform_promise_then);
+ Bind(&do_perform_promise_then);
+ InternalPerformPromiseThen(context, wrapped_value, on_resolve, on_reject,
+ throwaway_promise, UndefinedConstant(),
+ UndefinedConstant());
+
+ return wrapped_value;
+}
+
+} // namespace internal
+} // namespace v8
« no previous file with comments | « src/builtins/builtins-async.h ('k') | src/builtins/builtins-promise.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698