mirror of https://github.com/vitalif/phantomjs
Make CSConverter a real singleton.
parent
8af4fa714c
commit
d3f10a8e18
|
@ -29,14 +29,24 @@
|
||||||
|
|
||||||
#include "csconverter.h"
|
#include "csconverter.h"
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QWebFrame>
|
#include <QWebFrame>
|
||||||
|
|
||||||
#include "registry.h"
|
#include "registry.h"
|
||||||
|
|
||||||
// public:
|
static CSConverter *csconverter_instance = 0;
|
||||||
CSConverter::CSConverter(QObject *parent)
|
|
||||||
: QObject(parent)
|
CSConverter *CSConverter::instance()
|
||||||
|
{
|
||||||
|
if (!csconverter_instance)
|
||||||
|
csconverter_instance = new CSConverter();
|
||||||
|
|
||||||
|
return csconverter_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
CSConverter::CSConverter()
|
||||||
|
: QObject(QCoreApplication::instance())
|
||||||
{
|
{
|
||||||
QFile file(":/coffee-script.js");
|
QFile file(":/coffee-script.js");
|
||||||
if (!file.open(QFile::ReadOnly)) {
|
if (!file.open(QFile::ReadOnly)) {
|
||||||
|
|
|
@ -36,10 +36,11 @@
|
||||||
class CSConverter: public QObject
|
class CSConverter: public QObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CSConverter(QObject *parent = 0);
|
static CSConverter *instance();
|
||||||
QVariant convert(const QString &script);
|
QVariant convert(const QString &script);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
CSConverter();
|
||||||
QWebPage m_webPage;
|
QWebPage m_webPage;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -72,13 +72,7 @@ void Utils::messageHandler(QtMsgType type, const char *msg)
|
||||||
|
|
||||||
QVariant Utils::coffee2js(const QString &script)
|
QVariant Utils::coffee2js(const QString &script)
|
||||||
{
|
{
|
||||||
// We need only one instance of the CSConverter to survive for the whole life of PhantomJS
|
return CSConverter::instance()->convert(script);
|
||||||
static CSConverter *coffeeScriptConverter = NULL;
|
|
||||||
if ( !coffeeScriptConverter ) {
|
|
||||||
coffeeScriptConverter = new CSConverter();
|
|
||||||
}
|
|
||||||
|
|
||||||
return coffeeScriptConverter->convert(script);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Utils::injectJsInFrame(const QString &jsFilePath, const QString &libraryPath, QWebFrame *targetFrame, const bool startingScript)
|
bool Utils::injectJsInFrame(const QString &jsFilePath, const QString &libraryPath, QWebFrame *targetFrame, const bool startingScript)
|
||||||
|
|
Loading…
Reference in New Issue