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

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

Issue 2459283004: [promises] Move CreateResolvingFunctions to c++ (Closed)
Patch Set: Remove header Created 4 years, 1 month 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
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 #include "src/builtins/builtins-utils.h"
5 #include "src/builtins/builtins.h"
6
7 namespace v8 {
8 namespace internal {
9
10 enum PromiseResolvingFunctionContextSlot {
11 kAlreadyVisitedSlot = 4,
adamk 2016/11/09 00:06:23 Should this 4 be Context::MIN_CONTEXT_SLOTS or som
gsathya 2016/11/09 00:57:33 Done.
12 kPromiseSlot,
13 kDebugEventSlot,
14 };
15
16 BUILTIN(PromiseResolveClosure) {
adamk 2016/11/09 00:06:23 Can you add a comment here about what this relates
gsathya 2016/11/09 00:57:33 Done.
17 HandleScope scope(isolate);
18
19 Handle<Object> value = args.atOrUndefined(isolate, 1);
adamk 2016/11/09 00:06:23 Please move this down to where it's actually used,
gsathya 2016/11/09 00:57:33 Done.
20 Handle<Context> context(isolate->context(), isolate);
21 Handle<Smi> already_visited(Smi::cast(context->get(kAlreadyVisitedSlot)),
22 isolate);
23
24 if (already_visited->value() != 0) {
25 return isolate->heap()->undefined_value();
26 }
27
28 context->set(kAlreadyVisitedSlot, Smi::FromInt(1));
29 Handle<JSObject> promise(JSObject::cast(context->get(kPromiseSlot)), isolate);
30
31 MaybeHandle<Object> maybe_result;
32 Handle<Object> argv[] = {promise, value};
33 maybe_result = Execution::Call(isolate, isolate->promise_resolve(),
adamk 2016/11/09 00:06:23 RETURN_FAILURE_ON_EXCEPTION here, I think.
gsathya 2016/11/09 00:57:33 Done.
34 isolate->factory()->undefined_value(),
35 arraysize(argv), argv);
36 return isolate->heap()->undefined_value();
37 }
38
39 BUILTIN(PromiseRejectClosure) {
adamk 2016/11/09 00:06:23 Same here, spec reference? And below.
gsathya 2016/11/09 00:57:33 Done.
40 HandleScope scope(isolate);
41
42 Handle<Object> value = args.atOrUndefined(isolate, 1);
adamk 2016/11/09 00:06:23 Same thing, this can move down to where it's used.
gsathya 2016/11/09 00:57:33 Done.
43 Handle<Context> context(isolate->context(), isolate);
44 Handle<Smi> already_visited(Smi::cast(context->get(kAlreadyVisitedSlot)),
45 isolate);
46
47 if (already_visited->value() != 0) {
48 return isolate->heap()->undefined_value();
49 }
50
51 context->set(kAlreadyVisitedSlot, Smi::FromInt(1));
52
53 Handle<JSObject> promise(JSObject::cast(context->get(kPromiseSlot)), isolate);
54 Handle<Object> debug_event(context->get(kDebugEventSlot), isolate);
55 MaybeHandle<Object> maybe_result;
56 Handle<Object> argv[] = {promise, value, debug_event};
57 maybe_result = Execution::Call(isolate, isolate->promise_internal_reject(),
adamk 2016/11/09 00:06:23 RETURN_FAILURE_ON_EXCEPTION
gsathya 2016/11/09 00:57:33 Done.
58 isolate->factory()->undefined_value(),
59 arraysize(argv), argv);
60 return isolate->heap()->undefined_value();
61 }
62
63 BUILTIN(CreateResolvingFunctions) {
64 HandleScope scope(isolate);
65 DCHECK_EQ(3, args.length());
66
67 Handle<JSObject> promise = args.at<JSObject>(1);
68 Handle<Object> debug_event = args.at<Object>(2);
69
70 Handle<Context> context =
71 isolate->factory()->NewPromiseResolvingFunctionContext();
72 context->set_native_context(*isolate->native_context());
73 context->set(kAlreadyVisitedSlot, Smi::kZero);
74 context->set(kPromiseSlot, *promise);
75 context->set(kDebugEventSlot, *debug_event);
76
77 Handle<SharedFunctionInfo> resolve_shared_fun(
78 isolate->native_context()->promise_resolve_shared_fun(), isolate);
79 Handle<JSFunction> resolve =
80 isolate->factory()->NewFunctionFromSharedFunctionInfo(
81 isolate->sloppy_function_without_prototype_map(), resolve_shared_fun,
82 isolate->native_context(), TENURED);
83
84 Handle<SharedFunctionInfo> reject_shared_fun(
85 isolate->native_context()->promise_reject_shared_fun(), isolate);
86 Handle<JSFunction> reject =
87 isolate->factory()->NewFunctionFromSharedFunctionInfo(
88 isolate->sloppy_function_without_prototype_map(), reject_shared_fun,
89 isolate->native_context(), TENURED);
90
91 resolve->set_context(*context);
92 reject->set_context(*context);
93
94 Handle<FixedArray> result = isolate->factory()->NewFixedArray(2);
95 result->set(0, *resolve);
96 result->set(1, *reject);
97
98 return *isolate->factory()->NewJSArrayWithElements(result, FAST_ELEMENTS, 2,
99 NOT_TENURED);
100 }
101
102 } // namespace internal
103 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins/builtins.h ('k') | src/contexts.h » ('j') | src/factory.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698