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

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

Issue 1090583005: Revert of DevTools: [console] Logged promise rejections do not change state once handled (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Encompass Oilpan fix Created 5 years, 8 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
« no previous file with comments | « Source/bindings/core/v8/RejectedPromises.h ('k') | Source/bindings/core/v8/V8Initializer.cpp » ('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 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/ScriptState.h" 8 #include "bindings/core/v8/ScriptState.h"
9 #include "bindings/core/v8/ScriptValue.h" 9 #include "bindings/core/v8/ScriptValue.h"
10 #include "bindings/core/v8/V8Binding.h" 10 #include "bindings/core/v8/V8Binding.h"
11 #include "core/dom/ExecutionContext.h" 11 #include "core/dom/ExecutionContext.h"
12 #include "core/inspector/ConsoleMessage.h" 12 #include "core/inspector/ConsoleMessage.h"
13 #include "core/inspector/ScriptArguments.h" 13 #include "core/inspector/ScriptArguments.h"
14 14
15 namespace blink { 15 namespace blink {
16 16
17 static const unsigned maxReportedHandlersPendingResolution = 1000;
18
19 class RejectedPromises::Message final : public NoBaseWillBeGarbageCollectedFinal ized<RejectedPromises::Message> { 17 class RejectedPromises::Message final : public NoBaseWillBeGarbageCollectedFinal ized<RejectedPromises::Message> {
20 public: 18 public:
21 static PassOwnPtrWillBeRawPtr<Message> create(const ScriptValue& promise, co nst ScriptValue& exception, const String& errorMessage, const String& resourceNa me, int scriptId, int lineNumber, int columnNumber, PassRefPtrWillBeRawPtr<Scrip tCallStack> callStack) 19 static PassOwnPtrWillBeRawPtr<Message> create(const ScriptValue& promise, co nst ScriptValue& exception, const String& errorMessage, const String& resourceNa me, int scriptId, int lineNumber, int columnNumber, PassRefPtrWillBeRawPtr<Scrip tCallStack> callStack)
22 { 20 {
23 return adoptPtrWillBeNoop(new Message(promise, exception, errorMessage, resourceName, scriptId, lineNumber, columnNumber, callStack)); 21 return adoptPtrWillBeNoop(new Message(promise, exception, errorMessage, resourceName, scriptId, lineNumber, columnNumber, callStack));
24 } 22 }
25 23
26 DEFINE_INLINE_TRACE() 24 DEFINE_INLINE_TRACE()
27 { 25 {
28 visitor->trace(m_callStack); 26 visitor->trace(m_callStack);
29 } 27 }
30 28
31 private: 29 private:
32 Message(const ScriptValue& promise, const ScriptValue& exception, const Stri ng& errorMessage, const String& resourceName, int scriptId, int lineNumber, int columnNumber, PassRefPtrWillBeRawPtr<ScriptCallStack> callStack) 30 Message(const ScriptValue& promise, const ScriptValue& exception, const Stri ng& errorMessage, const String& resourceName, int scriptId, int lineNumber, int columnNumber, PassRefPtrWillBeRawPtr<ScriptCallStack> callStack)
33 : m_promise(promise) 31 : m_promise(promise)
34 , m_exception(exception) 32 , m_exception(exception)
35 , m_errorMessage(errorMessage) 33 , m_errorMessage(errorMessage)
36 , m_resourceName(resourceName) 34 , m_resourceName(resourceName)
37 , m_scriptId(scriptId) 35 , m_scriptId(scriptId)
38 , m_lineNumber(lineNumber) 36 , m_lineNumber(lineNumber)
39 , m_columnNumber(columnNumber) 37 , m_columnNumber(columnNumber)
40 , m_callStack(callStack) 38 , m_callStack(callStack)
41 , m_consoleMessageId(0)
42 { 39 {
43 } 40 }
44 41
45 friend class RejectedPromises; 42 friend class RejectedPromises;
46 43
47 const ScriptValue m_promise; 44 const ScriptValue m_promise;
48 const ScriptValue m_exception; 45 const ScriptValue m_exception;
49 const String m_errorMessage; 46 const String m_errorMessage;
50 const String m_resourceName; 47 const String m_resourceName;
51 const int m_scriptId; 48 const int m_scriptId;
52 const int m_lineNumber; 49 const int m_lineNumber;
53 const int m_columnNumber; 50 const int m_columnNumber;
54 const RefPtrWillBeMember<ScriptCallStack> m_callStack; 51 const RefPtrWillBeMember<ScriptCallStack> m_callStack;
55 unsigned m_consoleMessageId;
56 }; 52 };
57 53
58 RejectedPromises::RejectedPromises() 54 RejectedPromises::RejectedPromises()
59 { 55 {
60 } 56 }
61 57
62 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(RejectedPromises); 58 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(RejectedPromises);
63 59
64 DEFINE_TRACE(RejectedPromises) 60 DEFINE_TRACE(RejectedPromises)
65 { 61 {
66 visitor->trace(m_queue); 62 visitor->trace(m_queue);
67 visitor->trace(m_reportedAsErrors);
68 } 63 }
69 64
70 void RejectedPromises::rejectedWithNoHandler(ScriptState* scriptState, v8::Promi seRejectMessage data, const String& errorMessage, const String& resourceName, in t scriptId, int lineNumber, int columnNumber, PassRefPtrWillBeRawPtr<ScriptCallS tack> callStack) 65 void RejectedPromises::add(ScriptState* scriptState, v8::PromiseRejectMessage da ta, const String& errorMessage, const String& resourceName, int scriptId, int li neNumber, int columnNumber, PassRefPtrWillBeRawPtr<ScriptCallStack> callStack)
71 { 66 {
72 v8::Handle<v8::Promise> promise = data.GetPromise(); 67 v8::Handle<v8::Promise> promise = data.GetPromise();
73 OwnPtrWillBeRawPtr<Message> message = Message::create(ScriptValue(scriptStat e, promise), ScriptValue(scriptState, data.GetValue()), errorMessage, resourceNa me, scriptId, lineNumber, columnNumber, callStack); 68 OwnPtrWillBeRawPtr<Message> message = Message::create(ScriptValue(scriptStat e, promise), ScriptValue(scriptState, data.GetValue()), errorMessage, resourceNa me, scriptId, lineNumber, columnNumber, callStack);
74 69
75 m_queue.append(message.release()); 70 m_queue.append(message.release());
76 } 71 }
77 72
78 void RejectedPromises::handlerAdded(v8::PromiseRejectMessage data)
79 {
80 // First look it up in the pending messages and fast return, it'll be covere d by processQueue().
81 for (auto it = m_queue.begin(); it != m_queue.end(); ++it) {
82 ScriptState* scriptState = (*it)->m_promise.scriptState();
83 if (!scriptState->contextIsValid())
84 continue;
85
86 ScriptState::Scope scope(scriptState);
87 v8::Handle<v8::Value> promise = (*it)->m_promise.v8Value();
88 if (promise == data.GetPromise())
89 return;
90 }
91
92 // Then look it up in the reported errors.
93 for (auto it = m_reportedAsErrors.begin(); it != m_reportedAsErrors.end(); + +it) {
94 ScriptState* scriptState = (*it)->m_promise.scriptState();
95 if (!scriptState->contextIsValid())
96 continue;
97
98 ScriptState::Scope scope(scriptState);
99 v8::Handle<v8::Value> promise = (*it)->m_promise.v8Value();
100 if (promise != data.GetPromise())
101 continue;
102
103 // If execution termination has been triggered, quietly bail out.
104 if (v8::V8::IsExecutionTerminating(scriptState->isolate()))
105 continue;
106 ExecutionContext* executionContext = scriptState->executionContext();
107 if (!executionContext)
108 continue;
109
110 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::crea te(JSMessageSource, RevokedErrorMessageLevel, "Handler added to rejected promise ");
111 consoleMessage->setRelatedMessageId((*it)->m_consoleMessageId);
112 executionContext->addConsoleMessage(consoleMessage.release());
113 m_reportedAsErrors.remove(it);
114 break;
115 }
116 }
117
118 void RejectedPromises::dispose() 73 void RejectedPromises::dispose()
119 { 74 {
120 processQueue(); 75 processQueue();
121 } 76 }
122 77
123 void RejectedPromises::processQueue() 78 void RejectedPromises::processQueue()
124 { 79 {
125 while (!m_queue.isEmpty()) { 80 while (!m_queue.isEmpty()) {
126 OwnPtrWillBeRawPtr<Message> message = m_queue.takeFirst(); 81 OwnPtrWillBeRawPtr<Message> message = m_queue.takeFirst();
127 ScriptState* scriptState = message->m_promise.scriptState(); 82 ScriptState* scriptState = message->m_promise.scriptState();
(...skipping 25 matching lines...) Expand all
153 String embedderErrorMessage = message->m_errorMessage; 108 String embedderErrorMessage = message->m_errorMessage;
154 if (embedderErrorMessage.isEmpty()) 109 if (embedderErrorMessage.isEmpty())
155 embedderErrorMessage = errorMessage; 110 embedderErrorMessage = errorMessage;
156 else if (embedderErrorMessage.startsWith("Uncaught ")) 111 else if (embedderErrorMessage.startsWith("Uncaught "))
157 embedderErrorMessage.insert(" (in promise)", 8); 112 embedderErrorMessage.insert(" (in promise)", 8);
158 113
159 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::crea te(JSMessageSource, ErrorMessageLevel, embedderErrorMessage, message->m_resource Name, message->m_lineNumber, message->m_columnNumber); 114 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::crea te(JSMessageSource, ErrorMessageLevel, embedderErrorMessage, message->m_resource Name, message->m_lineNumber, message->m_columnNumber);
160 consoleMessage->setScriptArguments(arguments); 115 consoleMessage->setScriptArguments(arguments);
161 consoleMessage->setCallStack(message->m_callStack); 116 consoleMessage->setCallStack(message->m_callStack);
162 consoleMessage->setScriptId(message->m_scriptId); 117 consoleMessage->setScriptId(message->m_scriptId);
163 message->m_consoleMessageId = consoleMessage->assignMessageId();
164 executionContext->addConsoleMessage(consoleMessage.release()); 118 executionContext->addConsoleMessage(consoleMessage.release());
165
166 m_reportedAsErrors.append(message.release());
167 if (m_reportedAsErrors.size() > maxReportedHandlersPendingResolution)
168 m_reportedAsErrors.removeFirst();
169 } 119 }
170 } 120 }
171 121
172 } // namespace blink 122 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/RejectedPromises.h ('k') | Source/bindings/core/v8/V8Initializer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698