// from khtml/ecma/debugger/value2string.cpp QString valueToString(KJS::JSValue* value) { switch(value->type()) { case KJS::NumberType: { double v = 0.0; value->getNumber(v); return QString::number(v); } case KJS::BooleanType: return value->getBoolean() ? "true" : "false"; case KJS::StringType: { KJS::UString s; value->getString(s); return '"' + s.qstring() + '"'; } case KJS::UndefinedType: return "undefined"; case KJS::NullType: return "null"; case KJS::ObjectType: return "[object " + static_cast<KJS::JSObject*>(value)->className().qstring() +"]"; case KJS::GetterSetterType: case KJS::UnspecifiedType: default: return QString(); } }
bool JSConsoleWidget::execute( const QString &cmd, const KJS::Value &self ) { KJS::Completion jsres; bool ok = js->execute( jsres, cmd, self ); // Executed ok if ( ok ) { // No return value if ( !jsres.isValueCompletion() ) return ok; // Return value KJS::Value ret = jsres.value(); KJS::UString s = ret.toString( js->globalExec() ); if ( s.isNull() ) { warn( i18n("Success, but return value cannot be displayed") ); return ok; } QString txt = s.qstring(); txt = txt.replace( QChar('\n'), "<br>" ); println( txt ); return ok; } // Handle errors KJS::ComplType ct = jsres.complType(); if ( (ct == KJS::Throw) || (ct == KJS::Break) || ct == KJS::Continue ) { KJS::UString s = jsres.value().toString( js->globalExec() ); if ( !s.isNull() ) warn( s.qstring() ); else warn( i18n("Unspecified error") ); } else { kdDebug(80001) << "jsconsolewidget: Unknown completion error, " << ct << endl; warn( i18n("Unknown error returned, completion type %1").arg(ct) ); } return ok; }
bool KJSDebugWin::sourceParsed(KJS::ExecState *exec, int sourceId, const KJS::UString &source, int errorLine) { // Work out which source file this fragment is in SourceFile *sourceFile = 0; if(!m_nextSourceUrl.isEmpty()) sourceFile = getSourceFile(exec->interpreter(), m_nextSourceUrl); int index; if(!sourceFile) { index = m_sourceSel->count(); if(!m_nextSourceUrl.isEmpty()) { QString code = source.qstring(); KParts::ReadOnlyPart *part = static_cast< ScriptInterpreter * >(exec->interpreter())->part(); if(m_nextSourceUrl == part->url().url()) { // Only store the code here if it's not from the part's html page... in that // case we can get it from KHTMLPageCache code = QString::null; } sourceFile = new SourceFile(m_nextSourceUrl, code, exec->interpreter()); setSourceFile(exec->interpreter(), m_nextSourceUrl, sourceFile); m_sourceSelFiles.append(sourceFile); m_sourceSel->insertItem(m_nextSourceUrl); } else { // Sourced passed from somewhere else (possibly an eval call)... we don't know the url, // but we still know the interpreter sourceFile = new SourceFile("(unknown)", source.qstring(), exec->interpreter()); m_sourceSelFiles.append(sourceFile); m_sourceSel->insertItem(QString::number(index) += "-???"); } } else { // Ensure that each source file to be displayed is associated with // an appropriate interpreter if(!sourceFile->interpreter) sourceFile->interpreter = exec->interpreter(); for(index = 0; index < m_sourceSel->count(); index++) { if(m_sourceSelFiles.at(index) == sourceFile) break; } assert(index < m_sourceSel->count()); } SourceFragment *sf = new SourceFragment(sourceId, m_nextSourceBaseLine, errorLine, sourceFile); m_sourceFragments[sourceId] = sf; if(m_sourceSel->currentItem() < 0) m_sourceSel->setCurrentItem(index); if(m_sourceSel->currentItem() == index) { displaySourceFile(sourceFile, true); } m_nextSourceBaseLine = 1; m_nextSourceUrl = ""; return (m_mode != Stop); }