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

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

Issue 2622833002: WIP [esnext] implement async iteration proposal (Closed)
Patch Set: simplify AsyncIteratorValueUnwrap 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 unified diff | Download patch
« no previous file with comments | « src/builtins/builtins-async.h ('k') | src/builtins/builtins-async-generator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "src/builtins/builtins-async.h"
6 #include "src/builtins/builtins-utils.h"
7 #include "src/builtins/builtins.h"
8 #include "src/code-factory.h"
9 #include "src/code-stub-assembler.h"
10 #include "src/frames-inl.h"
11
12 namespace v8 {
13 namespace internal {
14
15 Node* AsyncBuiltinsAssembler::Await(
16 Node* context, Node* generator, Node* value, Node* outer_promise,
17 const NodeGenerator1& create_closure_context, int on_resolve_context_index,
18 int on_reject_context_index, bool is_catchable) {
19 // Let promiseCapability be ! NewPromiseCapability(%Promise%).
20 Node* const wrapped_value = AllocateAndInitJSPromise(context);
21
22 // Perform ! Call(promiseCapability.[[Resolve]], undefined, « promise »).
23 InternalResolvePromise(context, wrapped_value, value);
24
25 Node* const native_context = LoadNativeContext(context);
26
27 Node* const closure_context = create_closure_context(native_context);
28 Node* const map = LoadContextElement(
29 native_context, Context::STRICT_FUNCTION_WITHOUT_PROTOTYPE_MAP_INDEX);
30
31 Node* const on_reject_shared_fun =
32 LoadContextElement(native_context, on_reject_context_index);
33 CSA_SLOW_ASSERT(
34 this, HasInstanceType(on_reject_shared_fun, SHARED_FUNCTION_INFO_TYPE));
35 Node* const on_reject = AllocateFunctionWithMapAndContext(
36 map, on_reject_shared_fun, closure_context);
37
38 Node* const on_resolve_shared_fun =
39 LoadContextElement(native_context, on_resolve_context_index);
40 CSA_SLOW_ASSERT(
41 this, HasInstanceType(on_resolve_shared_fun, SHARED_FUNCTION_INFO_TYPE));
42 Node* const on_resolve = AllocateFunctionWithMapAndContext(
43 map, on_resolve_shared_fun, closure_context);
44
45 Node* const throwaway_promise =
46 AllocateAndInitJSPromise(context, wrapped_value);
47
48 // The Promise will be thrown away and not handled, but it shouldn't trigger
49 // unhandled reject events as its work is done
50 PromiseSetHasHandler(throwaway_promise);
51
52 Label do_perform_promise_then(this);
53 GotoUnless(IsDebugActive(), &do_perform_promise_then);
54 {
55 Label common(this);
56 GotoUnless(HasInstanceType(value, JS_PROMISE_TYPE), &common);
57 {
58 // Mark the reject handler callback to be a forwarding edge, rather
59 // than a meaningful catch handler
60 Node* const key =
61 HeapConstant(factory()->promise_forwarding_handler_symbol());
62 CallRuntime(Runtime::kSetProperty, on_reject, key, TrueConstant(),
63 SmiConstant(STRICT));
64
65 if (!is_catchable) {
66 PromiseSetHasHandler(value);
67 }
68 }
69
70 Goto(&common);
71 Bind(&common);
72 // Mark the dependency to outer Promise in case the throwaway Promise is
73 // found on the Promise stack
74 CSA_SLOW_ASSERT(this, HasInstanceType(outer_promise, JS_PROMISE_TYPE));
75
76 Node* const key = HeapConstant(factory()->promise_handled_by_symbol());
77 CallRuntime(Runtime::kSetProperty, throwaway_promise, key, outer_promise,
78 SmiConstant(STRICT));
79 }
80
81 Goto(&do_perform_promise_then);
82 Bind(&do_perform_promise_then);
83 InternalPerformPromiseThen(context, wrapped_value, on_resolve, on_reject,
84 throwaway_promise, UndefinedConstant(),
85 UndefinedConstant());
86
87 return wrapped_value;
88 }
89
90 } // namespace internal
91 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins/builtins-async.h ('k') | src/builtins/builtins-async-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698