Stop processing of JavaScript after phantom.exit().

This code:

    console.log("Hello World!");
    phantom.exit();
    console.log("Meh, noone should see me!");

currently produces this unexpected output:

    Hello World!
    Meh, noone should see me!

This patch fixes it to only output the first line, by loading a blank
page on phantom.exit(). Direct deletion of the web page can trigger
crashes, so this is a safe workaround.

https://github.com/ariya/phantomjs/issues/12431
2.0
Milian Wolff 2014-08-06 15:41:07 +02:00 committed by Ariya Hidayat
parent 77c47044cf
commit a9809996b1
1 changed files with 6 additions and 2 deletions

View File

@ -501,8 +501,12 @@ void Phantom::doExit(int code)
emit aboutToExit(code);
m_terminated = true;
m_returnValue = code;
foreach (QPointer<WebPage> page, m_pages)
page->deleteLater();
foreach (QPointer<WebPage> page, m_pages) {
// stop processing of JavaScript code by loading a blank page
page->mainFrame()->setUrl(QUrl(QStringLiteral("about:blank")));
// delay deletion into the event loop, direct deletion can trigger crashes
page->deleteLater();
}
m_pages.clear();
m_page = 0;
QApplication::instance()->exit(code);