forked from treefrogframework/treefrog-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0fefdcd
commit 3ac57f2
Showing
21 changed files
with
16,351 additions
and
4 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* ReactDOMServer v0.14.7 | ||
* | ||
* Copyright 2013-2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
*/ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e(require("react"));else if("function"==typeof define&&define.amd)define(["react"],e);else{var f;f="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,f.ReactDOMServer=e(f.React)}}(function(e){return e.__SECRET_DOM_SERVER_DO_NOT_USE_OR_YOU_WILL_BE_FIRED}); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "tjscontext.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "treactcomponent.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "../src/tjscontext.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "../src/treactcomponent.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* Copyright (c) 2016, AOYAMA Kazuharu | ||
* All rights reserved. | ||
* | ||
* This software may be used and distributed according to the terms of | ||
* the New BSD License, which is incorporated herein by reference. | ||
*/ | ||
|
||
#include <QJSEngine> | ||
#include <QJSValue> | ||
#include <QFile> | ||
#include <QTextStream> | ||
#include "tjscontext.h" | ||
#include "tsystemglobal.h" | ||
|
||
|
||
inline const char *prop(const QJSValue &val, const QString &name = QString()) | ||
{ | ||
return (name.isEmpty()) ? qPrintable(val.toString()) : qPrintable(val.property(name).toString()); | ||
} | ||
|
||
|
||
TJSContext::TJSContext(const QStringList &scriptFiles) | ||
: jsEngine(new QJSEngine()), funcObj(nullptr), lastFunc(), mutex(QMutex::Recursive) | ||
{ | ||
for (auto &file : scriptFiles) { | ||
load(file); | ||
} | ||
} | ||
|
||
|
||
TJSContext::~TJSContext() | ||
{ | ||
if (funcObj) { | ||
delete funcObj; | ||
} | ||
delete jsEngine; | ||
} | ||
|
||
|
||
QJSValue TJSContext::evaluate(const QString &program, const QString &fileName, int lineNumber) | ||
{ | ||
QJSValue ret = jsEngine->evaluate(program, fileName, lineNumber); | ||
if (ret.isError()) { | ||
tSystemError("JS uncaught exception at %s:%s : %s", prop(ret, "fileName"), | ||
prop(ret, "lineNumber"), prop(ret, "message")); | ||
} | ||
return ret; | ||
} | ||
|
||
|
||
QJSValue TJSContext::call(const QString &func, const QJSValue &arg) | ||
{ | ||
QJSValueList args = { arg }; | ||
return call(func, args); | ||
} | ||
|
||
|
||
QJSValue TJSContext::call(const QString &func, const QJSValueList &args) | ||
{ | ||
QMutexLocker locker(&mutex); | ||
QJSValue ret; | ||
|
||
QString funcsym = QString::number(args.count()) + func; | ||
if (funcsym != lastFunc || !funcObj) { | ||
lastFunc = funcsym; | ||
|
||
QString argstr; | ||
for (int i = 0; i < args.count(); i++) { | ||
argstr = QChar('a') + QString::number(i) + ','; | ||
} | ||
argstr.chop(1); | ||
|
||
QString defFunc = QString("function(%1){return(%2(%1));}").arg(argstr, func); | ||
|
||
if (!funcObj) { | ||
funcObj = new QJSValue(); | ||
} | ||
|
||
*funcObj = evaluate(defFunc); | ||
if (funcObj->isError()) { | ||
goto eval_error; | ||
} | ||
} | ||
|
||
ret = funcObj->call(args); | ||
if (ret.isError()) { | ||
tSystemError("JS uncaught exception at %s:%s : %s", prop(ret, "fileName"), | ||
prop(ret, "lineNumber"), prop(ret)); | ||
goto eval_error; | ||
} | ||
|
||
return ret; | ||
|
||
eval_error: | ||
delete funcObj; | ||
funcObj = nullptr; | ||
return ret; | ||
} | ||
|
||
|
||
bool TJSContext::load(const QString &fileName) | ||
{ | ||
QMutexLocker locker(&mutex); | ||
|
||
QFile script(fileName); | ||
if (!script.open(QIODevice::ReadOnly)) { | ||
// open error | ||
tSystemError("TJSContext open error: %s", qPrintable(fileName)); | ||
return false; | ||
} | ||
|
||
QTextStream stream(&script); | ||
QString contents = stream.readAll(); | ||
script.close(); | ||
|
||
QJSValue res = evaluate(contents, fileName); | ||
if (res.isError()) { | ||
return false; | ||
} | ||
|
||
tSystemDebug("TJSContext evaluation completed: %s", qPrintable(fileName)); | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#ifndef TJSCONTEXT_H | ||
#define TJSCONTEXT_H | ||
|
||
#include <QString> | ||
#include <QJSValue> | ||
#include <QMutex> | ||
#include <TGlobal> | ||
|
||
class QJSEngine; | ||
|
||
|
||
class T_CORE_EXPORT TJSContext | ||
{ | ||
public: | ||
TJSContext(const QStringList &scriptFiles = QStringList()); | ||
virtual ~TJSContext(); | ||
|
||
bool load(const QString &scriptFile); | ||
QJSValue evaluate(const QString &program, const QString &fileName = QString(), int lineNumber = 1); | ||
QJSValue call(const QString &func, const QJSValue &arg); | ||
QJSValue call(const QString &func, const QJSValueList &args = QJSValueList()); | ||
|
||
private: | ||
QJSEngine *jsEngine; | ||
QJSValue *funcObj; | ||
QString lastFunc; | ||
QMutex mutex; | ||
|
||
Q_DISABLE_COPY(TJSContext); | ||
}; | ||
|
||
#endif // TJSCONTEXT_H |
Oops, something went wrong.