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

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

Issue 2170263002: [DevTools] Pass error object when reporting exceptions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: worklets! Created 4 years, 4 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
(...skipping 26 matching lines...) Expand all
37 #include "core/inspector/ConsoleMessage.h" 37 #include "core/inspector/ConsoleMessage.h"
38 #include "core/inspector/InspectorInstrumentation.h" 38 #include "core/inspector/InspectorInstrumentation.h"
39 #include "core/workers/WorkerGlobalScope.h" 39 #include "core/workers/WorkerGlobalScope.h"
40 #include "core/workers/WorkerThread.h" 40 #include "core/workers/WorkerThread.h"
41 #include "platform/weborigin/SecurityPolicy.h" 41 #include "platform/weborigin/SecurityPolicy.h"
42 #include "wtf/PtrUtil.h" 42 #include "wtf/PtrUtil.h"
43 #include <memory> 43 #include <memory>
44 44
45 namespace blink { 45 namespace blink {
46 46
47 class ExecutionContext::PendingException {
48 WTF_MAKE_NONCOPYABLE(PendingException);
49 public:
50 PendingException(const String& errorMessage, std::unique_ptr<SourceLocation> location)
51 : m_errorMessage(errorMessage)
52 , m_location(std::move(location))
53 {
54 }
55
56 String m_errorMessage;
57 std::unique_ptr<SourceLocation> m_location;
58 };
59
60 ExecutionContext::ExecutionContext() 47 ExecutionContext::ExecutionContext()
61 : m_circularSequentialID(0) 48 : m_circularSequentialID(0)
62 , m_inDispatchErrorEvent(false) 49 , m_inDispatchErrorEvent(false)
63 , m_activeDOMObjectsAreSuspended(false) 50 , m_activeDOMObjectsAreSuspended(false)
64 , m_activeDOMObjectsAreStopped(false) 51 , m_activeDOMObjectsAreStopped(false)
65 , m_windowInteractionTokens(0) 52 , m_windowInteractionTokens(0)
66 , m_isRunSuspendableTasksScheduled(false) 53 , m_isRunSuspendableTasksScheduled(false)
67 , m_referrerPolicy(ReferrerPolicyDefault) 54 , m_referrerPolicy(ReferrerPolicyDefault)
68 { 55 {
69 } 56 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 bool ExecutionContext::shouldSanitizeScriptError(const String& sourceURL, Access ControlStatus corsStatus) 125 bool ExecutionContext::shouldSanitizeScriptError(const String& sourceURL, Access ControlStatus corsStatus)
139 { 126 {
140 if (corsStatus == OpaqueResource) 127 if (corsStatus == OpaqueResource)
141 return true; 128 return true;
142 return !(getSecurityOrigin()->canRequestNoSuborigin(completeURL(sourceURL)) || corsStatus == SharableCrossOrigin); 129 return !(getSecurityOrigin()->canRequestNoSuborigin(completeURL(sourceURL)) || corsStatus == SharableCrossOrigin);
143 } 130 }
144 131
145 void ExecutionContext::reportException(ErrorEvent* errorEvent, AccessControlStat us corsStatus) 132 void ExecutionContext::reportException(ErrorEvent* errorEvent, AccessControlStat us corsStatus)
146 { 133 {
147 if (m_inDispatchErrorEvent) { 134 if (m_inDispatchErrorEvent) {
148 if (!m_pendingExceptions) 135 m_pendingExceptions.append(errorEvent);
149 m_pendingExceptions = wrapUnique(new Vector<std::unique_ptr<PendingE xception>>());
150 m_pendingExceptions->append(wrapUnique(new PendingException(errorEvent-> messageForConsole(), errorEvent->location()->clone())));
151 return; 136 return;
152 } 137 }
153 138
154 // First report the original exception and only then all the nested ones. 139 // First report the original exception and only then all the nested ones.
155 if (!dispatchErrorEvent(errorEvent, corsStatus)) 140 if (!dispatchErrorEvent(errorEvent, corsStatus))
156 exceptionThrown(errorEvent->messageForConsole(), errorEvent->location()- >clone()); 141 exceptionThrown(errorEvent);
157 142
158 if (!m_pendingExceptions) 143 if (m_pendingExceptions.isEmpty())
159 return; 144 return;
160 145 for (ErrorEvent* e : m_pendingExceptions)
161 for (size_t i = 0; i < m_pendingExceptions->size(); i++) { 146 exceptionThrown(e);
162 PendingException* e = m_pendingExceptions->at(i).get(); 147 m_pendingExceptions.clear();
163 exceptionThrown(e->m_errorMessage, std::move(e->m_location));
164 }
165 m_pendingExceptions.reset();
166 } 148 }
167 149
168 bool ExecutionContext::dispatchErrorEvent(ErrorEvent* errorEvent, AccessControlS tatus corsStatus) 150 bool ExecutionContext::dispatchErrorEvent(ErrorEvent* errorEvent, AccessControlS tatus corsStatus)
169 { 151 {
170 EventTarget* target = errorEventTarget(); 152 EventTarget* target = errorEventTarget();
171 if (!target) 153 if (!target)
172 return false; 154 return false;
173 155
174 if (shouldSanitizeScriptError(errorEvent->filename(), corsStatus)) 156 if (shouldSanitizeScriptError(errorEvent->filename(), corsStatus))
175 errorEvent = ErrorEvent::createSanitizedError(errorEvent->world()); 157 errorEvent = ErrorEvent::createSanitizedError(errorEvent->world());
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } 268 }
287 269
288 void ExecutionContext::removeURLFromMemoryCache(const KURL& url) 270 void ExecutionContext::removeURLFromMemoryCache(const KURL& url)
289 { 271 {
290 memoryCache()->removeURLFromCache(url); 272 memoryCache()->removeURLFromCache(url);
291 } 273 }
292 274
293 DEFINE_TRACE(ExecutionContext) 275 DEFINE_TRACE(ExecutionContext)
294 { 276 {
295 visitor->trace(m_publicURLManager); 277 visitor->trace(m_publicURLManager);
278 visitor->trace(m_pendingExceptions);
296 ContextLifecycleNotifier::trace(visitor); 279 ContextLifecycleNotifier::trace(visitor);
297 Supplementable<ExecutionContext>::trace(visitor); 280 Supplementable<ExecutionContext>::trace(visitor);
298 } 281 }
299 282
300 } // namespace blink 283 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/ExecutionContext.h ('k') | third_party/WebKit/Source/core/inspector/MainThreadDebugger.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698