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

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

Issue 2487053002: [promises] Remove one runtime call to create_resolving_functions (Closed)
Patch Set: add dcheck 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
« no previous file with comments | « src/promise-utils.h ('k') | src/runtime/runtime.h » ('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/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 JSObject* PromiseUtils::GetPromise(Handle<Context> context) {
22 return JSObject::cast(context->get(kPromiseSlot));
23 }
24
25 Object* PromiseUtils::GetDebugEvent(Handle<Context> context) {
26 return context->get(kDebugEventSlot);
27 }
28
29 bool PromiseUtils::HasAlreadyVisited(Handle<Context> context) {
30 return Smi::cast(context->get(kAlreadyVisitedSlot))->value() != 0;
31 }
32
33 void PromiseUtils::SetAlreadyVisited(Handle<Context> context) {
34 context->set(kAlreadyVisitedSlot, Smi::FromInt(1));
35 }
36
37 void PromiseUtils::CreateResolvingFunctions(Isolate* isolate,
38 Handle<JSObject> promise,
39 Handle<Object> debug_event,
40 Handle<JSFunction>* resolve,
41 Handle<JSFunction>* reject) {
42 DCHECK(debug_event->IsTrue(isolate) || debug_event->IsFalse(isolate));
43 Handle<Context> context =
44 isolate->factory()->NewPromiseResolvingFunctionContext(
45 kPromiseContextLength);
46 context->set_native_context(*isolate->native_context());
47 context->set(kAlreadyVisitedSlot, Smi::kZero);
48 context->set(kPromiseSlot, *promise);
49 context->set(kDebugEventSlot, *debug_event);
50
51 Handle<SharedFunctionInfo> resolve_shared_fun(
52 isolate->native_context()->promise_resolve_shared_fun(), isolate);
53 Handle<JSFunction> resolve_fun =
54 isolate->factory()->NewFunctionFromSharedFunctionInfo(
55 isolate->sloppy_function_without_prototype_map(), resolve_shared_fun,
56 isolate->native_context(), TENURED);
57
58 Handle<SharedFunctionInfo> reject_shared_fun(
59 isolate->native_context()->promise_reject_shared_fun(), isolate);
60 Handle<JSFunction> reject_fun =
61 isolate->factory()->NewFunctionFromSharedFunctionInfo(
62 isolate->sloppy_function_without_prototype_map(), reject_shared_fun,
63 isolate->native_context(), TENURED);
64
65 resolve_fun->set_context(*context);
66 reject_fun->set_context(*context);
67
68 *resolve = resolve_fun;
69 *reject = reject_fun;
70 }
71
72 } // namespace internal
73 } // namespace v8
OLDNEW
« no previous file with comments | « src/promise-utils.h ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698