void FrameConsole::addMessage(MessageSource source, MessageLevel level, const String& message, const String& url, unsigned lineNumber, unsigned columnNumber, PassRefPtrWillBeRawPtr<ScriptCallStack> callStack, ScriptState* scriptState, unsigned long requestIdentifier) { if (muteCount) return; // FIXME: This should not need to reach for the main-frame. // Inspector code should just take the current frame and know how to walk itself. ExecutionContext* context = m_frame.document(); if (!context) return; String messageURL; if (callStack) { messageURL = callStack->at(0).sourceURL(); InspectorInstrumentation::addMessageToConsole(context, source, LogMessageType, level, message, callStack, requestIdentifier); } else { messageURL = url; InspectorInstrumentation::addMessageToConsole(context, source, LogMessageType, level, message, url, lineNumber, columnNumber, scriptState, requestIdentifier); } if (source == CSSMessageSource) return; String stackTrace; if (callStack && m_frame.chromeClient().shouldReportDetailedMessageForSource(messageURL)) stackTrace = FrameConsole::formatStackTraceString(message, callStack); m_frame.chromeClient().addMessageToConsole(&m_frame, source, level, message, lineNumber, messageURL, stackTrace); }
String FrameConsole::formatStackTraceString(const String& originalMessage, PassRefPtrWillBeRawPtr<ScriptCallStack> callStack) { StringBuilder stackTrace; for (size_t i = 0; i < callStack->size(); ++i) { const ScriptCallFrame& frame = callStack->at(i); stackTrace.append("\n at " + (frame.functionName().length() ? frame.functionName() : "(anonymous function)")); stackTrace.append(" ("); stackTrace.append(frame.sourceURL()); stackTrace.append(':'); stackTrace.append(String::number(frame.lineNumber())); stackTrace.append(':'); stackTrace.append(String::number(frame.columnNumber())); stackTrace.append(')'); } return stackTrace.toString(); }
ConsoleMessage::ConsoleMessage(bool, MessageSource source, MessageType type, MessageLevel level, const String& message, PassRefPtrWillBeRawPtr<ScriptCallStack> callStack, unsigned long requestIdentifier) : m_source(source) , m_type(type) , m_level(level) , m_message(message) , m_scriptState(0) , m_arguments(nullptr) , m_line(0) , m_column(0) , m_requestId(IdentifiersFactory::requestId(requestIdentifier)) , m_timestamp(WTF::currentTime()) { if (callStack && callStack->size()) { const ScriptCallFrame& frame = callStack->at(0); m_url = frame.sourceURL(); m_line = frame.lineNumber(); m_column = frame.columnNumber(); } m_callStack = callStack; }