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

Side by Side Diff: src/builtins/builtins-promise.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 | « BUILD.gn ('k') | src/factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4
4 #include "src/builtins/builtins-utils.h" 5 #include "src/builtins/builtins-utils.h"
5 #include "src/builtins/builtins.h" 6 #include "src/builtins/builtins.h"
6 7
8 #include "src/promise-utils.h"
9
7 namespace v8 { 10 namespace v8 {
8 namespace internal { 11 namespace internal {
9 12
10 enum PromiseResolvingFunctionContextSlot {
11 kAlreadyVisitedSlot = Context::MIN_CONTEXT_SLOTS,
12 kPromiseSlot,
13 kDebugEventSlot,
14 kPromiseContextLength,
15 };
16
17 // ES#sec-promise-resolve-functions 13 // ES#sec-promise-resolve-functions
18 // Promise Resolve Functions 14 // Promise Resolve Functions
19 BUILTIN(PromiseResolveClosure) { 15 BUILTIN(PromiseResolveClosure) {
20 HandleScope scope(isolate); 16 HandleScope scope(isolate);
21 17
22 Handle<Context> context(isolate->context(), isolate); 18 Handle<Context> context(isolate->context(), isolate);
23 Handle<Smi> already_visited(Smi::cast(context->get(kAlreadyVisitedSlot)),
24 isolate);
25 19
26 if (already_visited->value() != 0) { 20 if (PromiseUtils::HasAlreadyVisited(context)) {
27 return isolate->heap()->undefined_value(); 21 return isolate->heap()->undefined_value();
28 } 22 }
29 23
30 context->set(kAlreadyVisitedSlot, Smi::FromInt(1)); 24 PromiseUtils::SetAlreadyVisited(context);
31 Handle<JSObject> promise(JSObject::cast(context->get(kPromiseSlot)), isolate); 25 Handle<JSObject> promise = handle(PromiseUtils::GetPromise(context), isolate);
32 Handle<Object> value = args.atOrUndefined(isolate, 1); 26 Handle<Object> value = args.atOrUndefined(isolate, 1);
33 27
34 MaybeHandle<Object> maybe_result; 28 MaybeHandle<Object> maybe_result;
35 Handle<Object> argv[] = {promise, value}; 29 Handle<Object> argv[] = {promise, value};
36 RETURN_FAILURE_ON_EXCEPTION( 30 RETURN_FAILURE_ON_EXCEPTION(
37 isolate, Execution::Call(isolate, isolate->promise_resolve(), 31 isolate, Execution::Call(isolate, isolate->promise_resolve(),
38 isolate->factory()->undefined_value(), 32 isolate->factory()->undefined_value(),
39 arraysize(argv), argv)); 33 arraysize(argv), argv));
40 return isolate->heap()->undefined_value(); 34 return isolate->heap()->undefined_value();
41 } 35 }
42 36
43 // ES#sec-promise-reject-functions 37 // ES#sec-promise-reject-functions
44 // Promise Reject Functions 38 // Promise Reject Functions
45 BUILTIN(PromiseRejectClosure) { 39 BUILTIN(PromiseRejectClosure) {
46 HandleScope scope(isolate); 40 HandleScope scope(isolate);
47 41
48 Handle<Context> context(isolate->context(), isolate); 42 Handle<Context> context(isolate->context(), isolate);
49 Handle<Smi> already_visited(Smi::cast(context->get(kAlreadyVisitedSlot)),
50 isolate);
51 43
52 if (already_visited->value() != 0) { 44 if (PromiseUtils::HasAlreadyVisited(context)) {
53 return isolate->heap()->undefined_value(); 45 return isolate->heap()->undefined_value();
54 } 46 }
55 47
56 context->set(kAlreadyVisitedSlot, Smi::FromInt(1)); 48 PromiseUtils::SetAlreadyVisited(context);
57
58 Handle<Object> value = args.atOrUndefined(isolate, 1); 49 Handle<Object> value = args.atOrUndefined(isolate, 1);
59 Handle<JSObject> promise(JSObject::cast(context->get(kPromiseSlot)), isolate); 50 Handle<JSObject> promise = handle(PromiseUtils::GetPromise(context), isolate);
60 Handle<Object> debug_event(context->get(kDebugEventSlot), isolate); 51 Handle<Object> debug_event =
52 handle(PromiseUtils::GetDebugEvent(context), isolate);
61 MaybeHandle<Object> maybe_result; 53 MaybeHandle<Object> maybe_result;
62 Handle<Object> argv[] = {promise, value, debug_event}; 54 Handle<Object> argv[] = {promise, value, debug_event};
63 RETURN_FAILURE_ON_EXCEPTION( 55 RETURN_FAILURE_ON_EXCEPTION(
64 isolate, Execution::Call(isolate, isolate->promise_internal_reject(), 56 isolate, Execution::Call(isolate, isolate->promise_internal_reject(),
65 isolate->factory()->undefined_value(), 57 isolate->factory()->undefined_value(),
66 arraysize(argv), argv)); 58 arraysize(argv), argv));
67 return isolate->heap()->undefined_value(); 59 return isolate->heap()->undefined_value();
68 } 60 }
69 61
70 // ES#sec-createresolvingfunctions 62 // ES#sec-createresolvingfunctions
71 // CreateResolvingFunctions ( promise ) 63 // CreateResolvingFunctions ( promise )
72 BUILTIN(CreateResolvingFunctions) { 64 BUILTIN(CreateResolvingFunctions) {
73 HandleScope scope(isolate); 65 HandleScope scope(isolate);
74 DCHECK_EQ(3, args.length()); 66 DCHECK_EQ(3, args.length());
75 67
76 Handle<JSObject> promise = args.at<JSObject>(1); 68 Handle<JSObject> promise = args.at<JSObject>(1);
77 Handle<Object> debug_event = args.at<Object>(2); 69 Handle<Object> debug_event = args.at<Object>(2);
70 Handle<JSFunction> resolve, reject;
78 71
79 Handle<Context> context = 72 PromiseUtils::CreateResolvingFunctions(isolate, promise, debug_event,
80 isolate->factory()->NewPromiseResolvingFunctionContext( 73 &resolve, &reject);
81 kPromiseContextLength);
82 context->set_native_context(*isolate->native_context());
83 context->set(kAlreadyVisitedSlot, Smi::kZero);
84 context->set(kPromiseSlot, *promise);
85 context->set(kDebugEventSlot, *debug_event);
86
87 Handle<SharedFunctionInfo> resolve_shared_fun(
88 isolate->native_context()->promise_resolve_shared_fun(), isolate);
89 Handle<JSFunction> resolve =
90 isolate->factory()->NewFunctionFromSharedFunctionInfo(
91 isolate->sloppy_function_without_prototype_map(), resolve_shared_fun,
92 isolate->native_context(), TENURED);
93
94 Handle<SharedFunctionInfo> reject_shared_fun(
95 isolate->native_context()->promise_reject_shared_fun(), isolate);
96 Handle<JSFunction> reject =
97 isolate->factory()->NewFunctionFromSharedFunctionInfo(
98 isolate->sloppy_function_without_prototype_map(), reject_shared_fun,
99 isolate->native_context(), TENURED);
100
101 resolve->set_context(*context);
102 reject->set_context(*context);
103 74
104 Handle<FixedArray> result = isolate->factory()->NewFixedArray(2); 75 Handle<FixedArray> result = isolate->factory()->NewFixedArray(2);
105 result->set(0, *resolve); 76 result->set(0, *resolve);
106 result->set(1, *reject); 77 result->set(1, *reject);
107 78
108 return *isolate->factory()->NewJSArrayWithElements(result, FAST_ELEMENTS, 2, 79 return *isolate->factory()->NewJSArrayWithElements(result, FAST_ELEMENTS, 2,
109 NOT_TENURED); 80 NOT_TENURED);
110 } 81 }
111 82
112 } // namespace internal 83 } // namespace internal
113 } // namespace v8 84 } // namespace v8
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | src/factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698