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

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

Issue 2541283002: [promises] Port ResolvePromise to TF (Closed)
Patch Set: fix nits Created 4 years 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
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 #include "src/runtime/runtime-utils.h" 4 #include "src/runtime/runtime-utils.h"
5 5
6 #include "src/debug/debug.h" 6 #include "src/debug/debug.h"
7 #include "src/elements.h" 7 #include "src/elements.h"
8 #include "src/promise-utils.h" 8 #include "src/promise-utils.h"
9 9
10 namespace v8 { 10 namespace v8 {
11 namespace internal { 11 namespace internal {
12 12
13 namespace { 13 namespace {
14 14
15 void PromiseRejectEvent(Isolate* isolate, Handle<JSReceiver> promise, 15 void PromiseRejectEvent(Isolate* isolate, Handle<JSPromise> promise,
16 Handle<Object> rejected_promise, Handle<Object> value, 16 Handle<Object> rejected_promise, Handle<Object> value,
17 bool debug_event) { 17 bool debug_event) {
18 if (isolate->debug()->is_active() && debug_event) { 18 if (isolate->debug()->is_active() && debug_event) {
19 isolate->debug()->OnPromiseReject(rejected_promise, value); 19 isolate->debug()->OnPromiseReject(rejected_promise, value);
20 } 20 }
21 Handle<Symbol> key = isolate->factory()->promise_has_handler_symbol(); 21
22 // Do not report if we actually have a handler. 22 // Report only if we don't actually have a handler.
23 if (JSReceiver::GetDataProperty(promise, key)->IsUndefined(isolate)) { 23 if (!promise->has_handler()) {
24 isolate->ReportPromiseReject(Handle<JSObject>::cast(promise), value, 24 isolate->ReportPromiseReject(Handle<JSObject>::cast(promise), value,
25 v8::kPromiseRejectWithNoHandler); 25 v8::kPromiseRejectWithNoHandler);
26 } 26 }
27 } 27 }
28 28
29 } // namespace 29 } // namespace
30 30
31 RUNTIME_FUNCTION(Runtime_PromiseRejectEventFromStack) { 31 RUNTIME_FUNCTION(Runtime_PromiseRejectEventFromStack) {
32 DCHECK(args.length() == 2); 32 DCHECK(args.length() == 2);
33 HandleScope scope(isolate); 33 HandleScope scope(isolate);
34 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0); 34 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
35 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); 35 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1);
36 36
37 Handle<Object> rejected_promise = promise; 37 Handle<Object> rejected_promise = promise;
38 if (isolate->debug()->is_active()) { 38 if (isolate->debug()->is_active()) {
39 // If the Promise.reject call is caught, then this will return 39 // If the Promise.reject call is caught, then this will return
40 // undefined, which will be interpreted by PromiseRejectEvent 40 // undefined, which will be interpreted by PromiseRejectEvent
41 // as being a caught exception event. 41 // as being a caught exception event.
42 rejected_promise = isolate->GetPromiseOnStackOnThrow(); 42 rejected_promise = isolate->GetPromiseOnStackOnThrow();
43 } 43 }
44 PromiseRejectEvent(isolate, promise, rejected_promise, value, true); 44 PromiseRejectEvent(isolate, promise, rejected_promise, value, true);
45 return isolate->heap()->undefined_value(); 45 return isolate->heap()->undefined_value();
46 } 46 }
47 47
48 RUNTIME_FUNCTION(Runtime_PromiseRevokeReject) { 48 RUNTIME_FUNCTION(Runtime_PromiseRevokeReject) {
49 DCHECK(args.length() == 1); 49 DCHECK(args.length() == 1);
50 HandleScope scope(isolate); 50 HandleScope scope(isolate);
51 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0); 51 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
52 Handle<Symbol> key = isolate->factory()->promise_has_handler_symbol();
53 // At this point, no revocation has been issued before 52 // At this point, no revocation has been issued before
54 CHECK(JSReceiver::GetDataProperty(promise, key)->IsUndefined(isolate)); 53 CHECK(!promise->has_handler());
55 isolate->ReportPromiseReject(promise, Handle<Object>(), 54 isolate->ReportPromiseReject(promise, Handle<Object>(),
56 v8::kPromiseHandlerAddedAfterReject); 55 v8::kPromiseHandlerAddedAfterReject);
57 return isolate->heap()->undefined_value(); 56 return isolate->heap()->undefined_value();
58 } 57 }
59 58
60 namespace { 59 namespace {
61 void EnqueuePromiseReactionJob(Isolate* isolate, Handle<Object> value, 60 void EnqueuePromiseReactionJob(Isolate* isolate, Handle<Object> value,
62 Handle<Object> tasks, Handle<Object> deferred, 61 Handle<Object> tasks, Handle<Object> deferred,
63 Handle<Object> status) { 62 Handle<Object> status) {
64 Handle<Object> debug_id = isolate->factory()->undefined_value(); 63 Handle<Object> debug_id = isolate->factory()->undefined_value();
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 267
269 if (reject_reactions->IsJSObject()) { 268 if (reject_reactions->IsJSObject()) {
270 return *reject_reactions; 269 return *reject_reactions;
271 } 270 }
272 271
273 DCHECK(reject_reactions->IsFixedArray()); 272 DCHECK(reject_reactions->IsFixedArray());
274 return *isolate->factory()->NewJSArrayWithElements( 273 return *isolate->factory()->NewJSArrayWithElements(
275 Handle<FixedArray>::cast(reject_reactions)); 274 Handle<FixedArray>::cast(reject_reactions));
276 } 275 }
277 276
277 RUNTIME_FUNCTION(Runtime_PromiseMarkAsHandled) {
278 HandleScope scope(isolate);
279 DCHECK(args.length() == 1);
280 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
281
282 promise->set_has_handler(true);
283 return isolate->heap()->undefined_value();
284 }
285
278 } // namespace internal 286 } // namespace internal
279 } // namespace v8 287 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698