Skip to content

Commit

Permalink
now we eval each JS files separately so that the line numbers in the …
Browse files Browse the repository at this point in the history
…parse error messages should always make sense

git-svn-id: http://svn1.bj.corp.yahoo.com/repos/WebEng/lifesearch/vdom-webkit/VdomBrowser@61786 82b2e94c-9313-0410-8ced-81db5252d7f6
  • Loading branch information
agentzh committed Jul 30, 2009
1 parent 0badd4d commit d0679af
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
50 changes: 25 additions & 25 deletions mainwindow.cpp
Expand Up @@ -87,9 +87,30 @@ void MainWindow::loadFinished(bool done) {
m_urlEdit->setText(m_view->url().toEncoded());
addUrlToList();

if (!m_injectedJS.isNull() && m_injectedJS != "") {
QVariant res = evalJS(m_injectedJS + "true");
qDebug() << "injecting JS res: " << res << endl;
if (!m_injectedJSFiles.isEmpty()) {
for (int i = 0; i < m_injectedJSFiles.count(); i++) {
const QString& fileName = m_injectedJSFiles[i];
//qDebug() << QString("Checking if file %1 is readable...")
//.arg(fileName).toUtf8() << endl;
if (!QFile::exists(fileName)) {
qDebug() <<
QString("js file \"%1\" not found.\n").arg(fileName).toUtf8().data();
continue;
}

QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() <<
QString("Failed to load js file %1: %2\n")
.arg(fileName).arg(file.errorString()).toUtf8();
file.close();
continue;
}
qDebug() << "Loading JS file " << fileName << "...\n";
QString injectedJS = QString::fromUtf8(file.readAll()) + "\n";
QVariant res = evalJS(injectedJS + "true");
qDebug() << "injecting JS res: " << res << endl;
}
}

if (m_hunterEnabled) {
Expand Down Expand Up @@ -1000,28 +1021,7 @@ void MainWindow::loadUrl(const QUrl& url) {
}

void MainWindow::setJSFiles(QStringList& jsFiles) {
m_injectedJS.clear();
for (int i = 0; i < jsFiles.count(); i++) {
const QString& fileName = jsFiles[i];
//qDebug() << QString("Checking if file %1 is readable...")
//.arg(fileName).toUtf8() << endl;
if (!QFile::exists(fileName)) {
qDebug() <<
QString("js file \"%1\" not found.\n").arg(fileName).toUtf8().data();
continue;
}

QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() <<
QString("Failed to load js file %1: %2\n")
.arg(fileName).arg(file.errorString()).toUtf8();
file.close();
continue;
}
//qDebug() << "Reading file " << fileName << endl;
m_injectedJS += QString::fromUtf8(file.readAll()) + "\n";
}
m_injectedJSFiles = jsFiles;
//qDebug() << "!!! JS: " << m_injectedJS << endl;
}

2 changes: 1 addition & 1 deletion mainwindow.h
Expand Up @@ -269,7 +269,7 @@ protected slots:
Iterator m_iterator;

QSplitter* m_mainSplitter;
QString m_injectedJS;
QStringList m_injectedJSFiles;
};

#endif
Expand Down

0 comments on commit d0679af

Please sign in to comment.