Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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" |
| 39 #include "core/dom/ContainerNode.h" | 40 #include "core/dom/ContainerNode.h" |
| 40 #include "core/dom/Document.h" | 41 #include "core/dom/Document.h" |
| 41 #include "core/dom/Element.h" | 42 #include "core/dom/Element.h" |
| 42 #include "core/dom/ExecutionContext.h" | 43 #include "core/dom/ExecutionContext.h" |
| 43 #include "core/dom/StaticNodeList.h" | 44 #include "core/dom/StaticNodeList.h" |
| 45 #include "core/events/ErrorEvent.h" | |
| 44 #include "core/frame/FrameConsole.h" | 46 #include "core/frame/FrameConsole.h" |
| 45 #include "core/frame/FrameHost.h" | 47 #include "core/frame/FrameHost.h" |
| 46 #include "core/frame/LocalDOMWindow.h" | 48 #include "core/frame/LocalDOMWindow.h" |
| 47 #include "core/frame/LocalFrame.h" | 49 #include "core/frame/LocalFrame.h" |
| 48 #include "core/frame/Settings.h" | 50 #include "core/frame/Settings.h" |
| 49 #include "core/frame/UseCounter.h" | 51 #include "core/frame/UseCounter.h" |
| 50 #include "core/inspector/ConsoleMessage.h" | 52 #include "core/inspector/ConsoleMessage.h" |
| 51 #include "core/inspector/ConsoleMessageStorage.h" | 53 #include "core/inspector/ConsoleMessageStorage.h" |
| 52 #include "core/inspector/IdentifiersFactory.h" | 54 #include "core/inspector/IdentifiersFactory.h" |
| 53 #include "core/inspector/InspectedFrames.h" | 55 #include "core/inspector/InspectedFrames.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 DOMWrapperWorld& world = scriptState->world(); | 145 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())); | 146 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 } | 147 } |
| 146 | 148 |
| 147 void MainThreadDebugger::contextWillBeDestroyed(ScriptState* scriptState) | 149 void MainThreadDebugger::contextWillBeDestroyed(ScriptState* scriptState) |
| 148 { | 150 { |
| 149 v8::HandleScope handles(scriptState->isolate()); | 151 v8::HandleScope handles(scriptState->isolate()); |
| 150 debugger()->contextDestroyed(scriptState->context()); | 152 debugger()->contextDestroyed(scriptState->context()); |
| 151 } | 153 } |
| 152 | 154 |
| 153 void MainThreadDebugger::exceptionThrown(LocalFrame* frame, const String& errorM essage, std::unique_ptr<SourceLocation> location) | 155 void MainThreadDebugger::exceptionThrown(LocalFrame* frame, ErrorEvent* event) |
| 154 { | 156 { |
| 155 if (frame->host() && frame->host()->consoleMessageStorage().isMuted()) | 157 if (frame->host() && frame->host()->consoleMessageStorage().isMuted()) |
| 156 return; | 158 return; |
| 157 debugger()->exceptionThrown(contextGroupId(frame), errorMessage, location->u rl(), location->lineNumber(), location->columnNumber(), location->cloneStackTrac e(), location->scriptId()); | 159 |
| 158 frame->console().reportMessageToClient(ConsoleMessage::create(JSMessageSourc e, ErrorMessageLevel, errorMessage, std::move(location))); | 160 const String16 defaultMessage = "Uncaught"; |
| 161 ScriptState* scriptState = event->world() ? ScriptState::forWorld(frame, *ev ent->world()) : nullptr; | |
| 162 if (scriptState && scriptState->contextIsValid()) { | |
| 163 ScriptState::Scope scope(scriptState); | |
| 164 v8::Local<v8::Value> exception = V8ErrorHandler::loadExceptionFromErrorE ventWrapper(scriptState, event, scriptState->context()->Global()); | |
| 165 SourceLocation* location = event->location(); | |
| 166 debugger()->exceptionThrown(scriptState->context(), defaultMessage, exce ption, event->messageForConsole(), location->url(), location->lineNumber(), loca tion->columnNumber(), location->cloneStackTrace(), location->scriptId()); | |
|
kozy
2016/07/28 17:18:51
Could we extract this code from here and WorkerThr
dgozman
2016/07/28 17:40:56
Acknowledged.
| |
| 167 } | |
| 168 | |
| 169 // TODO(dgozman): do not wrap in ConsoleMessage. | |
| 170 frame->console().reportMessageToClient(ConsoleMessage::create(JSMessageSourc e, ErrorMessageLevel, event->messageForConsole(), event->location()->clone())); | |
| 159 } | 171 } |
| 160 | 172 |
| 161 int MainThreadDebugger::contextGroupId(LocalFrame* frame) | 173 int MainThreadDebugger::contextGroupId(LocalFrame* frame) |
| 162 { | 174 { |
| 163 LocalFrame* localFrameRoot = frame->localFrameRoot(); | 175 LocalFrame* localFrameRoot = frame->localFrameRoot(); |
| 164 return frameId(localFrameRoot); | 176 return frameId(localFrameRoot); |
| 165 } | 177 } |
| 166 | 178 |
| 167 MainThreadDebugger* MainThreadDebugger::instance() | 179 MainThreadDebugger* MainThreadDebugger::instance() |
| 168 { | 180 { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 { | 249 { |
| 238 LocalFrame* frame = WeakIdentifierMap<LocalFrame>::lookup(contextGroupId); | 250 LocalFrame* frame = WeakIdentifierMap<LocalFrame>::lookup(contextGroupId); |
| 239 frame->settings()->setForceMainWorldInitialization(false); | 251 frame->settings()->setForceMainWorldInitialization(false); |
| 240 } | 252 } |
| 241 | 253 |
| 242 void MainThreadDebugger::consoleAPIMessage(int contextGroupId, MessageLevel leve l, const String16& message, const String16& url, unsigned lineNumber, unsigned c olumnNumber, V8StackTrace* stackTrace) | 254 void MainThreadDebugger::consoleAPIMessage(int contextGroupId, MessageLevel leve l, const String16& message, const String16& url, unsigned lineNumber, unsigned c olumnNumber, V8StackTrace* stackTrace) |
| 243 { | 255 { |
| 244 LocalFrame* frame = WeakIdentifierMap<LocalFrame>::lookup(contextGroupId); | 256 LocalFrame* frame = WeakIdentifierMap<LocalFrame>::lookup(contextGroupId); |
| 245 if (!frame) | 257 if (!frame) |
| 246 return; | 258 return; |
| 247 // TODO(dgozman): maybe not wrap with ConsoleMessage. | 259 // TODO(dgozman): do not wrap in ConsoleMessage. |
| 248 ConsoleMessage* consoleMessage = ConsoleMessage::create(ConsoleAPIMessageSou rce, level, message, SourceLocation::create(url, lineNumber, columnNumber, stack Trace ? stackTrace->clone() : nullptr, 0)); | 260 ConsoleMessage* consoleMessage = ConsoleMessage::create(ConsoleAPIMessageSou rce, level, message, SourceLocation::create(url, lineNumber, columnNumber, stack Trace ? stackTrace->clone() : nullptr, 0)); |
| 249 frame->console().reportMessageToClient(consoleMessage); | 261 frame->console().reportMessageToClient(consoleMessage); |
| 250 } | 262 } |
| 251 | 263 |
| 252 v8::MaybeLocal<v8::Value> MainThreadDebugger::memoryInfo(v8::Isolate* isolate, v 8::Local<v8::Context> context) | 264 v8::MaybeLocal<v8::Value> MainThreadDebugger::memoryInfo(v8::Isolate* isolate, v 8::Local<v8::Context> context) |
| 253 { | 265 { |
| 254 ExecutionContext* executionContext = toExecutionContext(context); | 266 ExecutionContext* executionContext = toExecutionContext(context); |
| 255 ASSERT_UNUSED(executionContext, executionContext); | 267 ASSERT_UNUSED(executionContext, executionContext); |
| 256 ASSERT(executionContext->isDocument()); | 268 ASSERT(executionContext->isDocument()); |
| 257 return toV8(MemoryInfo::create(), context->Global(), isolate); | 269 return toV8(MemoryInfo::create(), context->Global(), isolate); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 return; | 366 return; |
| 355 if (!nodes->Set(context, index++, toV8(node, info.Holder(), info.Get Isolate())).FromMaybe(false)) | 367 if (!nodes->Set(context, index++, toV8(node, info.Holder(), info.Get Isolate())).FromMaybe(false)) |
| 356 return; | 368 return; |
| 357 } | 369 } |
| 358 info.GetReturnValue().Set(nodes); | 370 info.GetReturnValue().Set(nodes); |
| 359 } | 371 } |
| 360 exceptionState.throwIfNeeded(); | 372 exceptionState.throwIfNeeded(); |
| 361 } | 373 } |
| 362 | 374 |
| 363 } // namespace blink | 375 } // namespace blink |
| OLD | NEW |