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