void PageConsole::addMessage(MessageSource source, MessageLevel level, const String& message, const String& url, unsigned lineNumber, unsigned columnNumber, PassRefPtr<ScriptCallStack> callStack, JSC::ExecState* state, unsigned long requestIdentifier) { if (muteCount && source != ConsoleAPIMessageSource) return; Page* page = this->page(); if (!page) return; if (callStack) InspectorInstrumentation::addMessageToConsole(page, source, LogMessageType, level, message, callStack, requestIdentifier); else InspectorInstrumentation::addMessageToConsole(page, source, LogMessageType, level, message, url, lineNumber, columnNumber, state, requestIdentifier); if (source == CSSMessageSource) return; if (page->settings().privateBrowsingEnabled()) return; page->chrome().client().addMessageToConsole(source, level, message, lineNumber, columnNumber, url); if (!page->settings().logsPageMessagesToSystemConsoleEnabled() && !shouldPrintExceptions()) return; printSourceURLAndLine(url, lineNumber); printMessageSourceAndLevelPrefix(source, level); printf(" %s\n", message.utf8().data()); }
void Console::trace(ScriptCallStack* callStack) { addMessage(TraceMessageType, LogMessageLevel, callStack, true); if (!shouldPrintExceptions()) return; printf("Stack Trace\n"); for (unsigned i = 0; i < callStack->size(); ++i) { String functionName = String(callStack->at(i).functionName()); printf("\t%s\n", functionName.utf8().data()); } }
void Console::trace(PassRefPtr<ScriptArguments> arguments, PassRefPtr<ScriptCallStack> prpCallStack) { RefPtr<ScriptCallStack> callStack = prpCallStack; addMessage(TraceMessageType, LogMessageLevel, arguments, callStack, true); if (!shouldPrintExceptions()) return; printf("Stack Trace\n"); for (unsigned i = 0; i < callStack->size(); ++i) { String functionName = String(callStack->at(i).functionName()); printf("\t%s\n", functionName.utf8().data()); } }
void Console::addMessage(MessageType type, MessageLevel level, ScriptState* state, PassRefPtr<ScriptArguments> prpArguments, bool acceptNoArguments, bool printTrace) { RefPtr<ScriptArguments> arguments = prpArguments; Page* page = this->page(); if (!page) return; if (!acceptNoArguments && !arguments->argumentCount()) return; size_t stackSize = printTrace ? ScriptCallStack::maxCallStackSizeToCapture : 1; RefPtr<ScriptCallStack> callStack(createScriptCallStack(state, stackSize)); const ScriptCallFrame& lastCaller = callStack->at(0); if (shouldPrintExceptions()) { printSourceURLAndLine(lastCaller.sourceURL(), 0); printMessageSourceAndLevelPrefix(ConsoleAPIMessageSource, level); for (unsigned i = 0; i < arguments->argumentCount(); ++i) { String argAsString; if (arguments->argumentAt(i).getString(arguments->globalState(), argAsString)) printf(" %s", argAsString.utf8().data()); } printf("\n"); } if (printTrace) { printf("Stack Trace\n"); for (unsigned i = 0; i < callStack->size(); ++i) { String functionName = String(callStack->at(i).functionName()); printf("\t%s\n", functionName.utf8().data()); } } String message; if (arguments->getFirstArgumentAsString(message)) page->chrome()->client()->addMessageToConsole(ConsoleAPIMessageSource, type, level, message, lastCaller.lineNumber(), lastCaller.sourceURL()); InspectorInstrumentation::addMessageToConsole(page, ConsoleAPIMessageSource, type, level, message, state, arguments.release()); }
void PageConsoleClient::addMessage(MessageSource source, MessageLevel level, const String& message, const String& url, unsigned lineNumber, unsigned columnNumber, PassRefPtr<ScriptCallStack> callStack, JSC::ExecState* state, unsigned long requestIdentifier) { if (muteCount && source != MessageSource::ConsoleAPI) return; if (callStack) InspectorInstrumentation::addMessageToConsole(&m_page, source, MessageType::Log, level, message, callStack, requestIdentifier); else InspectorInstrumentation::addMessageToConsole(&m_page, source, MessageType::Log, level, message, url, lineNumber, columnNumber, state, requestIdentifier); if (source == MessageSource::CSS) return; if (m_page.usesEphemeralSession()) return; m_page.chrome().client().addMessageToConsole(source, level, message, lineNumber, columnNumber, url); if (!m_page.settings().logsPageMessagesToSystemConsoleEnabled() && !shouldPrintExceptions()) return; ConsoleClient::printConsoleMessage(MessageSource::ConsoleAPI, MessageType::Log, level, message, url, lineNumber, columnNumber); }
void Console::trace(ScriptState* state, PassRefPtr<ScriptArguments> arguments) { addMessage(TraceMessageType, LogMessageLevel, state, arguments, true, shouldPrintExceptions()); }
Completion Interpreter::evaluate(const UString& sourceURL, int startingLineNumber, const UChar* code, int codeLength, JSValue* thisV) { JSLock lock; // prevent against infinite recursion if (m_recursion >= 20) return Completion(Throw, Error::create(&m_globalExec, GeneralError, "Recursion too deep")); // parse the source code int sid; int errLine; UString errMsg; RefPtr<ProgramNode> progNode = Parser::parse(sourceURL, startingLineNumber, code, codeLength, &sid, &errLine, &errMsg); // notify debugger that source has been parsed if (m_debugger) { bool cont = m_debugger->sourceParsed(&m_globalExec, sid, sourceURL, UString(code, codeLength), startingLineNumber, errLine, errMsg); if (!cont) return Completion(Break); } // no program node means a syntax error occurred if (!progNode) return Completion(Throw, Error::create(&m_globalExec, SyntaxError, errMsg, errLine, sid, sourceURL)); m_globalExec.clearException(); m_recursion++; JSObject* globalObj = m_globalObject; JSObject* thisObj = globalObj; // "this" must be an object... use same rules as Function.prototype.apply() if (thisV && !thisV->isUndefinedOrNull()) thisObj = thisV->toObject(&m_globalExec); Completion res; if (m_globalExec.hadException()) // the thisV->toObject() conversion above might have thrown an exception - if so, propagate it res = Completion(Throw, m_globalExec.exception()); else { // execute the code Context ctx(globalObj, this, thisObj, progNode.get()); ExecState newExec(this, &ctx); ctx.setExecState(&newExec); progNode->processVarDecls(&newExec); res = progNode->execute(&newExec); } m_recursion--; if (shouldPrintExceptions() && res.complType() == Throw) { JSLock lock; ExecState* exec = globalExec(); CString f = sourceURL.UTF8String(); CString message = res.value()->toObject(exec)->toString(exec).UTF8String(); int line = res.value()->toObject(exec)->get(exec, "line")->toUInt32(exec); #if PLATFORM(WIN_OS) printf("%s line %d: %s\n", f.c_str(), line, message.c_str()); #else printf("[%d] %s line %d: %s\n", getpid(), f.c_str(), line, message.c_str()); #endif } return res; }