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

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

Issue 2487053002: [promises] Remove one runtime call to create_resolving_functions (Closed)
Patch Set: rebase 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
5 #include "src/promise-utils.h"
6
7 #include "src/factory.h"
8 #include "src/isolate.h"
9 #include "src/objects-inl.h"
10
11 namespace v8 {
12 namespace internal {
13
14 enum PromiseResolvingFunctionContextSlot {
15 kAlreadyVisitedSlot = Context::MIN_CONTEXT_SLOTS,
16 kPromiseSlot,
17 kDebugEventSlot,
18 kPromiseContextLength,
19 };
20
21 Handle<JSObject> PromiseUtils::GetPromise(Isolate* isolate,
adamk 2016/11/10 18:10:54 You could make these just return raw pointers, lea
gsathya 2016/11/11 02:34:37 Done.
22 Handle<Context> context) {
23 return handle(JSObject::cast(context->get(PromiseUtils::kPromiseSlot)),
adamk 2016/11/10 18:10:54 Hmm, looks like these need updating to refer to th
gsathya 2016/11/11 02:34:37 Done.
24 isolate);
25 }
26
27 Handle<Object> PromiseUtils::GetDebugEvent(Isolate* isolate,
28 Handle<Context> context) {
29 return handle(context->get(PromiseUtils::kDebugEventSlot), isolate);
30 }
31
32 Handle<Smi> PromiseUtils::GetAlreadyVisited(Isolate* isolate,
33 Handle<Context> context) {
34 return handle(Smi::cast(context->get(PromiseUtils::kAlreadyVisitedSlot)),
35 isolate);
36 }
37
38 void PromiseUtils::SetAlreadyVisitedToTrue(Handle<Context> context) {
39 context->set(PromiseUtils::kAlreadyVisitedSlot, Smi::FromInt(1));
40 }
41
42 void PromiseUtils::CreateResolvingFunctions(Isolate* isolate,
43 Handle<JSObject> promise,
44 Handle<Object> debug_event,
adamk 2016/11/10 18:10:54 Can you add the same DCHECK here for debug_event b
gsathya 2016/11/11 02:34:36 It seems redundant to have the same DCHECK in both
45 Handle<JSFunction>* resolve,
46 Handle<JSFunction>* reject) {
47 Handle<Context> context =
48 isolate->factory()->NewPromiseResolvingFunctionContext(
49 kPromiseContextLength);
50 context->set_native_context(*isolate->native_context());
51 context->set(kAlreadyVisitedSlot, Smi::kZero);
52 context->set(kPromiseSlot, *promise);
53 context->set(kDebugEventSlot, *debug_event);
54
55 Handle<SharedFunctionInfo> resolve_shared_fun(
56 isolate->native_context()->promise_resolve_shared_fun(), isolate);
57 Handle<JSFunction> resolve_fun =
58 isolate->factory()->NewFunctionFromSharedFunctionInfo(
59 isolate->sloppy_function_without_prototype_map(), resolve_shared_fun,
60 isolate->native_context(), TENURED);
61
62 Handle<SharedFunctionInfo> reject_shared_fun(
63 isolate->native_context()->promise_reject_shared_fun(), isolate);
64 Handle<JSFunction> reject_fun =
65 isolate->factory()->NewFunctionFromSharedFunctionInfo(
66 isolate->sloppy_function_without_prototype_map(), reject_shared_fun,
67 isolate->native_context(), TENURED);
68
69 resolve_fun->set_context(*context);
70 reject_fun->set_context(*context);
71
72 *resolve = resolve_fun;
73 *reject = reject_fun;
74 }
75
76 } // namespace internal
77 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698