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

Side by Side Diff: Source/bindings/core/v8/RejectedPromises.cpp

Issue 1181353005: Return null when no promise/reason is given in PromiseRejectionEvent (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: updates Created 5 years, 6 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium 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
5 #include "config.h" 5 #include "config.h"
6 #include "bindings/core/v8/RejectedPromises.h" 6 #include "bindings/core/v8/RejectedPromises.h"
7 7
8 #include "bindings/core/v8/ScopedPersistent.h" 8 #include "bindings/core/v8/ScopedPersistent.h"
9 #include "bindings/core/v8/ScriptState.h" 9 #include "bindings/core/v8/ScriptState.h"
10 #include "bindings/core/v8/ScriptValue.h" 10 #include "bindings/core/v8/ScriptValue.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 if (value.IsEmpty() || !value->IsPromise()) 60 if (value.IsEmpty() || !value->IsPromise())
61 return; 61 return;
62 ASSERT(!v8::Local<v8::Promise>::Cast(value)->HasHandler()); 62 ASSERT(!v8::Local<v8::Promise>::Cast(value)->HasHandler());
63 63
64 EventTarget* target = executionContext->errorEventTarget(); 64 EventTarget* target = executionContext->errorEventTarget();
65 if (RuntimeEnabledFeatures::promiseRejectionEventEnabled() && target) { 65 if (RuntimeEnabledFeatures::promiseRejectionEventEnabled() && target) {
66 PromiseRejectionEventInit init; 66 PromiseRejectionEventInit init;
67 init.setPromise(ScriptPromise(m_scriptState, value)); 67 init.setPromise(ScriptPromise(m_scriptState, value));
68 init.setReason(m_exception); 68 init.setReason(m_exception);
69 init.setCancelable(true); 69 init.setCancelable(true);
70 RefPtrWillBeRawPtr<PromiseRejectionEvent> event = PromiseRejectionEv ent::create(EventTypeNames::unhandledrejection, init); 70 RefPtrWillBeRawPtr<PromiseRejectionEvent> event = PromiseRejectionEv ent::create(m_scriptState, EventTypeNames::unhandledrejection, init);
71 // Log to console if event was not preventDefault()'ed. 71 // Log to console if event was not preventDefault()'ed.
72 m_shouldLogToConsole = target->dispatchEvent(event); 72 m_shouldLogToConsole = target->dispatchEvent(event);
73 } 73 }
74 74
75 if (m_shouldLogToConsole) { 75 if (m_shouldLogToConsole) {
76 const String errorMessage = "Uncaught (in promise)"; 76 const String errorMessage = "Uncaught (in promise)";
77 Vector<ScriptValue> args; 77 Vector<ScriptValue> args;
78 args.append(ScriptValue(m_scriptState, v8String(m_scriptState->isola te(), errorMessage))); 78 args.append(ScriptValue(m_scriptState, v8String(m_scriptState->isola te(), errorMessage)));
79 args.append(m_exception); 79 args.append(m_exception);
80 RefPtrWillBeRawPtr<ScriptArguments> arguments = ScriptArguments::cre ate(m_scriptState, args); 80 RefPtrWillBeRawPtr<ScriptArguments> arguments = ScriptArguments::cre ate(m_scriptState, args);
(...skipping 26 matching lines...) Expand all
107 v8::Local<v8::Value> value = m_promise.newLocal(m_scriptState->isolate() ); 107 v8::Local<v8::Value> value = m_promise.newLocal(m_scriptState->isolate() );
108 // Either collected or https://crbug.com/450330 108 // Either collected or https://crbug.com/450330
109 if (value.IsEmpty() || !value->IsPromise()) 109 if (value.IsEmpty() || !value->IsPromise())
110 return; 110 return;
111 111
112 EventTarget* target = executionContext->errorEventTarget(); 112 EventTarget* target = executionContext->errorEventTarget();
113 if (RuntimeEnabledFeatures::promiseRejectionEventEnabled() && target) { 113 if (RuntimeEnabledFeatures::promiseRejectionEventEnabled() && target) {
114 PromiseRejectionEventInit init; 114 PromiseRejectionEventInit init;
115 init.setPromise(ScriptPromise(m_scriptState, value)); 115 init.setPromise(ScriptPromise(m_scriptState, value));
116 init.setReason(m_exception); 116 init.setReason(m_exception);
117 RefPtrWillBeRawPtr<PromiseRejectionEvent> event = PromiseRejectionEv ent::create(EventTypeNames::rejectionhandled, init); 117 RefPtrWillBeRawPtr<PromiseRejectionEvent> event = PromiseRejectionEv ent::create(m_scriptState, EventTypeNames::rejectionhandled, init);
118 m_shouldLogToConsole &= target->dispatchEvent(event); 118 m_shouldLogToConsole &= target->dispatchEvent(event);
119 } 119 }
120 120
121 if (m_shouldLogToConsole) { 121 if (m_shouldLogToConsole) {
122 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage:: create(JSMessageSource, RevokedErrorMessageLevel, "Handler added to rejected pro mise"); 122 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage:: create(JSMessageSource, RevokedErrorMessageLevel, "Handler added to rejected pro mise");
123 consoleMessage->setRelatedMessageId(m_consoleMessageId); 123 consoleMessage->setRelatedMessageId(m_consoleMessageId);
124 executionContext->addConsoleMessage(consoleMessage.release()); 124 executionContext->addConsoleMessage(consoleMessage.release());
125 } 125 }
126 } 126 }
127 127
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 continue; 222 continue;
223 223
224 message->report(); 224 message->report();
225 m_reportedAsErrors.append(message.release()); 225 m_reportedAsErrors.append(message.release());
226 if (m_reportedAsErrors.size() > maxReportedHandlersPendingResolution) 226 if (m_reportedAsErrors.size() > maxReportedHandlersPendingResolution)
227 m_reportedAsErrors.remove(0, maxReportedHandlersPendingResolution / 10); 227 m_reportedAsErrors.remove(0, maxReportedHandlersPendingResolution / 10);
228 } 228 }
229 } 229 }
230 230
231 } // namespace blink 231 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698