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

Side by Side Diff: third_party/WebKit/Source/core/dom/ExecutionContext.cpp

Issue 2010603002: Use SourceLocation when reporting runtime exceptions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2004243002
Patch Set: test fixes Created 4 years, 7 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2012 Google Inc. All Rights Reserved. 3 * Copyright (C) 2012 Google Inc. All Rights Reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
13 * 13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 * 25 *
26 */ 26 */
27 27
28 #include "core/dom/ExecutionContext.h" 28 #include "core/dom/ExecutionContext.h"
29 29
30 #include "bindings/core/v8/ScriptCallStack.h" 30 #include "bindings/core/v8/SourceLocation.h"
31 #include "core/dom/ExecutionContextTask.h" 31 #include "core/dom/ExecutionContextTask.h"
32 #include "core/events/ErrorEvent.h" 32 #include "core/events/ErrorEvent.h"
33 #include "core/events/EventTarget.h" 33 #include "core/events/EventTarget.h"
34 #include "core/fetch/MemoryCache.h" 34 #include "core/fetch/MemoryCache.h"
35 #include "core/frame/UseCounter.h" 35 #include "core/frame/UseCounter.h"
36 #include "core/html/PublicURLManager.h" 36 #include "core/html/PublicURLManager.h"
37 #include "core/inspector/InspectorInstrumentation.h" 37 #include "core/inspector/InspectorInstrumentation.h"
38 #include "core/workers/WorkerGlobalScope.h" 38 #include "core/workers/WorkerGlobalScope.h"
39 #include "core/workers/WorkerThread.h" 39 #include "core/workers/WorkerThread.h"
40 40
41 namespace blink { 41 namespace blink {
42 42
43 class ExecutionContext::PendingException { 43 class ExecutionContext::PendingException {
44 WTF_MAKE_NONCOPYABLE(PendingException); 44 WTF_MAKE_NONCOPYABLE(PendingException);
45 public: 45 public:
46 PendingException(const String& errorMessage, int lineNumber, int columnNumbe r, int scriptId, const String& sourceURL, PassRefPtr<ScriptCallStack> callStack) 46 PendingException(const String& errorMessage, PassOwnPtr<SourceLocation> loca tion)
47 : m_errorMessage(errorMessage) 47 : m_errorMessage(errorMessage)
48 , m_lineNumber(lineNumber) 48 , m_location(std::move(location))
49 , m_columnNumber(columnNumber)
50 , m_scriptId(scriptId)
51 , m_sourceURL(sourceURL)
52 , m_callStack(callStack)
53 { 49 {
54 } 50 }
55 51
56 String m_errorMessage; 52 String m_errorMessage;
57 int m_lineNumber; 53 OwnPtr<SourceLocation> m_location;
58 int m_columnNumber;
59 int m_scriptId;
60 String m_sourceURL;
61 RefPtr<ScriptCallStack> m_callStack;
62 }; 54 };
63 55
64 ExecutionContext::ExecutionContext() 56 ExecutionContext::ExecutionContext()
65 : m_circularSequentialID(0) 57 : m_circularSequentialID(0)
66 , m_inDispatchErrorEvent(false) 58 , m_inDispatchErrorEvent(false)
67 , m_activeDOMObjectsAreSuspended(false) 59 , m_activeDOMObjectsAreSuspended(false)
68 , m_activeDOMObjectsAreStopped(false) 60 , m_activeDOMObjectsAreStopped(false)
69 , m_windowInteractionTokens(0) 61 , m_windowInteractionTokens(0)
70 , m_isRunSuspendableTasksScheduled(false) 62 , m_isRunSuspendableTasksScheduled(false)
71 , m_referrerPolicy(ReferrerPolicyDefault) 63 , m_referrerPolicy(ReferrerPolicyDefault)
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 object->suspend(); 131 object->suspend();
140 } 132 }
141 133
142 bool ExecutionContext::shouldSanitizeScriptError(const String& sourceURL, Access ControlStatus corsStatus) 134 bool ExecutionContext::shouldSanitizeScriptError(const String& sourceURL, Access ControlStatus corsStatus)
143 { 135 {
144 if (corsStatus == OpaqueResource) 136 if (corsStatus == OpaqueResource)
145 return true; 137 return true;
146 return !(getSecurityOrigin()->canRequestNoSuborigin(completeURL(sourceURL)) || corsStatus == SharableCrossOrigin); 138 return !(getSecurityOrigin()->canRequestNoSuborigin(completeURL(sourceURL)) || corsStatus == SharableCrossOrigin);
147 } 139 }
148 140
149 void ExecutionContext::reportException(ErrorEvent* errorEvent, int scriptId, Pas sRefPtr<ScriptCallStack> callStack, AccessControlStatus corsStatus) 141 void ExecutionContext::reportException(ErrorEvent* errorEvent, PassOwnPtr<Source Location> location, AccessControlStatus corsStatus)
150 { 142 {
151 if (m_inDispatchErrorEvent) { 143 if (m_inDispatchErrorEvent) {
152 if (!m_pendingExceptions) 144 if (!m_pendingExceptions)
153 m_pendingExceptions = adoptPtr(new Vector<OwnPtr<PendingException>>( )); 145 m_pendingExceptions = adoptPtr(new Vector<OwnPtr<PendingException>>( ));
154 m_pendingExceptions->append(adoptPtr(new PendingException(errorEvent->me ssageForConsole(), errorEvent->lineno(), errorEvent->colno(), scriptId, errorEve nt->filename(), callStack))); 146 m_pendingExceptions->append(adoptPtr(new PendingException(errorEvent->me ssageForConsole(), std::move(location))));
155 return; 147 return;
156 } 148 }
157 149
158 // First report the original exception and only then all the nested ones. 150 // First report the original exception and only then all the nested ones.
159 if (!dispatchErrorEvent(errorEvent, corsStatus)) 151 if (!dispatchErrorEvent(errorEvent, corsStatus))
160 logExceptionToConsole(errorEvent->messageForConsole(), scriptId, errorEv ent->filename(), errorEvent->lineno(), errorEvent->colno(), callStack); 152 logExceptionToConsole(errorEvent->messageForConsole(), std::move(locatio n));
161 153
162 if (!m_pendingExceptions) 154 if (!m_pendingExceptions)
163 return; 155 return;
164 156
165 for (size_t i = 0; i < m_pendingExceptions->size(); i++) { 157 for (size_t i = 0; i < m_pendingExceptions->size(); i++) {
166 PendingException* e = m_pendingExceptions->at(i).get(); 158 PendingException* e = m_pendingExceptions->at(i).get();
167 logExceptionToConsole(e->m_errorMessage, e->m_scriptId, e->m_sourceURL, e->m_lineNumber, e->m_columnNumber, e->m_callStack); 159 logExceptionToConsole(e->m_errorMessage, std::move(e->m_location));
168 } 160 }
169 m_pendingExceptions.reset(); 161 m_pendingExceptions.reset();
170 } 162 }
171 163
172 bool ExecutionContext::dispatchErrorEvent(ErrorEvent* errorEvent, AccessControlS tatus corsStatus) 164 bool ExecutionContext::dispatchErrorEvent(ErrorEvent* errorEvent, AccessControlS tatus corsStatus)
173 { 165 {
174 EventTarget* target = errorEventTarget(); 166 EventTarget* target = errorEventTarget();
175 if (!target) 167 if (!target)
176 return false; 168 return false;
177 169
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 } 266 }
275 267
276 DEFINE_TRACE(ExecutionContext) 268 DEFINE_TRACE(ExecutionContext)
277 { 269 {
278 visitor->trace(m_publicURLManager); 270 visitor->trace(m_publicURLManager);
279 ContextLifecycleNotifier::trace(visitor); 271 ContextLifecycleNotifier::trace(visitor);
280 Supplementable<ExecutionContext>::trace(visitor); 272 Supplementable<ExecutionContext>::trace(visitor);
281 } 273 }
282 274
283 } // namespace blink 275 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/ExecutionContext.h ('k') | third_party/WebKit/Source/core/inspector/ConsoleMessage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698