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

Side by Side Diff: third_party/WebKit/Source/core/inspector/MainThreadDebugger.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) 2011 Google Inc. All rights reserved. 2 * Copyright (c) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 16 matching lines...) Expand all
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "core/inspector/MainThreadDebugger.h" 31 #include "core/inspector/MainThreadDebugger.h"
32 32
33 #include "bindings/core/v8/BindingSecurity.h" 33 #include "bindings/core/v8/BindingSecurity.h"
34 #include "bindings/core/v8/DOMWrapperWorld.h" 34 #include "bindings/core/v8/DOMWrapperWorld.h"
35 #include "bindings/core/v8/ScriptController.h" 35 #include "bindings/core/v8/ScriptController.h"
36 #include "bindings/core/v8/SourceLocation.h" 36 #include "bindings/core/v8/SourceLocation.h"
37 #include "bindings/core/v8/V8ErrorHandler.h"
37 #include "bindings/core/v8/V8Node.h" 38 #include "bindings/core/v8/V8Node.h"
38 #include "bindings/core/v8/V8Window.h" 39 #include "bindings/core/v8/V8Window.h"
40 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
39 #include "core/dom/ContainerNode.h" 41 #include "core/dom/ContainerNode.h"
40 #include "core/dom/Document.h" 42 #include "core/dom/Document.h"
41 #include "core/dom/Element.h" 43 #include "core/dom/Element.h"
42 #include "core/dom/ExecutionContext.h" 44 #include "core/dom/ExecutionContext.h"
43 #include "core/dom/StaticNodeList.h" 45 #include "core/dom/StaticNodeList.h"
46 #include "core/events/ErrorEvent.h"
44 #include "core/frame/FrameConsole.h" 47 #include "core/frame/FrameConsole.h"
45 #include "core/frame/FrameHost.h" 48 #include "core/frame/FrameHost.h"
46 #include "core/frame/LocalDOMWindow.h" 49 #include "core/frame/LocalDOMWindow.h"
47 #include "core/frame/LocalFrame.h" 50 #include "core/frame/LocalFrame.h"
48 #include "core/frame/Settings.h" 51 #include "core/frame/Settings.h"
49 #include "core/frame/UseCounter.h" 52 #include "core/frame/UseCounter.h"
50 #include "core/inspector/ConsoleMessage.h" 53 #include "core/inspector/ConsoleMessage.h"
51 #include "core/inspector/ConsoleMessageStorage.h" 54 #include "core/inspector/ConsoleMessageStorage.h"
52 #include "core/inspector/IdentifiersFactory.h" 55 #include "core/inspector/IdentifiersFactory.h"
53 #include "core/inspector/InspectedFrames.h" 56 #include "core/inspector/InspectedFrames.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 DOMWrapperWorld& world = scriptState->world(); 146 DOMWrapperWorld& world = scriptState->world();
144 debugger()->contextCreated(V8ContextInfo(scriptState->context(), contextGrou pId(frame), world.isMainWorld(), origin ? origin->toRawString() : "", world.isIs olatedWorld() ? world.isolatedWorldHumanReadableName() : "", IdentifiersFactory: :frameId(frame), scriptState->getExecutionContext()->isDocument())); 147 debugger()->contextCreated(V8ContextInfo(scriptState->context(), contextGrou pId(frame), world.isMainWorld(), origin ? origin->toRawString() : "", world.isIs olatedWorld() ? world.isolatedWorldHumanReadableName() : "", IdentifiersFactory: :frameId(frame), scriptState->getExecutionContext()->isDocument()));
145 } 148 }
146 149
147 void MainThreadDebugger::contextWillBeDestroyed(ScriptState* scriptState) 150 void MainThreadDebugger::contextWillBeDestroyed(ScriptState* scriptState)
148 { 151 {
149 v8::HandleScope handles(scriptState->isolate()); 152 v8::HandleScope handles(scriptState->isolate());
150 debugger()->contextDestroyed(scriptState->context()); 153 debugger()->contextDestroyed(scriptState->context());
151 } 154 }
152 155
153 void MainThreadDebugger::exceptionThrown(LocalFrame* frame, const String& errorM essage, std::unique_ptr<SourceLocation> location) 156 void MainThreadDebugger::exceptionThrown(ExecutionContext* context, ErrorEvent* event)
154 { 157 {
158 LocalFrame* frame = nullptr;
159 ScriptState* scriptState = nullptr;
160 if (context->isDocument()) {
161 frame = toDocument(context)->frame();
162 scriptState = event->world() ? ScriptState::forWorld(frame, *event->worl d()) : nullptr;
163 }
164 if (context->isMainThreadWorkletGlobalScope()) {
165 frame = toMainThreadWorkletGlobalScope(context)->frame();
166 scriptState = toMainThreadWorkletGlobalScope(context)->scriptController( )->getScriptState();
167 }
168
155 if (frame->host() && frame->host()->consoleMessageStorage().isMuted()) 169 if (frame->host() && frame->host()->consoleMessageStorage().isMuted())
156 return; 170 return;
157 debugger()->exceptionThrown(contextGroupId(frame), errorMessage, location->u rl(), location->lineNumber(), location->columnNumber(), location->cloneStackTrac e(), location->scriptId()); 171
158 frame->console().reportMessageToClient(ConsoleMessage::create(JSMessageSourc e, ErrorMessageLevel, errorMessage, std::move(location))); 172 const String16 defaultMessage = "Uncaught";
173 if (scriptState && scriptState->contextIsValid()) {
174 ScriptState::Scope scope(scriptState);
175 v8::Local<v8::Value> exception = V8ErrorHandler::loadExceptionFromErrorE ventWrapper(scriptState, event, scriptState->context()->Global());
176 SourceLocation* location = event->location();
177 debugger()->exceptionThrown(scriptState->context(), defaultMessage, exce ption, event->messageForConsole(), location->url(), location->lineNumber(), loca tion->columnNumber(), location->cloneStackTrace(), location->scriptId());
178 }
179
180 // TODO(dgozman): do not wrap in ConsoleMessage.
181 frame->console().reportMessageToClient(ConsoleMessage::create(JSMessageSourc e, ErrorMessageLevel, event->messageForConsole(), event->location()->clone()));
159 } 182 }
160 183
161 int MainThreadDebugger::contextGroupId(LocalFrame* frame) 184 int MainThreadDebugger::contextGroupId(LocalFrame* frame)
162 { 185 {
163 LocalFrame* localFrameRoot = frame->localFrameRoot(); 186 LocalFrame* localFrameRoot = frame->localFrameRoot();
164 return frameId(localFrameRoot); 187 return frameId(localFrameRoot);
165 } 188 }
166 189
167 MainThreadDebugger* MainThreadDebugger::instance() 190 MainThreadDebugger* MainThreadDebugger::instance()
168 { 191 {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 frame->settings()->setForceMainWorldInitialization(false); 262 frame->settings()->setForceMainWorldInitialization(false);
240 } 263 }
241 264
242 void MainThreadDebugger::consoleAPIMessage(int contextGroupId, V8ConsoleAPIType type, const String16& message, const String16& url, unsigned lineNumber, unsigne d columnNumber, V8StackTrace* stackTrace) 265 void MainThreadDebugger::consoleAPIMessage(int contextGroupId, V8ConsoleAPIType type, const String16& message, const String16& url, unsigned lineNumber, unsigne d columnNumber, V8StackTrace* stackTrace)
243 { 266 {
244 LocalFrame* frame = WeakIdentifierMap<LocalFrame>::lookup(contextGroupId); 267 LocalFrame* frame = WeakIdentifierMap<LocalFrame>::lookup(contextGroupId);
245 if (!frame) 268 if (!frame)
246 return; 269 return;
247 if (type == V8ConsoleAPIType::kClear && frame->host()) 270 if (type == V8ConsoleAPIType::kClear && frame->host())
248 frame->host()->consoleMessageStorage().clear(); 271 frame->host()->consoleMessageStorage().clear();
249 // TODO(dgozman): maybe not wrap with ConsoleMessage. 272 // TODO(dgozman): do not wrap in ConsoleMessage.
250 ConsoleMessage* consoleMessage = ConsoleMessage::create(ConsoleAPIMessageSou rce, consoleAPITypeToMessageLevel(type), message, SourceLocation::create(url, li neNumber, columnNumber, stackTrace ? stackTrace->clone() : nullptr, 0)); 273 ConsoleMessage* consoleMessage = ConsoleMessage::create(ConsoleAPIMessageSou rce, consoleAPITypeToMessageLevel(type), message, SourceLocation::create(url, li neNumber, columnNumber, stackTrace ? stackTrace->clone() : nullptr, 0));
251 frame->console().reportMessageToClient(consoleMessage); 274 frame->console().reportMessageToClient(consoleMessage);
252 } 275 }
253 276
254 v8::MaybeLocal<v8::Value> MainThreadDebugger::memoryInfo(v8::Isolate* isolate, v 8::Local<v8::Context> context) 277 v8::MaybeLocal<v8::Value> MainThreadDebugger::memoryInfo(v8::Isolate* isolate, v 8::Local<v8::Context> context)
255 { 278 {
256 ExecutionContext* executionContext = toExecutionContext(context); 279 ExecutionContext* executionContext = toExecutionContext(context);
257 ASSERT_UNUSED(executionContext, executionContext); 280 ASSERT_UNUSED(executionContext, executionContext);
258 ASSERT(executionContext->isDocument()); 281 ASSERT(executionContext->isDocument());
259 return toV8(MemoryInfo::create(), context->Global(), isolate); 282 return toV8(MemoryInfo::create(), context->Global(), isolate);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 return; 379 return;
357 if (!nodes->Set(context, index++, toV8(node, info.Holder(), info.Get Isolate())).FromMaybe(false)) 380 if (!nodes->Set(context, index++, toV8(node, info.Holder(), info.Get Isolate())).FromMaybe(false))
358 return; 381 return;
359 } 382 }
360 info.GetReturnValue().Set(nodes); 383 info.GetReturnValue().Set(nodes);
361 } 384 }
362 exceptionState.throwIfNeeded(); 385 exceptionState.throwIfNeeded();
363 } 386 }
364 387
365 } // namespace blink 388 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698