phantomjs/src/phantom.cpp

500 lines
15 KiB
C++
Raw Permalink Normal View History

2011-04-09 21:34:04 +04:00
/*
This file is part of the PhantomJS project from Ofi Labs.
Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>
Copyright (C) 2011 Ivan De Marino <ivan.de.marino@gmail.com>
2011-04-09 21:34:04 +04:00
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the <organization> nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "phantom.h"
#include <QApplication>
#include <QDir>
#include <QFileInfo>
#include <QFile>
#include <QtWebKitWidgets/QWebPage>
#include <QDebug>
#include <QMetaObject>
#include <QMetaProperty>
#include <QStandardPaths>
2010-12-27 07:04:53 +03:00
#include "consts.h"
2011-08-21 11:47:34 +04:00
#include "terminal.h"
#include "utils.h"
#include "webpage.h"
#include "webserver.h"
A REPL for PhantomJS This covers [Issue 252](http://code.google.com/p/phantomjs/issues/detail?id=252) The commit is composed of 12 squashed commits: commit efdc6ba4f143c30a690fd97d92d80fa412e79999 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Mon Feb 27 00:19:36 2012 +0000 Pretty-pringing and Completion Caching done! * This completes pretty-printing for the result of evaluated * expressions in the REPL. * Also, now we cache the "possible completions", to speed things up * a bit (nothing fancy though). * Minor tweaks to the internal doc and the way we "mock" * pretty-printing for QObjects/REPLCompletanle * All tests passing :) commit 1f9ef690e112a535b431fca409b77bb9c09d1c70 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Feb 26 22:35:00 2012 +0000 Moving most of REPL shim JavaScritp code in a separate file. Way easier to work on. commit 02d460a16fee14e7096ae7d899c03902c5b8a9c6 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sat Feb 25 20:25:18 2012 +0000 Initialisation of the Completions is now done in a pure virtual. This means that every REPLCompletable object will ACTUALLY register completion strings, ONLY if we are running a REPL and that object is ACTUALLY created. Otherwise, why bother? Adding completions for all exposed REPLCompletable objects Also, fixed an issue with _getCompletions() commit 412c3778fb04aa1c7379f8e760afce702b0428dd Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 21 00:49:17 2012 +0000 Few more tweaks to the REPL: - Now 'phantom' is the first QObject with proper completion - No repetition in QObject completions - LVAL of any user expression is now correctly prettified and printed Major things left to do: - Cache completions (using QCache?) - Add completions for the other QObject - When the LVAL of a user expression is a QObject, print what's expected, not the QObject "real" structure commit 46f04713c8165d898055e15478bb31403f8c93f1 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 7 10:13:23 2012 -0800 Pretty-print expressions result Still not done though: there are issues with the NON-Native JS objects. commit 98b2fe67651dc750b62c6fa9cf1d80317fd9ae06 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Fri Feb 3 00:22:52 2012 -0800 Introducing REPLCompletable. This class should be inherited by any JavaScript-exposed QObject, to ensure correct Auto-Completion. Correct auto-completion for QObjects. - Now even QObjects can correctly provide auto-completion, and avoid showing "not for users" methods - The strings used for the auto-completion are stored in a single Index: minimum memory footprint - Still, there is optimization that should be done (when "searching" for the right completion by prefix) - Completion for the objects not set up yet, but now it's just a trivial sequence of "addCompletion('bla')" in their constructors commit 9bd48618154b1530a37b41f4060440184e23253d Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Feb 2 00:20:25 2012 -0800 Changing the way we import Linenoise. Will just import a specific commit, and update manually when needed. commit cfc9bae9fbdab13b01019b34b7cbd565e3153780 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 23:22:26 2012 -0800 Made the REPL into a Singleton. With Auto-completion!. Reasons: 1) Needed a pointer to function (i.e. a static method) to be used with Linenoise to provide auto-completions 2) It makes more sense, as it's not like we are going to have 2 REPL running at the same time, are we? There are problems to address: - the enumeration in JS seems to return only the native interface of our objects - the function completions contain argument types of those functions - "private" methods are exposed commit c78bd32e17f8e0e4cc4a0066858de8cc81d33b97 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 22:10:20 2012 -0800 Migrating from the original, now [unmantained Linenoise](https://github.com/antirez/linenoise) to the fairly active [tadmarshall fork](https://github.com/tadmarshall/linenoise). Also now the project is imported as a Git Submodule. Having migrated to the latest Linenoise (see prev. commit), now this _SHOULD_ work on Windows too. But, of course, this needs testing. :) commit 43713c5723d7c5ed446ba41ae8d6f8c9feba7f9b Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Jan 24 23:17:06 2012 -0800 Now that the basics work, I'm adding support for REPL history. This is something almost everyone today is accustomed to. Also, now REPL history works! And I found some useful resources to solve pending TODOs. commit 31e5f88b044a5b4a823c67527ef8c245d2ac7863 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 22 20:56:36 2012 -0800 Adding Linenoise Project (https://github.com/antirez/linenoise). For now is included as a drop-in set of files. Later on, if the Linenoise project has frequent updates, we might prefer to do it as a git-submodule. commit 4be9c15c65db4767e482fba0be13f8aab286d5f3 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Jan 5 15:31:13 2012 +0000 First simple REPL implementation. - Not complete - Still doesn't handle arrow keys (needed for history)
2012-01-05 19:31:13 +04:00
#include "repl.h"
#include "system.h"
#include "callback.h"
#include "cookiejar.h"
#include "childprocess.h"
static Phantom *phantomInstance = NULL;
// private:
2010-12-27 07:04:53 +03:00
Phantom::Phantom(QObject *parent)
: QObject(parent)
, m_terminated(false)
2010-12-27 07:04:53 +03:00
, m_returnValue(0)
, m_filesystem(0)
, m_system(0)
, m_childprocess(0)
2010-12-27 07:04:53 +03:00
{
QStringList args = QApplication::arguments();
// Prepare the configuration object based on the command line arguments.
// Because this object will be used by other classes, it needs to be ready ASAP.
m_config.init(&args);
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
// Apply debug configuration as early as possible
Utils::printDebugMessages = m_config.printDebugMessages();
}
void Phantom::init()
{
if (m_config.helpFlag()) {
Terminal::instance()->cout(QString("%1").arg(m_config.helpText()));
Terminal::instance()->cout("Any of the options that accept boolean values ('true'/'false') can also accept 'yes'/'no'.");
Terminal::instance()->cout("");
Terminal::instance()->cout("Without any argument, PhantomJS will launch in interactive mode (REPL).");
Terminal::instance()->cout("");
Terminal::instance()->cout("Documentation can be found at the web site, http://phantomjs.org.");
Terminal::instance()->cout("");
m_terminated = true;
return;
}
if (m_config.versionFlag()) {
m_terminated = true;
Terminal::instance()->cout(QString("%1").arg(PHANTOMJS_VERSION_STRING));
return;
}
if (!m_config.unknownOption().isEmpty()) {
Terminal::instance()->cerr(m_config.unknownOption());
m_terminated = true;
return;
}
// Initialize the CookieJar
m_defaultCookieJar = new CookieJar(m_config.cookiesFile());
QWebSettings::setOfflineWebApplicationCachePath(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
if (m_config.offlineStoragePath().isEmpty()) {
QWebSettings::setOfflineStoragePath(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
} else {
QWebSettings::setOfflineStoragePath(m_config.offlineStoragePath());
}
if (m_config.offlineStorageDefaultQuota() > 0) {
QWebSettings::setOfflineStorageDefaultQuota(m_config.offlineStorageDefaultQuota());
}
m_page = new WebPage(this, QUrl::fromLocalFile(m_config.scriptFile()));
m_page->setCookieJar(m_defaultCookieJar);
m_pages.append(m_page);
// Set up proxy if required
QString proxyType = m_config.proxyType();
if (proxyType != "none") {
setProxy(m_config.proxyHost(), m_config.proxyPort(), proxyType, m_config.proxyAuthUser(), m_config.proxyAuthPass());
}
// Set output encoding
Terminal::instance()->setEncoding(m_config.outputEncoding());
// Set script file encoding
m_scriptFileEnc.setEncoding(m_config.scriptEncoding());
connect(m_page, SIGNAL(javaScriptConsoleMessageSent(QString)),
SLOT(printConsoleMessage(QString)));
connect(m_page, SIGNAL(initialized()),
SLOT(onInitialized()));
2011-08-26 22:02:59 +04:00
m_defaultPageSettings[PAGE_SETTINGS_LOAD_IMAGES] = QVariant::fromValue(m_config.autoLoadImages());
m_defaultPageSettings[PAGE_SETTINGS_JS_ENABLED] = QVariant::fromValue(true);
m_defaultPageSettings[PAGE_SETTINGS_XSS_AUDITING] = QVariant::fromValue(false);
m_defaultPageSettings[PAGE_SETTINGS_USER_AGENT] = QVariant::fromValue(m_page->userAgent());
m_defaultPageSettings[PAGE_SETTINGS_LOCAL_ACCESS_REMOTE] = QVariant::fromValue(m_config.localToRemoteUrlAccessEnabled());
m_defaultPageSettings[PAGE_SETTINGS_WEB_SECURITY_ENABLED] = QVariant::fromValue(m_config.webSecurityEnabled());
m_defaultPageSettings[PAGE_SETTINGS_JS_CAN_OPEN_WINDOWS] = QVariant::fromValue(m_config.javascriptCanOpenWindows());
m_defaultPageSettings[PAGE_SETTINGS_JS_CAN_CLOSE_WINDOWS] = QVariant::fromValue(m_config.javascriptCanCloseWindows());
2011-05-28 09:36:34 +04:00
m_page->applySettings(m_defaultPageSettings);
setLibraryPath(QFileInfo(m_config.scriptFile()).dir().absolutePath());
}
2011-05-26 13:18:09 +04:00
// public:
Phantom *Phantom::instance() {
if (NULL == phantomInstance) {
phantomInstance = new Phantom();
phantomInstance->init();
}
return phantomInstance;
}
Phantom::~Phantom()
{
// Nothing to do: cleanup is handled by QObject relationships
2010-12-27 07:04:53 +03:00
}
2011-05-28 09:36:34 +04:00
QVariantMap Phantom::defaultPageSettings() const
{
return m_defaultPageSettings;
}
QString Phantom::outputEncoding() const
{
2011-08-21 11:47:34 +04:00
return Terminal::instance()->getEncoding();
}
void Phantom::setOutputEncoding(const QString &encoding)
{
2011-08-21 11:47:34 +04:00
Terminal::instance()->setEncoding(encoding);
}
bool Phantom::execute()
2010-12-27 07:04:53 +03:00
{
if (m_terminated)
return false;
#ifndef QT_NO_DEBUG_OUTPUT
qDebug() << "Phantom - execute: Configuration";
const QMetaObject* configMetaObj = m_config.metaObject();
for (int i = 0, ilen = configMetaObj->propertyCount(); i < ilen; ++i) {
qDebug() << " " << i << configMetaObj->property(i).name() << ":" << m_config.property(configMetaObj->property(i).name()).toString();
}
qDebug() << "Phantom - execute: Script & Arguments";
qDebug() << " " << "script:" << m_config.scriptFile();
QStringList args = m_config.scriptArgs();
for (int i = 0, ilen = args.length(); i < ilen; ++i) {
qDebug() << " " << i << "arg:" << args.at(i);
}
#endif
if (m_config.isWebdriverMode()) { // Remote WebDriver mode requested
qDebug() << "Phantom - execute: Starting Remote WebDriver mode";
if (!Utils::injectJsInFrame(":/ghostdriver/main.js", QString(), m_scriptFileEnc, QDir::currentPath(), m_page->mainFrame(), true)) {
m_returnValue = -1;
return false;
}
} else if (m_config.scriptFile().isEmpty()) { // REPL mode requested
qDebug() << "Phantom - execute: Starting REPL mode";
// REPL is only valid for javascript
const QString &scriptLanguage = m_config.scriptLanguage();
if (scriptLanguage != "javascript" && !scriptLanguage.isNull()) {
QString errMessage = QString("Unsupported language: %1").arg(scriptLanguage);
Terminal::instance()->cerr(errMessage);
qWarning("%s", qPrintable(errMessage));
return false;
}
A REPL for PhantomJS This covers [Issue 252](http://code.google.com/p/phantomjs/issues/detail?id=252) The commit is composed of 12 squashed commits: commit efdc6ba4f143c30a690fd97d92d80fa412e79999 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Mon Feb 27 00:19:36 2012 +0000 Pretty-pringing and Completion Caching done! * This completes pretty-printing for the result of evaluated * expressions in the REPL. * Also, now we cache the "possible completions", to speed things up * a bit (nothing fancy though). * Minor tweaks to the internal doc and the way we "mock" * pretty-printing for QObjects/REPLCompletanle * All tests passing :) commit 1f9ef690e112a535b431fca409b77bb9c09d1c70 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Feb 26 22:35:00 2012 +0000 Moving most of REPL shim JavaScritp code in a separate file. Way easier to work on. commit 02d460a16fee14e7096ae7d899c03902c5b8a9c6 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sat Feb 25 20:25:18 2012 +0000 Initialisation of the Completions is now done in a pure virtual. This means that every REPLCompletable object will ACTUALLY register completion strings, ONLY if we are running a REPL and that object is ACTUALLY created. Otherwise, why bother? Adding completions for all exposed REPLCompletable objects Also, fixed an issue with _getCompletions() commit 412c3778fb04aa1c7379f8e760afce702b0428dd Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 21 00:49:17 2012 +0000 Few more tweaks to the REPL: - Now 'phantom' is the first QObject with proper completion - No repetition in QObject completions - LVAL of any user expression is now correctly prettified and printed Major things left to do: - Cache completions (using QCache?) - Add completions for the other QObject - When the LVAL of a user expression is a QObject, print what's expected, not the QObject "real" structure commit 46f04713c8165d898055e15478bb31403f8c93f1 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 7 10:13:23 2012 -0800 Pretty-print expressions result Still not done though: there are issues with the NON-Native JS objects. commit 98b2fe67651dc750b62c6fa9cf1d80317fd9ae06 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Fri Feb 3 00:22:52 2012 -0800 Introducing REPLCompletable. This class should be inherited by any JavaScript-exposed QObject, to ensure correct Auto-Completion. Correct auto-completion for QObjects. - Now even QObjects can correctly provide auto-completion, and avoid showing "not for users" methods - The strings used for the auto-completion are stored in a single Index: minimum memory footprint - Still, there is optimization that should be done (when "searching" for the right completion by prefix) - Completion for the objects not set up yet, but now it's just a trivial sequence of "addCompletion('bla')" in their constructors commit 9bd48618154b1530a37b41f4060440184e23253d Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Feb 2 00:20:25 2012 -0800 Changing the way we import Linenoise. Will just import a specific commit, and update manually when needed. commit cfc9bae9fbdab13b01019b34b7cbd565e3153780 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 23:22:26 2012 -0800 Made the REPL into a Singleton. With Auto-completion!. Reasons: 1) Needed a pointer to function (i.e. a static method) to be used with Linenoise to provide auto-completions 2) It makes more sense, as it's not like we are going to have 2 REPL running at the same time, are we? There are problems to address: - the enumeration in JS seems to return only the native interface of our objects - the function completions contain argument types of those functions - "private" methods are exposed commit c78bd32e17f8e0e4cc4a0066858de8cc81d33b97 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 22:10:20 2012 -0800 Migrating from the original, now [unmantained Linenoise](https://github.com/antirez/linenoise) to the fairly active [tadmarshall fork](https://github.com/tadmarshall/linenoise). Also now the project is imported as a Git Submodule. Having migrated to the latest Linenoise (see prev. commit), now this _SHOULD_ work on Windows too. But, of course, this needs testing. :) commit 43713c5723d7c5ed446ba41ae8d6f8c9feba7f9b Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Jan 24 23:17:06 2012 -0800 Now that the basics work, I'm adding support for REPL history. This is something almost everyone today is accustomed to. Also, now REPL history works! And I found some useful resources to solve pending TODOs. commit 31e5f88b044a5b4a823c67527ef8c245d2ac7863 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 22 20:56:36 2012 -0800 Adding Linenoise Project (https://github.com/antirez/linenoise). For now is included as a drop-in set of files. Later on, if the Linenoise project has frequent updates, we might prefer to do it as a git-submodule. commit 4be9c15c65db4767e482fba0be13f8aab286d5f3 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Jan 5 15:31:13 2012 +0000 First simple REPL implementation. - Not complete - Still doesn't handle arrow keys (needed for history)
2012-01-05 19:31:13 +04:00
// Create the REPL: it will launch itself, no need to store this variable.
REPL::getInstance(m_page->mainFrame(), this);
} else { // Load the User Script
qDebug() << "Phantom - execute: Starting normal mode";
A REPL for PhantomJS This covers [Issue 252](http://code.google.com/p/phantomjs/issues/detail?id=252) The commit is composed of 12 squashed commits: commit efdc6ba4f143c30a690fd97d92d80fa412e79999 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Mon Feb 27 00:19:36 2012 +0000 Pretty-pringing and Completion Caching done! * This completes pretty-printing for the result of evaluated * expressions in the REPL. * Also, now we cache the "possible completions", to speed things up * a bit (nothing fancy though). * Minor tweaks to the internal doc and the way we "mock" * pretty-printing for QObjects/REPLCompletanle * All tests passing :) commit 1f9ef690e112a535b431fca409b77bb9c09d1c70 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Feb 26 22:35:00 2012 +0000 Moving most of REPL shim JavaScritp code in a separate file. Way easier to work on. commit 02d460a16fee14e7096ae7d899c03902c5b8a9c6 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sat Feb 25 20:25:18 2012 +0000 Initialisation of the Completions is now done in a pure virtual. This means that every REPLCompletable object will ACTUALLY register completion strings, ONLY if we are running a REPL and that object is ACTUALLY created. Otherwise, why bother? Adding completions for all exposed REPLCompletable objects Also, fixed an issue with _getCompletions() commit 412c3778fb04aa1c7379f8e760afce702b0428dd Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 21 00:49:17 2012 +0000 Few more tweaks to the REPL: - Now 'phantom' is the first QObject with proper completion - No repetition in QObject completions - LVAL of any user expression is now correctly prettified and printed Major things left to do: - Cache completions (using QCache?) - Add completions for the other QObject - When the LVAL of a user expression is a QObject, print what's expected, not the QObject "real" structure commit 46f04713c8165d898055e15478bb31403f8c93f1 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 7 10:13:23 2012 -0800 Pretty-print expressions result Still not done though: there are issues with the NON-Native JS objects. commit 98b2fe67651dc750b62c6fa9cf1d80317fd9ae06 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Fri Feb 3 00:22:52 2012 -0800 Introducing REPLCompletable. This class should be inherited by any JavaScript-exposed QObject, to ensure correct Auto-Completion. Correct auto-completion for QObjects. - Now even QObjects can correctly provide auto-completion, and avoid showing "not for users" methods - The strings used for the auto-completion are stored in a single Index: minimum memory footprint - Still, there is optimization that should be done (when "searching" for the right completion by prefix) - Completion for the objects not set up yet, but now it's just a trivial sequence of "addCompletion('bla')" in their constructors commit 9bd48618154b1530a37b41f4060440184e23253d Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Feb 2 00:20:25 2012 -0800 Changing the way we import Linenoise. Will just import a specific commit, and update manually when needed. commit cfc9bae9fbdab13b01019b34b7cbd565e3153780 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 23:22:26 2012 -0800 Made the REPL into a Singleton. With Auto-completion!. Reasons: 1) Needed a pointer to function (i.e. a static method) to be used with Linenoise to provide auto-completions 2) It makes more sense, as it's not like we are going to have 2 REPL running at the same time, are we? There are problems to address: - the enumeration in JS seems to return only the native interface of our objects - the function completions contain argument types of those functions - "private" methods are exposed commit c78bd32e17f8e0e4cc4a0066858de8cc81d33b97 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 22:10:20 2012 -0800 Migrating from the original, now [unmantained Linenoise](https://github.com/antirez/linenoise) to the fairly active [tadmarshall fork](https://github.com/tadmarshall/linenoise). Also now the project is imported as a Git Submodule. Having migrated to the latest Linenoise (see prev. commit), now this _SHOULD_ work on Windows too. But, of course, this needs testing. :) commit 43713c5723d7c5ed446ba41ae8d6f8c9feba7f9b Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Jan 24 23:17:06 2012 -0800 Now that the basics work, I'm adding support for REPL history. This is something almost everyone today is accustomed to. Also, now REPL history works! And I found some useful resources to solve pending TODOs. commit 31e5f88b044a5b4a823c67527ef8c245d2ac7863 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 22 20:56:36 2012 -0800 Adding Linenoise Project (https://github.com/antirez/linenoise). For now is included as a drop-in set of files. Later on, if the Linenoise project has frequent updates, we might prefer to do it as a git-submodule. commit 4be9c15c65db4767e482fba0be13f8aab286d5f3 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Jan 5 15:31:13 2012 +0000 First simple REPL implementation. - Not complete - Still doesn't handle arrow keys (needed for history)
2012-01-05 19:31:13 +04:00
if (m_config.debug()) {
// Debug enabled
if (!Utils::loadJSForDebug(m_config.scriptFile(), m_config.scriptLanguage(), m_scriptFileEnc, QDir::currentPath(), m_page->mainFrame(), m_config.remoteDebugAutorun())) {
A REPL for PhantomJS This covers [Issue 252](http://code.google.com/p/phantomjs/issues/detail?id=252) The commit is composed of 12 squashed commits: commit efdc6ba4f143c30a690fd97d92d80fa412e79999 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Mon Feb 27 00:19:36 2012 +0000 Pretty-pringing and Completion Caching done! * This completes pretty-printing for the result of evaluated * expressions in the REPL. * Also, now we cache the "possible completions", to speed things up * a bit (nothing fancy though). * Minor tweaks to the internal doc and the way we "mock" * pretty-printing for QObjects/REPLCompletanle * All tests passing :) commit 1f9ef690e112a535b431fca409b77bb9c09d1c70 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Feb 26 22:35:00 2012 +0000 Moving most of REPL shim JavaScritp code in a separate file. Way easier to work on. commit 02d460a16fee14e7096ae7d899c03902c5b8a9c6 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sat Feb 25 20:25:18 2012 +0000 Initialisation of the Completions is now done in a pure virtual. This means that every REPLCompletable object will ACTUALLY register completion strings, ONLY if we are running a REPL and that object is ACTUALLY created. Otherwise, why bother? Adding completions for all exposed REPLCompletable objects Also, fixed an issue with _getCompletions() commit 412c3778fb04aa1c7379f8e760afce702b0428dd Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 21 00:49:17 2012 +0000 Few more tweaks to the REPL: - Now 'phantom' is the first QObject with proper completion - No repetition in QObject completions - LVAL of any user expression is now correctly prettified and printed Major things left to do: - Cache completions (using QCache?) - Add completions for the other QObject - When the LVAL of a user expression is a QObject, print what's expected, not the QObject "real" structure commit 46f04713c8165d898055e15478bb31403f8c93f1 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 7 10:13:23 2012 -0800 Pretty-print expressions result Still not done though: there are issues with the NON-Native JS objects. commit 98b2fe67651dc750b62c6fa9cf1d80317fd9ae06 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Fri Feb 3 00:22:52 2012 -0800 Introducing REPLCompletable. This class should be inherited by any JavaScript-exposed QObject, to ensure correct Auto-Completion. Correct auto-completion for QObjects. - Now even QObjects can correctly provide auto-completion, and avoid showing "not for users" methods - The strings used for the auto-completion are stored in a single Index: minimum memory footprint - Still, there is optimization that should be done (when "searching" for the right completion by prefix) - Completion for the objects not set up yet, but now it's just a trivial sequence of "addCompletion('bla')" in their constructors commit 9bd48618154b1530a37b41f4060440184e23253d Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Feb 2 00:20:25 2012 -0800 Changing the way we import Linenoise. Will just import a specific commit, and update manually when needed. commit cfc9bae9fbdab13b01019b34b7cbd565e3153780 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 23:22:26 2012 -0800 Made the REPL into a Singleton. With Auto-completion!. Reasons: 1) Needed a pointer to function (i.e. a static method) to be used with Linenoise to provide auto-completions 2) It makes more sense, as it's not like we are going to have 2 REPL running at the same time, are we? There are problems to address: - the enumeration in JS seems to return only the native interface of our objects - the function completions contain argument types of those functions - "private" methods are exposed commit c78bd32e17f8e0e4cc4a0066858de8cc81d33b97 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 22:10:20 2012 -0800 Migrating from the original, now [unmantained Linenoise](https://github.com/antirez/linenoise) to the fairly active [tadmarshall fork](https://github.com/tadmarshall/linenoise). Also now the project is imported as a Git Submodule. Having migrated to the latest Linenoise (see prev. commit), now this _SHOULD_ work on Windows too. But, of course, this needs testing. :) commit 43713c5723d7c5ed446ba41ae8d6f8c9feba7f9b Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Jan 24 23:17:06 2012 -0800 Now that the basics work, I'm adding support for REPL history. This is something almost everyone today is accustomed to. Also, now REPL history works! And I found some useful resources to solve pending TODOs. commit 31e5f88b044a5b4a823c67527ef8c245d2ac7863 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 22 20:56:36 2012 -0800 Adding Linenoise Project (https://github.com/antirez/linenoise). For now is included as a drop-in set of files. Later on, if the Linenoise project has frequent updates, we might prefer to do it as a git-submodule. commit 4be9c15c65db4767e482fba0be13f8aab286d5f3 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Jan 5 15:31:13 2012 +0000 First simple REPL implementation. - Not complete - Still doesn't handle arrow keys (needed for history)
2012-01-05 19:31:13 +04:00
m_returnValue = -1;
return false;
}
m_page->showInspector(m_config.remoteDebugPort());
} else {
if (!Utils::injectJsInFrame(m_config.scriptFile(), m_config.scriptLanguage(), m_scriptFileEnc, QDir::currentPath(), m_page->mainFrame(), true)) {
A REPL for PhantomJS This covers [Issue 252](http://code.google.com/p/phantomjs/issues/detail?id=252) The commit is composed of 12 squashed commits: commit efdc6ba4f143c30a690fd97d92d80fa412e79999 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Mon Feb 27 00:19:36 2012 +0000 Pretty-pringing and Completion Caching done! * This completes pretty-printing for the result of evaluated * expressions in the REPL. * Also, now we cache the "possible completions", to speed things up * a bit (nothing fancy though). * Minor tweaks to the internal doc and the way we "mock" * pretty-printing for QObjects/REPLCompletanle * All tests passing :) commit 1f9ef690e112a535b431fca409b77bb9c09d1c70 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Feb 26 22:35:00 2012 +0000 Moving most of REPL shim JavaScritp code in a separate file. Way easier to work on. commit 02d460a16fee14e7096ae7d899c03902c5b8a9c6 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sat Feb 25 20:25:18 2012 +0000 Initialisation of the Completions is now done in a pure virtual. This means that every REPLCompletable object will ACTUALLY register completion strings, ONLY if we are running a REPL and that object is ACTUALLY created. Otherwise, why bother? Adding completions for all exposed REPLCompletable objects Also, fixed an issue with _getCompletions() commit 412c3778fb04aa1c7379f8e760afce702b0428dd Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 21 00:49:17 2012 +0000 Few more tweaks to the REPL: - Now 'phantom' is the first QObject with proper completion - No repetition in QObject completions - LVAL of any user expression is now correctly prettified and printed Major things left to do: - Cache completions (using QCache?) - Add completions for the other QObject - When the LVAL of a user expression is a QObject, print what's expected, not the QObject "real" structure commit 46f04713c8165d898055e15478bb31403f8c93f1 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 7 10:13:23 2012 -0800 Pretty-print expressions result Still not done though: there are issues with the NON-Native JS objects. commit 98b2fe67651dc750b62c6fa9cf1d80317fd9ae06 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Fri Feb 3 00:22:52 2012 -0800 Introducing REPLCompletable. This class should be inherited by any JavaScript-exposed QObject, to ensure correct Auto-Completion. Correct auto-completion for QObjects. - Now even QObjects can correctly provide auto-completion, and avoid showing "not for users" methods - The strings used for the auto-completion are stored in a single Index: minimum memory footprint - Still, there is optimization that should be done (when "searching" for the right completion by prefix) - Completion for the objects not set up yet, but now it's just a trivial sequence of "addCompletion('bla')" in their constructors commit 9bd48618154b1530a37b41f4060440184e23253d Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Feb 2 00:20:25 2012 -0800 Changing the way we import Linenoise. Will just import a specific commit, and update manually when needed. commit cfc9bae9fbdab13b01019b34b7cbd565e3153780 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 23:22:26 2012 -0800 Made the REPL into a Singleton. With Auto-completion!. Reasons: 1) Needed a pointer to function (i.e. a static method) to be used with Linenoise to provide auto-completions 2) It makes more sense, as it's not like we are going to have 2 REPL running at the same time, are we? There are problems to address: - the enumeration in JS seems to return only the native interface of our objects - the function completions contain argument types of those functions - "private" methods are exposed commit c78bd32e17f8e0e4cc4a0066858de8cc81d33b97 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 22:10:20 2012 -0800 Migrating from the original, now [unmantained Linenoise](https://github.com/antirez/linenoise) to the fairly active [tadmarshall fork](https://github.com/tadmarshall/linenoise). Also now the project is imported as a Git Submodule. Having migrated to the latest Linenoise (see prev. commit), now this _SHOULD_ work on Windows too. But, of course, this needs testing. :) commit 43713c5723d7c5ed446ba41ae8d6f8c9feba7f9b Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Jan 24 23:17:06 2012 -0800 Now that the basics work, I'm adding support for REPL history. This is something almost everyone today is accustomed to. Also, now REPL history works! And I found some useful resources to solve pending TODOs. commit 31e5f88b044a5b4a823c67527ef8c245d2ac7863 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 22 20:56:36 2012 -0800 Adding Linenoise Project (https://github.com/antirez/linenoise). For now is included as a drop-in set of files. Later on, if the Linenoise project has frequent updates, we might prefer to do it as a git-submodule. commit 4be9c15c65db4767e482fba0be13f8aab286d5f3 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Jan 5 15:31:13 2012 +0000 First simple REPL implementation. - Not complete - Still doesn't handle arrow keys (needed for history)
2012-01-05 19:31:13 +04:00
m_returnValue = -1;
return false;
}
}
}
return !m_terminated;
2010-12-27 07:04:53 +03:00
}
int Phantom::returnValue() const
2010-12-27 07:04:53 +03:00
{
return m_returnValue;
2010-12-27 07:04:53 +03:00
}
QString Phantom::libraryPath() const
{
return m_page->libraryPath();
}
void Phantom::setLibraryPath(const QString &libraryPath)
{
m_page->setLibraryPath(libraryPath);
}
QVariantMap Phantom::version() const
{
QVariantMap result;
result["major"] = PHANTOMJS_VERSION_MAJOR;
result["minor"] = PHANTOMJS_VERSION_MINOR;
result["patch"] = PHANTOMJS_VERSION_PATCH;
return result;
}
QObject *Phantom::page() const
{
return m_page;
}
Config *Phantom::config()
{
return &m_config;
}
bool Phantom::printDebugMessages() const
{
return m_config.printDebugMessages();
}
bool Phantom::areCookiesEnabled() const
{
return m_defaultCookieJar->isEnabled();
}
void Phantom::setCookiesEnabled(const bool value)
{
if (value) {
m_defaultCookieJar->enable();
} else {
m_defaultCookieJar->disable();
}
}
bool Phantom::webdriverMode() const
{
return m_config.isWebdriverMode();
}
// public slots:
QObject *Phantom::createCookieJar(const QString& filePath) {
return new CookieJar(filePath, this);
}
QObject *Phantom::createWebPage()
{
WebPage *page = new WebPage(this);
page->setCookieJar(m_defaultCookieJar);
// Store pointer to the page for later cleanup
m_pages.append(page);
// Apply default settings to the page
2011-05-28 09:36:34 +04:00
page->applySettings(m_defaultPageSettings);
// Show web-inspector if in debug mode
if (m_config.debug()) {
page->showInspector(m_config.remoteDebugPort());
}
return page;
}
QObject* Phantom::createWebServer()
{
WebServer *server = new WebServer(this);
m_servers.append(server);
return server;
}
QObject *Phantom::createFilesystem()
{
if (!m_filesystem)
m_filesystem = new FileSystem(this);
return m_filesystem;
}
QObject *Phantom::createSystem()
{
if (!m_system) {
m_system = new System(this);
QStringList systemArgs;
systemArgs += m_config.scriptFile();
systemArgs += m_config.scriptArgs();
m_system->setArgs(systemArgs);
}
return m_system;
}
QObject *Phantom::_createChildProcess()
{
if (!m_childprocess) {
m_childprocess = new ChildProcess(this);
}
return m_childprocess;
}
QObject* Phantom::createCallback()
{
return new Callback(this);
}
void Phantom::loadModule(const QString &moduleSource, const QString &filename)
{
if (m_terminated)
return;
QString scriptSource =
"(function(require, exports, module) {" +
moduleSource +
"}.call({}," +
"require.cache['" + filename + "']._getRequire()," +
"require.cache['" + filename + "'].exports," +
"require.cache['" + filename + "']" +
"));";
m_page->mainFrame()->evaluateJavaScript(scriptSource);
}
2011-09-11 13:19:20 +04:00
bool Phantom::injectJs(const QString &jsFilePath)
{
QString pre = "";
qDebug() << "Phantom - injectJs:" << jsFilePath;
// If in Remote Webdriver Mode, we need to manipulate the PATH, to point it to a resource in `ghostdriver.qrc`
if (webdriverMode()) {
pre = ":/ghostdriver/";
qDebug() << "Phantom - injectJs: prepending" << pre;
}
if (m_terminated)
return false;
return Utils::injectJsInFrame(pre + jsFilePath, libraryPath(), m_page->mainFrame());
}
void Phantom::setProxy(const QString &ip, const qint64 &port, const QString &proxyType, const QString &user, const QString &password)
{
qDebug() << "Set " << proxyType << " proxy to: " << ip << ":" << port;
if (ip.isEmpty()) {
QNetworkProxyFactory::setUseSystemConfiguration(true);
} else {
QNetworkProxy::ProxyType networkProxyType = QNetworkProxy::HttpProxy;
if (proxyType == "socks5") {
networkProxyType = QNetworkProxy::Socks5Proxy;
}
// Checking for passed proxy user and password
if(!user.isEmpty() && !password.isEmpty()) {
QNetworkProxy proxy(networkProxyType, ip, port, user, password);
QNetworkProxy::setApplicationProxy(proxy);
} else {
QNetworkProxy proxy(networkProxyType, ip, port);
QNetworkProxy::setApplicationProxy(proxy);
}
}
}
void Phantom::exit(int code)
{
A REPL for PhantomJS This covers [Issue 252](http://code.google.com/p/phantomjs/issues/detail?id=252) The commit is composed of 12 squashed commits: commit efdc6ba4f143c30a690fd97d92d80fa412e79999 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Mon Feb 27 00:19:36 2012 +0000 Pretty-pringing and Completion Caching done! * This completes pretty-printing for the result of evaluated * expressions in the REPL. * Also, now we cache the "possible completions", to speed things up * a bit (nothing fancy though). * Minor tweaks to the internal doc and the way we "mock" * pretty-printing for QObjects/REPLCompletanle * All tests passing :) commit 1f9ef690e112a535b431fca409b77bb9c09d1c70 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Feb 26 22:35:00 2012 +0000 Moving most of REPL shim JavaScritp code in a separate file. Way easier to work on. commit 02d460a16fee14e7096ae7d899c03902c5b8a9c6 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sat Feb 25 20:25:18 2012 +0000 Initialisation of the Completions is now done in a pure virtual. This means that every REPLCompletable object will ACTUALLY register completion strings, ONLY if we are running a REPL and that object is ACTUALLY created. Otherwise, why bother? Adding completions for all exposed REPLCompletable objects Also, fixed an issue with _getCompletions() commit 412c3778fb04aa1c7379f8e760afce702b0428dd Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 21 00:49:17 2012 +0000 Few more tweaks to the REPL: - Now 'phantom' is the first QObject with proper completion - No repetition in QObject completions - LVAL of any user expression is now correctly prettified and printed Major things left to do: - Cache completions (using QCache?) - Add completions for the other QObject - When the LVAL of a user expression is a QObject, print what's expected, not the QObject "real" structure commit 46f04713c8165d898055e15478bb31403f8c93f1 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 7 10:13:23 2012 -0800 Pretty-print expressions result Still not done though: there are issues with the NON-Native JS objects. commit 98b2fe67651dc750b62c6fa9cf1d80317fd9ae06 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Fri Feb 3 00:22:52 2012 -0800 Introducing REPLCompletable. This class should be inherited by any JavaScript-exposed QObject, to ensure correct Auto-Completion. Correct auto-completion for QObjects. - Now even QObjects can correctly provide auto-completion, and avoid showing "not for users" methods - The strings used for the auto-completion are stored in a single Index: minimum memory footprint - Still, there is optimization that should be done (when "searching" for the right completion by prefix) - Completion for the objects not set up yet, but now it's just a trivial sequence of "addCompletion('bla')" in their constructors commit 9bd48618154b1530a37b41f4060440184e23253d Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Feb 2 00:20:25 2012 -0800 Changing the way we import Linenoise. Will just import a specific commit, and update manually when needed. commit cfc9bae9fbdab13b01019b34b7cbd565e3153780 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 23:22:26 2012 -0800 Made the REPL into a Singleton. With Auto-completion!. Reasons: 1) Needed a pointer to function (i.e. a static method) to be used with Linenoise to provide auto-completions 2) It makes more sense, as it's not like we are going to have 2 REPL running at the same time, are we? There are problems to address: - the enumeration in JS seems to return only the native interface of our objects - the function completions contain argument types of those functions - "private" methods are exposed commit c78bd32e17f8e0e4cc4a0066858de8cc81d33b97 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 22:10:20 2012 -0800 Migrating from the original, now [unmantained Linenoise](https://github.com/antirez/linenoise) to the fairly active [tadmarshall fork](https://github.com/tadmarshall/linenoise). Also now the project is imported as a Git Submodule. Having migrated to the latest Linenoise (see prev. commit), now this _SHOULD_ work on Windows too. But, of course, this needs testing. :) commit 43713c5723d7c5ed446ba41ae8d6f8c9feba7f9b Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Jan 24 23:17:06 2012 -0800 Now that the basics work, I'm adding support for REPL history. This is something almost everyone today is accustomed to. Also, now REPL history works! And I found some useful resources to solve pending TODOs. commit 31e5f88b044a5b4a823c67527ef8c245d2ac7863 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 22 20:56:36 2012 -0800 Adding Linenoise Project (https://github.com/antirez/linenoise). For now is included as a drop-in set of files. Later on, if the Linenoise project has frequent updates, we might prefer to do it as a git-submodule. commit 4be9c15c65db4767e482fba0be13f8aab286d5f3 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Jan 5 15:31:13 2012 +0000 First simple REPL implementation. - Not complete - Still doesn't handle arrow keys (needed for history)
2012-01-05 19:31:13 +04:00
if (m_config.debug()) {
Terminal::instance()->cout("Phantom::exit() called but not quitting in debug mode.");
A REPL for PhantomJS This covers [Issue 252](http://code.google.com/p/phantomjs/issues/detail?id=252) The commit is composed of 12 squashed commits: commit efdc6ba4f143c30a690fd97d92d80fa412e79999 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Mon Feb 27 00:19:36 2012 +0000 Pretty-pringing and Completion Caching done! * This completes pretty-printing for the result of evaluated * expressions in the REPL. * Also, now we cache the "possible completions", to speed things up * a bit (nothing fancy though). * Minor tweaks to the internal doc and the way we "mock" * pretty-printing for QObjects/REPLCompletanle * All tests passing :) commit 1f9ef690e112a535b431fca409b77bb9c09d1c70 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Feb 26 22:35:00 2012 +0000 Moving most of REPL shim JavaScritp code in a separate file. Way easier to work on. commit 02d460a16fee14e7096ae7d899c03902c5b8a9c6 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sat Feb 25 20:25:18 2012 +0000 Initialisation of the Completions is now done in a pure virtual. This means that every REPLCompletable object will ACTUALLY register completion strings, ONLY if we are running a REPL and that object is ACTUALLY created. Otherwise, why bother? Adding completions for all exposed REPLCompletable objects Also, fixed an issue with _getCompletions() commit 412c3778fb04aa1c7379f8e760afce702b0428dd Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 21 00:49:17 2012 +0000 Few more tweaks to the REPL: - Now 'phantom' is the first QObject with proper completion - No repetition in QObject completions - LVAL of any user expression is now correctly prettified and printed Major things left to do: - Cache completions (using QCache?) - Add completions for the other QObject - When the LVAL of a user expression is a QObject, print what's expected, not the QObject "real" structure commit 46f04713c8165d898055e15478bb31403f8c93f1 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 7 10:13:23 2012 -0800 Pretty-print expressions result Still not done though: there are issues with the NON-Native JS objects. commit 98b2fe67651dc750b62c6fa9cf1d80317fd9ae06 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Fri Feb 3 00:22:52 2012 -0800 Introducing REPLCompletable. This class should be inherited by any JavaScript-exposed QObject, to ensure correct Auto-Completion. Correct auto-completion for QObjects. - Now even QObjects can correctly provide auto-completion, and avoid showing "not for users" methods - The strings used for the auto-completion are stored in a single Index: minimum memory footprint - Still, there is optimization that should be done (when "searching" for the right completion by prefix) - Completion for the objects not set up yet, but now it's just a trivial sequence of "addCompletion('bla')" in their constructors commit 9bd48618154b1530a37b41f4060440184e23253d Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Feb 2 00:20:25 2012 -0800 Changing the way we import Linenoise. Will just import a specific commit, and update manually when needed. commit cfc9bae9fbdab13b01019b34b7cbd565e3153780 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 23:22:26 2012 -0800 Made the REPL into a Singleton. With Auto-completion!. Reasons: 1) Needed a pointer to function (i.e. a static method) to be used with Linenoise to provide auto-completions 2) It makes more sense, as it's not like we are going to have 2 REPL running at the same time, are we? There are problems to address: - the enumeration in JS seems to return only the native interface of our objects - the function completions contain argument types of those functions - "private" methods are exposed commit c78bd32e17f8e0e4cc4a0066858de8cc81d33b97 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 22:10:20 2012 -0800 Migrating from the original, now [unmantained Linenoise](https://github.com/antirez/linenoise) to the fairly active [tadmarshall fork](https://github.com/tadmarshall/linenoise). Also now the project is imported as a Git Submodule. Having migrated to the latest Linenoise (see prev. commit), now this _SHOULD_ work on Windows too. But, of course, this needs testing. :) commit 43713c5723d7c5ed446ba41ae8d6f8c9feba7f9b Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Jan 24 23:17:06 2012 -0800 Now that the basics work, I'm adding support for REPL history. This is something almost everyone today is accustomed to. Also, now REPL history works! And I found some useful resources to solve pending TODOs. commit 31e5f88b044a5b4a823c67527ef8c245d2ac7863 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 22 20:56:36 2012 -0800 Adding Linenoise Project (https://github.com/antirez/linenoise). For now is included as a drop-in set of files. Later on, if the Linenoise project has frequent updates, we might prefer to do it as a git-submodule. commit 4be9c15c65db4767e482fba0be13f8aab286d5f3 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Jan 5 15:31:13 2012 +0000 First simple REPL implementation. - Not complete - Still doesn't handle arrow keys (needed for history)
2012-01-05 19:31:13 +04:00
} else {
doExit(code);
}
}
void Phantom::debugExit(int code)
{
doExit(code);
}
A REPL for PhantomJS This covers [Issue 252](http://code.google.com/p/phantomjs/issues/detail?id=252) The commit is composed of 12 squashed commits: commit efdc6ba4f143c30a690fd97d92d80fa412e79999 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Mon Feb 27 00:19:36 2012 +0000 Pretty-pringing and Completion Caching done! * This completes pretty-printing for the result of evaluated * expressions in the REPL. * Also, now we cache the "possible completions", to speed things up * a bit (nothing fancy though). * Minor tweaks to the internal doc and the way we "mock" * pretty-printing for QObjects/REPLCompletanle * All tests passing :) commit 1f9ef690e112a535b431fca409b77bb9c09d1c70 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Feb 26 22:35:00 2012 +0000 Moving most of REPL shim JavaScritp code in a separate file. Way easier to work on. commit 02d460a16fee14e7096ae7d899c03902c5b8a9c6 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sat Feb 25 20:25:18 2012 +0000 Initialisation of the Completions is now done in a pure virtual. This means that every REPLCompletable object will ACTUALLY register completion strings, ONLY if we are running a REPL and that object is ACTUALLY created. Otherwise, why bother? Adding completions for all exposed REPLCompletable objects Also, fixed an issue with _getCompletions() commit 412c3778fb04aa1c7379f8e760afce702b0428dd Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 21 00:49:17 2012 +0000 Few more tweaks to the REPL: - Now 'phantom' is the first QObject with proper completion - No repetition in QObject completions - LVAL of any user expression is now correctly prettified and printed Major things left to do: - Cache completions (using QCache?) - Add completions for the other QObject - When the LVAL of a user expression is a QObject, print what's expected, not the QObject "real" structure commit 46f04713c8165d898055e15478bb31403f8c93f1 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 7 10:13:23 2012 -0800 Pretty-print expressions result Still not done though: there are issues with the NON-Native JS objects. commit 98b2fe67651dc750b62c6fa9cf1d80317fd9ae06 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Fri Feb 3 00:22:52 2012 -0800 Introducing REPLCompletable. This class should be inherited by any JavaScript-exposed QObject, to ensure correct Auto-Completion. Correct auto-completion for QObjects. - Now even QObjects can correctly provide auto-completion, and avoid showing "not for users" methods - The strings used for the auto-completion are stored in a single Index: minimum memory footprint - Still, there is optimization that should be done (when "searching" for the right completion by prefix) - Completion for the objects not set up yet, but now it's just a trivial sequence of "addCompletion('bla')" in their constructors commit 9bd48618154b1530a37b41f4060440184e23253d Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Feb 2 00:20:25 2012 -0800 Changing the way we import Linenoise. Will just import a specific commit, and update manually when needed. commit cfc9bae9fbdab13b01019b34b7cbd565e3153780 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 23:22:26 2012 -0800 Made the REPL into a Singleton. With Auto-completion!. Reasons: 1) Needed a pointer to function (i.e. a static method) to be used with Linenoise to provide auto-completions 2) It makes more sense, as it's not like we are going to have 2 REPL running at the same time, are we? There are problems to address: - the enumeration in JS seems to return only the native interface of our objects - the function completions contain argument types of those functions - "private" methods are exposed commit c78bd32e17f8e0e4cc4a0066858de8cc81d33b97 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 22:10:20 2012 -0800 Migrating from the original, now [unmantained Linenoise](https://github.com/antirez/linenoise) to the fairly active [tadmarshall fork](https://github.com/tadmarshall/linenoise). Also now the project is imported as a Git Submodule. Having migrated to the latest Linenoise (see prev. commit), now this _SHOULD_ work on Windows too. But, of course, this needs testing. :) commit 43713c5723d7c5ed446ba41ae8d6f8c9feba7f9b Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Jan 24 23:17:06 2012 -0800 Now that the basics work, I'm adding support for REPL history. This is something almost everyone today is accustomed to. Also, now REPL history works! And I found some useful resources to solve pending TODOs. commit 31e5f88b044a5b4a823c67527ef8c245d2ac7863 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 22 20:56:36 2012 -0800 Adding Linenoise Project (https://github.com/antirez/linenoise). For now is included as a drop-in set of files. Later on, if the Linenoise project has frequent updates, we might prefer to do it as a git-submodule. commit 4be9c15c65db4767e482fba0be13f8aab286d5f3 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Jan 5 15:31:13 2012 +0000 First simple REPL implementation. - Not complete - Still doesn't handle arrow keys (needed for history)
2012-01-05 19:31:13 +04:00
// private slots:
void Phantom::printConsoleMessage(const QString &message)
A REPL for PhantomJS This covers [Issue 252](http://code.google.com/p/phantomjs/issues/detail?id=252) The commit is composed of 12 squashed commits: commit efdc6ba4f143c30a690fd97d92d80fa412e79999 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Mon Feb 27 00:19:36 2012 +0000 Pretty-pringing and Completion Caching done! * This completes pretty-printing for the result of evaluated * expressions in the REPL. * Also, now we cache the "possible completions", to speed things up * a bit (nothing fancy though). * Minor tweaks to the internal doc and the way we "mock" * pretty-printing for QObjects/REPLCompletanle * All tests passing :) commit 1f9ef690e112a535b431fca409b77bb9c09d1c70 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Feb 26 22:35:00 2012 +0000 Moving most of REPL shim JavaScritp code in a separate file. Way easier to work on. commit 02d460a16fee14e7096ae7d899c03902c5b8a9c6 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sat Feb 25 20:25:18 2012 +0000 Initialisation of the Completions is now done in a pure virtual. This means that every REPLCompletable object will ACTUALLY register completion strings, ONLY if we are running a REPL and that object is ACTUALLY created. Otherwise, why bother? Adding completions for all exposed REPLCompletable objects Also, fixed an issue with _getCompletions() commit 412c3778fb04aa1c7379f8e760afce702b0428dd Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 21 00:49:17 2012 +0000 Few more tweaks to the REPL: - Now 'phantom' is the first QObject with proper completion - No repetition in QObject completions - LVAL of any user expression is now correctly prettified and printed Major things left to do: - Cache completions (using QCache?) - Add completions for the other QObject - When the LVAL of a user expression is a QObject, print what's expected, not the QObject "real" structure commit 46f04713c8165d898055e15478bb31403f8c93f1 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 7 10:13:23 2012 -0800 Pretty-print expressions result Still not done though: there are issues with the NON-Native JS objects. commit 98b2fe67651dc750b62c6fa9cf1d80317fd9ae06 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Fri Feb 3 00:22:52 2012 -0800 Introducing REPLCompletable. This class should be inherited by any JavaScript-exposed QObject, to ensure correct Auto-Completion. Correct auto-completion for QObjects. - Now even QObjects can correctly provide auto-completion, and avoid showing "not for users" methods - The strings used for the auto-completion are stored in a single Index: minimum memory footprint - Still, there is optimization that should be done (when "searching" for the right completion by prefix) - Completion for the objects not set up yet, but now it's just a trivial sequence of "addCompletion('bla')" in their constructors commit 9bd48618154b1530a37b41f4060440184e23253d Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Feb 2 00:20:25 2012 -0800 Changing the way we import Linenoise. Will just import a specific commit, and update manually when needed. commit cfc9bae9fbdab13b01019b34b7cbd565e3153780 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 23:22:26 2012 -0800 Made the REPL into a Singleton. With Auto-completion!. Reasons: 1) Needed a pointer to function (i.e. a static method) to be used with Linenoise to provide auto-completions 2) It makes more sense, as it's not like we are going to have 2 REPL running at the same time, are we? There are problems to address: - the enumeration in JS seems to return only the native interface of our objects - the function completions contain argument types of those functions - "private" methods are exposed commit c78bd32e17f8e0e4cc4a0066858de8cc81d33b97 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 22:10:20 2012 -0800 Migrating from the original, now [unmantained Linenoise](https://github.com/antirez/linenoise) to the fairly active [tadmarshall fork](https://github.com/tadmarshall/linenoise). Also now the project is imported as a Git Submodule. Having migrated to the latest Linenoise (see prev. commit), now this _SHOULD_ work on Windows too. But, of course, this needs testing. :) commit 43713c5723d7c5ed446ba41ae8d6f8c9feba7f9b Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Jan 24 23:17:06 2012 -0800 Now that the basics work, I'm adding support for REPL history. This is something almost everyone today is accustomed to. Also, now REPL history works! And I found some useful resources to solve pending TODOs. commit 31e5f88b044a5b4a823c67527ef8c245d2ac7863 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 22 20:56:36 2012 -0800 Adding Linenoise Project (https://github.com/antirez/linenoise). For now is included as a drop-in set of files. Later on, if the Linenoise project has frequent updates, we might prefer to do it as a git-submodule. commit 4be9c15c65db4767e482fba0be13f8aab286d5f3 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Jan 5 15:31:13 2012 +0000 First simple REPL implementation. - Not complete - Still doesn't handle arrow keys (needed for history)
2012-01-05 19:31:13 +04:00
{
Terminal::instance()->cout(message);
A REPL for PhantomJS This covers [Issue 252](http://code.google.com/p/phantomjs/issues/detail?id=252) The commit is composed of 12 squashed commits: commit efdc6ba4f143c30a690fd97d92d80fa412e79999 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Mon Feb 27 00:19:36 2012 +0000 Pretty-pringing and Completion Caching done! * This completes pretty-printing for the result of evaluated * expressions in the REPL. * Also, now we cache the "possible completions", to speed things up * a bit (nothing fancy though). * Minor tweaks to the internal doc and the way we "mock" * pretty-printing for QObjects/REPLCompletanle * All tests passing :) commit 1f9ef690e112a535b431fca409b77bb9c09d1c70 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Feb 26 22:35:00 2012 +0000 Moving most of REPL shim JavaScritp code in a separate file. Way easier to work on. commit 02d460a16fee14e7096ae7d899c03902c5b8a9c6 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sat Feb 25 20:25:18 2012 +0000 Initialisation of the Completions is now done in a pure virtual. This means that every REPLCompletable object will ACTUALLY register completion strings, ONLY if we are running a REPL and that object is ACTUALLY created. Otherwise, why bother? Adding completions for all exposed REPLCompletable objects Also, fixed an issue with _getCompletions() commit 412c3778fb04aa1c7379f8e760afce702b0428dd Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 21 00:49:17 2012 +0000 Few more tweaks to the REPL: - Now 'phantom' is the first QObject with proper completion - No repetition in QObject completions - LVAL of any user expression is now correctly prettified and printed Major things left to do: - Cache completions (using QCache?) - Add completions for the other QObject - When the LVAL of a user expression is a QObject, print what's expected, not the QObject "real" structure commit 46f04713c8165d898055e15478bb31403f8c93f1 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 7 10:13:23 2012 -0800 Pretty-print expressions result Still not done though: there are issues with the NON-Native JS objects. commit 98b2fe67651dc750b62c6fa9cf1d80317fd9ae06 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Fri Feb 3 00:22:52 2012 -0800 Introducing REPLCompletable. This class should be inherited by any JavaScript-exposed QObject, to ensure correct Auto-Completion. Correct auto-completion for QObjects. - Now even QObjects can correctly provide auto-completion, and avoid showing "not for users" methods - The strings used for the auto-completion are stored in a single Index: minimum memory footprint - Still, there is optimization that should be done (when "searching" for the right completion by prefix) - Completion for the objects not set up yet, but now it's just a trivial sequence of "addCompletion('bla')" in their constructors commit 9bd48618154b1530a37b41f4060440184e23253d Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Feb 2 00:20:25 2012 -0800 Changing the way we import Linenoise. Will just import a specific commit, and update manually when needed. commit cfc9bae9fbdab13b01019b34b7cbd565e3153780 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 23:22:26 2012 -0800 Made the REPL into a Singleton. With Auto-completion!. Reasons: 1) Needed a pointer to function (i.e. a static method) to be used with Linenoise to provide auto-completions 2) It makes more sense, as it's not like we are going to have 2 REPL running at the same time, are we? There are problems to address: - the enumeration in JS seems to return only the native interface of our objects - the function completions contain argument types of those functions - "private" methods are exposed commit c78bd32e17f8e0e4cc4a0066858de8cc81d33b97 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 22:10:20 2012 -0800 Migrating from the original, now [unmantained Linenoise](https://github.com/antirez/linenoise) to the fairly active [tadmarshall fork](https://github.com/tadmarshall/linenoise). Also now the project is imported as a Git Submodule. Having migrated to the latest Linenoise (see prev. commit), now this _SHOULD_ work on Windows too. But, of course, this needs testing. :) commit 43713c5723d7c5ed446ba41ae8d6f8c9feba7f9b Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Jan 24 23:17:06 2012 -0800 Now that the basics work, I'm adding support for REPL history. This is something almost everyone today is accustomed to. Also, now REPL history works! And I found some useful resources to solve pending TODOs. commit 31e5f88b044a5b4a823c67527ef8c245d2ac7863 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 22 20:56:36 2012 -0800 Adding Linenoise Project (https://github.com/antirez/linenoise). For now is included as a drop-in set of files. Later on, if the Linenoise project has frequent updates, we might prefer to do it as a git-submodule. commit 4be9c15c65db4767e482fba0be13f8aab286d5f3 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Jan 5 15:31:13 2012 +0000 First simple REPL implementation. - Not complete - Still doesn't handle arrow keys (needed for history)
2012-01-05 19:31:13 +04:00
}
A REPL for PhantomJS This covers [Issue 252](http://code.google.com/p/phantomjs/issues/detail?id=252) The commit is composed of 12 squashed commits: commit efdc6ba4f143c30a690fd97d92d80fa412e79999 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Mon Feb 27 00:19:36 2012 +0000 Pretty-pringing and Completion Caching done! * This completes pretty-printing for the result of evaluated * expressions in the REPL. * Also, now we cache the "possible completions", to speed things up * a bit (nothing fancy though). * Minor tweaks to the internal doc and the way we "mock" * pretty-printing for QObjects/REPLCompletanle * All tests passing :) commit 1f9ef690e112a535b431fca409b77bb9c09d1c70 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Feb 26 22:35:00 2012 +0000 Moving most of REPL shim JavaScritp code in a separate file. Way easier to work on. commit 02d460a16fee14e7096ae7d899c03902c5b8a9c6 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sat Feb 25 20:25:18 2012 +0000 Initialisation of the Completions is now done in a pure virtual. This means that every REPLCompletable object will ACTUALLY register completion strings, ONLY if we are running a REPL and that object is ACTUALLY created. Otherwise, why bother? Adding completions for all exposed REPLCompletable objects Also, fixed an issue with _getCompletions() commit 412c3778fb04aa1c7379f8e760afce702b0428dd Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 21 00:49:17 2012 +0000 Few more tweaks to the REPL: - Now 'phantom' is the first QObject with proper completion - No repetition in QObject completions - LVAL of any user expression is now correctly prettified and printed Major things left to do: - Cache completions (using QCache?) - Add completions for the other QObject - When the LVAL of a user expression is a QObject, print what's expected, not the QObject "real" structure commit 46f04713c8165d898055e15478bb31403f8c93f1 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 7 10:13:23 2012 -0800 Pretty-print expressions result Still not done though: there are issues with the NON-Native JS objects. commit 98b2fe67651dc750b62c6fa9cf1d80317fd9ae06 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Fri Feb 3 00:22:52 2012 -0800 Introducing REPLCompletable. This class should be inherited by any JavaScript-exposed QObject, to ensure correct Auto-Completion. Correct auto-completion for QObjects. - Now even QObjects can correctly provide auto-completion, and avoid showing "not for users" methods - The strings used for the auto-completion are stored in a single Index: minimum memory footprint - Still, there is optimization that should be done (when "searching" for the right completion by prefix) - Completion for the objects not set up yet, but now it's just a trivial sequence of "addCompletion('bla')" in their constructors commit 9bd48618154b1530a37b41f4060440184e23253d Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Feb 2 00:20:25 2012 -0800 Changing the way we import Linenoise. Will just import a specific commit, and update manually when needed. commit cfc9bae9fbdab13b01019b34b7cbd565e3153780 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 23:22:26 2012 -0800 Made the REPL into a Singleton. With Auto-completion!. Reasons: 1) Needed a pointer to function (i.e. a static method) to be used with Linenoise to provide auto-completions 2) It makes more sense, as it's not like we are going to have 2 REPL running at the same time, are we? There are problems to address: - the enumeration in JS seems to return only the native interface of our objects - the function completions contain argument types of those functions - "private" methods are exposed commit c78bd32e17f8e0e4cc4a0066858de8cc81d33b97 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 22:10:20 2012 -0800 Migrating from the original, now [unmantained Linenoise](https://github.com/antirez/linenoise) to the fairly active [tadmarshall fork](https://github.com/tadmarshall/linenoise). Also now the project is imported as a Git Submodule. Having migrated to the latest Linenoise (see prev. commit), now this _SHOULD_ work on Windows too. But, of course, this needs testing. :) commit 43713c5723d7c5ed446ba41ae8d6f8c9feba7f9b Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Jan 24 23:17:06 2012 -0800 Now that the basics work, I'm adding support for REPL history. This is something almost everyone today is accustomed to. Also, now REPL history works! And I found some useful resources to solve pending TODOs. commit 31e5f88b044a5b4a823c67527ef8c245d2ac7863 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 22 20:56:36 2012 -0800 Adding Linenoise Project (https://github.com/antirez/linenoise). For now is included as a drop-in set of files. Later on, if the Linenoise project has frequent updates, we might prefer to do it as a git-submodule. commit 4be9c15c65db4767e482fba0be13f8aab286d5f3 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Jan 5 15:31:13 2012 +0000 First simple REPL implementation. - Not complete - Still doesn't handle arrow keys (needed for history)
2012-01-05 19:31:13 +04:00
void Phantom::onInitialized()
{
// Add 'phantom' object to the global scope
m_page->mainFrame()->addToJavaScriptWindowObject("phantom", this);
// Bootstrap the PhantomJS scope
m_page->mainFrame()->evaluateJavaScript(
Utils::readResourceFileUtf8(":/bootstrap.js")
);
A REPL for PhantomJS This covers [Issue 252](http://code.google.com/p/phantomjs/issues/detail?id=252) The commit is composed of 12 squashed commits: commit efdc6ba4f143c30a690fd97d92d80fa412e79999 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Mon Feb 27 00:19:36 2012 +0000 Pretty-pringing and Completion Caching done! * This completes pretty-printing for the result of evaluated * expressions in the REPL. * Also, now we cache the "possible completions", to speed things up * a bit (nothing fancy though). * Minor tweaks to the internal doc and the way we "mock" * pretty-printing for QObjects/REPLCompletanle * All tests passing :) commit 1f9ef690e112a535b431fca409b77bb9c09d1c70 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Feb 26 22:35:00 2012 +0000 Moving most of REPL shim JavaScritp code in a separate file. Way easier to work on. commit 02d460a16fee14e7096ae7d899c03902c5b8a9c6 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sat Feb 25 20:25:18 2012 +0000 Initialisation of the Completions is now done in a pure virtual. This means that every REPLCompletable object will ACTUALLY register completion strings, ONLY if we are running a REPL and that object is ACTUALLY created. Otherwise, why bother? Adding completions for all exposed REPLCompletable objects Also, fixed an issue with _getCompletions() commit 412c3778fb04aa1c7379f8e760afce702b0428dd Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 21 00:49:17 2012 +0000 Few more tweaks to the REPL: - Now 'phantom' is the first QObject with proper completion - No repetition in QObject completions - LVAL of any user expression is now correctly prettified and printed Major things left to do: - Cache completions (using QCache?) - Add completions for the other QObject - When the LVAL of a user expression is a QObject, print what's expected, not the QObject "real" structure commit 46f04713c8165d898055e15478bb31403f8c93f1 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 7 10:13:23 2012 -0800 Pretty-print expressions result Still not done though: there are issues with the NON-Native JS objects. commit 98b2fe67651dc750b62c6fa9cf1d80317fd9ae06 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Fri Feb 3 00:22:52 2012 -0800 Introducing REPLCompletable. This class should be inherited by any JavaScript-exposed QObject, to ensure correct Auto-Completion. Correct auto-completion for QObjects. - Now even QObjects can correctly provide auto-completion, and avoid showing "not for users" methods - The strings used for the auto-completion are stored in a single Index: minimum memory footprint - Still, there is optimization that should be done (when "searching" for the right completion by prefix) - Completion for the objects not set up yet, but now it's just a trivial sequence of "addCompletion('bla')" in their constructors commit 9bd48618154b1530a37b41f4060440184e23253d Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Feb 2 00:20:25 2012 -0800 Changing the way we import Linenoise. Will just import a specific commit, and update manually when needed. commit cfc9bae9fbdab13b01019b34b7cbd565e3153780 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 23:22:26 2012 -0800 Made the REPL into a Singleton. With Auto-completion!. Reasons: 1) Needed a pointer to function (i.e. a static method) to be used with Linenoise to provide auto-completions 2) It makes more sense, as it's not like we are going to have 2 REPL running at the same time, are we? There are problems to address: - the enumeration in JS seems to return only the native interface of our objects - the function completions contain argument types of those functions - "private" methods are exposed commit c78bd32e17f8e0e4cc4a0066858de8cc81d33b97 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 22:10:20 2012 -0800 Migrating from the original, now [unmantained Linenoise](https://github.com/antirez/linenoise) to the fairly active [tadmarshall fork](https://github.com/tadmarshall/linenoise). Also now the project is imported as a Git Submodule. Having migrated to the latest Linenoise (see prev. commit), now this _SHOULD_ work on Windows too. But, of course, this needs testing. :) commit 43713c5723d7c5ed446ba41ae8d6f8c9feba7f9b Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Jan 24 23:17:06 2012 -0800 Now that the basics work, I'm adding support for REPL history. This is something almost everyone today is accustomed to. Also, now REPL history works! And I found some useful resources to solve pending TODOs. commit 31e5f88b044a5b4a823c67527ef8c245d2ac7863 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 22 20:56:36 2012 -0800 Adding Linenoise Project (https://github.com/antirez/linenoise). For now is included as a drop-in set of files. Later on, if the Linenoise project has frequent updates, we might prefer to do it as a git-submodule. commit 4be9c15c65db4767e482fba0be13f8aab286d5f3 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Jan 5 15:31:13 2012 +0000 First simple REPL implementation. - Not complete - Still doesn't handle arrow keys (needed for history)
2012-01-05 19:31:13 +04:00
}
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
bool Phantom::setCookies(const QVariantList &cookies)
{
// Delete all the cookies from the CookieJar
m_defaultCookieJar->clearCookies();
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
// Add a new set of cookies
return m_defaultCookieJar->addCookiesFromMap(cookies);
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
}
QVariantList Phantom::cookies() const
{
// Return all the Cookies in the CookieJar, as a list of Maps (aka JSON in JS space)
return m_defaultCookieJar->cookiesToMap();
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
}
bool Phantom::addCookie(const QVariantMap &cookie)
{
return m_defaultCookieJar->addCookieFromMap(cookie);
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
}
bool Phantom::deleteCookie(const QString &cookieName)
{
if (!cookieName.isEmpty()) {
return m_defaultCookieJar->deleteCookie(cookieName);
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
}
return false;
}
void Phantom::clearCookies()
{
m_defaultCookieJar->clearCookies();
Redesign the Cookies API (part 2) Addresses [Issue #761](http://code.google.com/p/phantomjs/issues/detail?id=761). This is a combination of 5 commits. 1. Date in Cookie can be set via "seconds since epoch" as well. * In addition to the current string format, we can now set cookies via integer of msec since epoch * Expiration date can be set via "expires" or "expiry" option ("expires" has priority) * Returned cookie will contain "expires" as string and "expiry" as msec since epoch I believe this can simplify code that uses cookies and it doesn't change the functionality. 2. Applying the "--debug" command line options as early as possible. 3. Fixing bug and behaviour in the CookieJar * It's not possible to set a cookie without a domain: will default to the domain of the page it's set on * "page.clearCookies()" was broken * "cookiejar.deleteCookie("name", url)" reimplemented because deleting via "expiration" doesn't work 4. Improving (and more fixing) in the CookieJar * Purging Session or Expired Cookies now works * Added boolean return values to inform if the requested cookie operation succeeded * Timestamps for "expiry/expires" in Milliseconds, as JS does by default * Improved detection that a cookie has been accepted or rejected by the cookiejar NOTE: Unfortunately, the Qt provided QNetworkCookieJar is a very limited and not extremely well designed solution. It doesn't provide any "nice and clean" CRUD API, and you are only left with a SET/GET to deal with. Mechanism to understand when and when not a cookie is added are hidden, and require extra work in the sub-class (our CookieJar) to fill the gap. 5. Methods on the "phantom" object to manipulate the CookieJar. * phantom.cookies (array of JSON/Cookies) * phantom.cookiesEnabled (boolean) * phantom.addCookie * phantom.deleteCookie * phantom.clearCookies Those methods operate on the CookieJar directly and have no URL restriction. In other words, if page P1 can see set of cookies C1, and page P2 can see set of cookies C2, "phantom.cookies" can see (i.e. operate upon) both C1 and C2.
2012-09-09 15:24:15 +04:00
}
A REPL for PhantomJS This covers [Issue 252](http://code.google.com/p/phantomjs/issues/detail?id=252) The commit is composed of 12 squashed commits: commit efdc6ba4f143c30a690fd97d92d80fa412e79999 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Mon Feb 27 00:19:36 2012 +0000 Pretty-pringing and Completion Caching done! * This completes pretty-printing for the result of evaluated * expressions in the REPL. * Also, now we cache the "possible completions", to speed things up * a bit (nothing fancy though). * Minor tweaks to the internal doc and the way we "mock" * pretty-printing for QObjects/REPLCompletanle * All tests passing :) commit 1f9ef690e112a535b431fca409b77bb9c09d1c70 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Feb 26 22:35:00 2012 +0000 Moving most of REPL shim JavaScritp code in a separate file. Way easier to work on. commit 02d460a16fee14e7096ae7d899c03902c5b8a9c6 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sat Feb 25 20:25:18 2012 +0000 Initialisation of the Completions is now done in a pure virtual. This means that every REPLCompletable object will ACTUALLY register completion strings, ONLY if we are running a REPL and that object is ACTUALLY created. Otherwise, why bother? Adding completions for all exposed REPLCompletable objects Also, fixed an issue with _getCompletions() commit 412c3778fb04aa1c7379f8e760afce702b0428dd Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 21 00:49:17 2012 +0000 Few more tweaks to the REPL: - Now 'phantom' is the first QObject with proper completion - No repetition in QObject completions - LVAL of any user expression is now correctly prettified and printed Major things left to do: - Cache completions (using QCache?) - Add completions for the other QObject - When the LVAL of a user expression is a QObject, print what's expected, not the QObject "real" structure commit 46f04713c8165d898055e15478bb31403f8c93f1 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 7 10:13:23 2012 -0800 Pretty-print expressions result Still not done though: there are issues with the NON-Native JS objects. commit 98b2fe67651dc750b62c6fa9cf1d80317fd9ae06 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Fri Feb 3 00:22:52 2012 -0800 Introducing REPLCompletable. This class should be inherited by any JavaScript-exposed QObject, to ensure correct Auto-Completion. Correct auto-completion for QObjects. - Now even QObjects can correctly provide auto-completion, and avoid showing "not for users" methods - The strings used for the auto-completion are stored in a single Index: minimum memory footprint - Still, there is optimization that should be done (when "searching" for the right completion by prefix) - Completion for the objects not set up yet, but now it's just a trivial sequence of "addCompletion('bla')" in their constructors commit 9bd48618154b1530a37b41f4060440184e23253d Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Feb 2 00:20:25 2012 -0800 Changing the way we import Linenoise. Will just import a specific commit, and update manually when needed. commit cfc9bae9fbdab13b01019b34b7cbd565e3153780 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 23:22:26 2012 -0800 Made the REPL into a Singleton. With Auto-completion!. Reasons: 1) Needed a pointer to function (i.e. a static method) to be used with Linenoise to provide auto-completions 2) It makes more sense, as it's not like we are going to have 2 REPL running at the same time, are we? There are problems to address: - the enumeration in JS seems to return only the native interface of our objects - the function completions contain argument types of those functions - "private" methods are exposed commit c78bd32e17f8e0e4cc4a0066858de8cc81d33b97 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 22:10:20 2012 -0800 Migrating from the original, now [unmantained Linenoise](https://github.com/antirez/linenoise) to the fairly active [tadmarshall fork](https://github.com/tadmarshall/linenoise). Also now the project is imported as a Git Submodule. Having migrated to the latest Linenoise (see prev. commit), now this _SHOULD_ work on Windows too. But, of course, this needs testing. :) commit 43713c5723d7c5ed446ba41ae8d6f8c9feba7f9b Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Jan 24 23:17:06 2012 -0800 Now that the basics work, I'm adding support for REPL history. This is something almost everyone today is accustomed to. Also, now REPL history works! And I found some useful resources to solve pending TODOs. commit 31e5f88b044a5b4a823c67527ef8c245d2ac7863 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 22 20:56:36 2012 -0800 Adding Linenoise Project (https://github.com/antirez/linenoise). For now is included as a drop-in set of files. Later on, if the Linenoise project has frequent updates, we might prefer to do it as a git-submodule. commit 4be9c15c65db4767e482fba0be13f8aab286d5f3 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Jan 5 15:31:13 2012 +0000 First simple REPL implementation. - Not complete - Still doesn't handle arrow keys (needed for history)
2012-01-05 19:31:13 +04:00
// private:
void Phantom::doExit(int code)
{
A REPL for PhantomJS This covers [Issue 252](http://code.google.com/p/phantomjs/issues/detail?id=252) The commit is composed of 12 squashed commits: commit efdc6ba4f143c30a690fd97d92d80fa412e79999 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Mon Feb 27 00:19:36 2012 +0000 Pretty-pringing and Completion Caching done! * This completes pretty-printing for the result of evaluated * expressions in the REPL. * Also, now we cache the "possible completions", to speed things up * a bit (nothing fancy though). * Minor tweaks to the internal doc and the way we "mock" * pretty-printing for QObjects/REPLCompletanle * All tests passing :) commit 1f9ef690e112a535b431fca409b77bb9c09d1c70 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Feb 26 22:35:00 2012 +0000 Moving most of REPL shim JavaScritp code in a separate file. Way easier to work on. commit 02d460a16fee14e7096ae7d899c03902c5b8a9c6 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sat Feb 25 20:25:18 2012 +0000 Initialisation of the Completions is now done in a pure virtual. This means that every REPLCompletable object will ACTUALLY register completion strings, ONLY if we are running a REPL and that object is ACTUALLY created. Otherwise, why bother? Adding completions for all exposed REPLCompletable objects Also, fixed an issue with _getCompletions() commit 412c3778fb04aa1c7379f8e760afce702b0428dd Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 21 00:49:17 2012 +0000 Few more tweaks to the REPL: - Now 'phantom' is the first QObject with proper completion - No repetition in QObject completions - LVAL of any user expression is now correctly prettified and printed Major things left to do: - Cache completions (using QCache?) - Add completions for the other QObject - When the LVAL of a user expression is a QObject, print what's expected, not the QObject "real" structure commit 46f04713c8165d898055e15478bb31403f8c93f1 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Feb 7 10:13:23 2012 -0800 Pretty-print expressions result Still not done though: there are issues with the NON-Native JS objects. commit 98b2fe67651dc750b62c6fa9cf1d80317fd9ae06 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Fri Feb 3 00:22:52 2012 -0800 Introducing REPLCompletable. This class should be inherited by any JavaScript-exposed QObject, to ensure correct Auto-Completion. Correct auto-completion for QObjects. - Now even QObjects can correctly provide auto-completion, and avoid showing "not for users" methods - The strings used for the auto-completion are stored in a single Index: minimum memory footprint - Still, there is optimization that should be done (when "searching" for the right completion by prefix) - Completion for the objects not set up yet, but now it's just a trivial sequence of "addCompletion('bla')" in their constructors commit 9bd48618154b1530a37b41f4060440184e23253d Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Feb 2 00:20:25 2012 -0800 Changing the way we import Linenoise. Will just import a specific commit, and update manually when needed. commit cfc9bae9fbdab13b01019b34b7cbd565e3153780 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 23:22:26 2012 -0800 Made the REPL into a Singleton. With Auto-completion!. Reasons: 1) Needed a pointer to function (i.e. a static method) to be used with Linenoise to provide auto-completions 2) It makes more sense, as it's not like we are going to have 2 REPL running at the same time, are we? There are problems to address: - the enumeration in JS seems to return only the native interface of our objects - the function completions contain argument types of those functions - "private" methods are exposed commit c78bd32e17f8e0e4cc4a0066858de8cc81d33b97 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 29 22:10:20 2012 -0800 Migrating from the original, now [unmantained Linenoise](https://github.com/antirez/linenoise) to the fairly active [tadmarshall fork](https://github.com/tadmarshall/linenoise). Also now the project is imported as a Git Submodule. Having migrated to the latest Linenoise (see prev. commit), now this _SHOULD_ work on Windows too. But, of course, this needs testing. :) commit 43713c5723d7c5ed446ba41ae8d6f8c9feba7f9b Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Tue Jan 24 23:17:06 2012 -0800 Now that the basics work, I'm adding support for REPL history. This is something almost everyone today is accustomed to. Also, now REPL history works! And I found some useful resources to solve pending TODOs. commit 31e5f88b044a5b4a823c67527ef8c245d2ac7863 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Sun Jan 22 20:56:36 2012 -0800 Adding Linenoise Project (https://github.com/antirez/linenoise). For now is included as a drop-in set of files. Later on, if the Linenoise project has frequent updates, we might prefer to do it as a git-submodule. commit 4be9c15c65db4767e482fba0be13f8aab286d5f3 Author: Ivan De Marino <ivan.de.marino@gmail.com> Date: Thu Jan 5 15:31:13 2012 +0000 First simple REPL implementation. - Not complete - Still doesn't handle arrow keys (needed for history)
2012-01-05 19:31:13 +04:00
emit aboutToExit(code);
m_terminated = true;
m_returnValue = code;
foreach (QPointer<WebPage> page, m_pages) {
if (!page)
continue;
// 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);
2010-12-27 07:04:53 +03:00
}