本文整理汇总了C++中QScriptSyntaxCheckResult::errorMessage方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptSyntaxCheckResult::errorMessage方法的具体用法?C++ QScriptSyntaxCheckResult::errorMessage怎么用?C++ QScriptSyntaxCheckResult::errorMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptSyntaxCheckResult
的用法示例。
在下文中一共展示了QScriptSyntaxCheckResult::errorMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: js_include
//-- \subsection{include(file)}
//-- Includes another source code file at this point. This is experimental, and breaks the
//-- lint tool, so use with care.
static QScriptValue js_include(QScriptContext *context, QScriptEngine *engine)
{
QString path = context->argument(0).toString();
UDWORD size;
char *bytes = NULL;
if (!loadFile(path.toAscii().constData(), &bytes, &size))
{
debug(LOG_ERROR, "Failed to read include file \"%s\"", path.toAscii().constData());
return QScriptValue(false);
}
QString source = QString::fromAscii(bytes, size);
free(bytes);
QScriptSyntaxCheckResult syntax = QScriptEngine::checkSyntax(source);
if (syntax.state() != QScriptSyntaxCheckResult::Valid)
{
debug(LOG_ERROR, "Syntax error in include %s line %d: %s",
path.toAscii().constData(), syntax.errorLineNumber(), syntax.errorMessage().toAscii().constData());
return QScriptValue(false);
}
context->setActivationObject(engine->globalObject());
context->setThisObject(engine->globalObject());
QScriptValue result = engine->evaluate(source, path);
if (engine->hasUncaughtException())
{
int line = engine->uncaughtExceptionLineNumber();
debug(LOG_ERROR, "Uncaught exception at line %d, include file %s: %s",
line, path.toAscii().constData(), result.toString().toAscii().constData());
return QScriptValue(false);
}
return QScriptValue(true);
}
示例2: check
bool ProgramScriptAction::check(const QString &xmlFile, const TypeRule *rule,
SymFactory *factory)
{
Q_UNUSED(rule);
Q_UNUSED(factory);
// Delete old program
if (_program) {
delete _program;
_program = 0;
}
QScriptSyntaxCheckResult result =
QScriptEngine::checkSyntax(_srcCode);
if (result.state() != QScriptSyntaxCheckResult::Valid) {
typeRuleError2(xmlFile,
srcLine() + result.errorLineNumber() - 1,
result.errorColumnNumber(),
QString("Syntax error: %1")
.arg(result.errorMessage()));
}
else {
// Wrap the code into a function so that the return statement
// is available to the code
QString code = QString("function %1() {\n%2\n}")
.arg(js::inlinefunc).arg(_srcCode);
_program = new QScriptProgram(code, xmlFile, srcLine() - 1);
}
return true;
}
示例3: execFile
bool Terminal::execFile(QString filePath) {
if(!Utils::isExtension(filePath, QString("js"))) {
std::cout << "File Invalid..."
<< std::endl
<< "Acceptable extension *.js";
return false;
}
QString script = Utils::getContent(filePath);
if(script.isEmpty()) { return false; }
QScriptSyntaxCheckResult result = this->m_engine->checkSyntax(script);
if(result.state() == QScriptSyntaxCheckResult::Error) {
QString error("Error on line %1 column %2\nMessage: %3");
error = error.arg(QString::number(result.errorLineNumber()),
QString::number(result.errorColumnNumber()),
result.errorMessage());
std::cout << error.toAscii().constData() << std::endl;
return false;
}
Jsws *jsws = new Jsws(this->m_engine, script,parent());
QScriptValue value = this->m_engine->newQObject(jsws);
this->m_engine->globalObject().setProperty("WS", value);
this->m_engine->evaluate(script);
return true;
}
示例4: loadPlayerScript
bool loadPlayerScript(QString path, int player, int difficulty)
{
ASSERT_OR_RETURN(false, player < MAX_PLAYERS, "Player index %d out of bounds", player);
QScriptEngine *engine = new QScriptEngine();
UDWORD size;
char *bytes = NULL;
if (!loadFile(path.toAscii().constData(), &bytes, &size))
{
debug(LOG_ERROR, "Failed to read script file \"%s\"", path.toAscii().constData());
return false;
}
QString source = QString::fromAscii(bytes, size);
free(bytes);
QScriptSyntaxCheckResult syntax = QScriptEngine::checkSyntax(source);
ASSERT_OR_RETURN(false, syntax.state() == QScriptSyntaxCheckResult::Valid, "Syntax error in %s line %d: %s",
path.toAscii().constData(), syntax.errorLineNumber(), syntax.errorMessage().toAscii().constData());
// Remember internal, reserved names
QScriptValueIterator it(engine->globalObject());
while (it.hasNext())
{
it.next();
internalNamespace.insert(it.name(), 1);
}
QScriptValue result = engine->evaluate(source, path);
ASSERT_OR_RETURN(false, !engine->hasUncaughtException(), "Uncaught exception at line %d, file %s: %s",
engine->uncaughtExceptionLineNumber(), path.toAscii().constData(), result.toString().toAscii().constData());
// Special functions
engine->globalObject().setProperty("setTimer", engine->newFunction(js_setTimer));
engine->globalObject().setProperty("queue", engine->newFunction(js_queue));
engine->globalObject().setProperty("removeTimer", engine->newFunction(js_removeTimer));
engine->globalObject().setProperty("include", engine->newFunction(js_include));
engine->globalObject().setProperty("bind", engine->newFunction(js_bind));
// Special global variables
engine->globalObject().setProperty("me", player, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("selectedPlayer", selectedPlayer, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("gameTime", gameTime, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("difficulty", difficulty, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("mapName", game.map, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("baseType", game.base, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("alliancesType", game.alliance, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("powerType", game.power, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("maxPlayers", game.maxPlayers, QScriptValue::ReadOnly | QScriptValue::Undeletable);
engine->globalObject().setProperty("scavengers", game.scavengers, QScriptValue::ReadOnly | QScriptValue::Undeletable);
// Regular functions
registerFunctions(engine);
// Register script
scripts.push_back(engine);
return true;
}
示例5: Load
void JavascriptInstance::Load()
{
PROFILE(JSInstance_Load);
if (!engine_)
CreateEngine();
if (sourceFile.isEmpty() && scriptRefs_.empty())
{
LogError("JavascriptInstance::Load: No script content to load!");
return;
}
// Can't specify both a file source and an Asset API source.
if (!sourceFile.isEmpty() && !scriptRefs_.empty())
{
LogError("JavascriptInstance::Load: Cannot specify both an local input source file and a list of script refs to load!");
return;
}
bool useAssetAPI = !scriptRefs_.empty();
size_t numScripts = useAssetAPI ? scriptRefs_.size() : 1;
// Determine based on code origin whether it can be trusted with system access or not
if (useAssetAPI)
{
trusted_ = true;
for(unsigned i = 0; i < scriptRefs_.size(); ++i)
trusted_ = trusted_ && scriptRefs_[i]->IsTrusted();
}
else // Local file: always trusted.
{
program_ = LoadScript(sourceFile);
trusted_ = true; // This is a file on the local filesystem. We are making an assumption nobody can inject untrusted code here.
// Actually, we are assuming the attacker does not know the absolute location of the asset cache locally here, since if he makes
// the client to load a script into local cache, he could use this code path to automatically load that unsafe script from cache, and make it trusted. -jj.
}
// Check the validity of the syntax in the input.
for (size_t i = 0; i < numScripts; ++i)
{
QString scriptSourceFilename = (useAssetAPI ? scriptRefs_[i]->Name() : sourceFile);
QString &scriptContent = (useAssetAPI ? scriptRefs_[i]->scriptContent : program_);
QScriptSyntaxCheckResult syntaxResult = engine_->checkSyntax(scriptContent);
if (syntaxResult.state() != QScriptSyntaxCheckResult::Valid)
{
LogError("Syntax error in script " + scriptSourceFilename + "," + QString::number(syntaxResult.errorLineNumber()) +
": " + syntaxResult.errorMessage());
// Delete our loaded script content (if any exists).
program_ == "";
}
}
}
示例6: performSyntaxCheck
bool ScriptLoader::performSyntaxCheck(const QString & script)
{
QScriptSyntaxCheckResult syntaxCheck = p_engine->checkSyntax(script);
if(syntaxCheck.state() != QScriptSyntaxCheckResult::Valid)
{
qDebug() << "ScriptLoader::load: Syntax error in the script";
qDebug() << "Line" << syntaxCheck.errorLineNumber() << ": error:" << syntaxCheck.errorMessage();
return false;
}
return true;
}
示例7: QObject
ScriptSandbox::ScriptSandbox(const PluginManager *parent, const QString &file, const QString &script, AdamantPlugin *owner)
: QObject()
, _manager(parent)
, _script(script)
, _owner(owner)
, _engine()
, _engineDebugger()
, _errorString()
{
_engineDebugger.attachTo(&_engine);
_program = QScriptProgram(_script, file);
// Register MetaTypes, sometimes Q_DECL doesn't seem to cut it...
qRegisterMetaType<Session::Request*>("Session::Request");
qRegisterMetaType<AdamantUI*>("AdamantUI");
qRegisterMetaType<ItemManager*>("ItemManager");
qRegisterMetaType<AdamantUI::ApplicationTheme>("ApplicationTheme");
// qScriptRegisterMetaType<AdamantUI::ApplicationTheme>(&_engine, [](QScriptEngine *engine, const AdamantUI::ApplicationTheme &t) -> QScriptValue {
// return QScriptValue(static_cast<int>(t));
// }, [](const QScriptValue &obj, AdamantUI::ApplicationTheme &t) {
// t = static_cast<AdamantUI::ApplicationTheme>(obj.toInt32());
// });
QScriptSyntaxCheckResult syntax = _engine.checkSyntax(_script);
if (syntax.state() != QScriptSyntaxCheckResult::Valid){
_errorString = syntax.errorMessage();
}
else {
// Default Globals
addGlobalObject("manager", (QObject*)_manager);
addGlobalObject("script", this);
addGlobalObject("core", _manager->core());
addGlobalObject("app", qApp);
}
{
QScriptValue func = _engine.newFunction(ScriptSandbox::runFunc, this);
_engine.globalObject().setProperty("run", func);
}
{
QScriptValue func = _engine.newFunction(ScriptSandbox::importFunc, this);
_engine.globalObject().setProperty("using", func);
}
{
QScriptValue func = _engine.newFunction(ScriptSandbox::printFunc, this);
_engine.globalObject().setProperty("print", func);
}
}
示例8: if
Script::Script(QString script)
{
setObjectName(metaObject()->className());
addOutputPort("ERROR");
//From http://www.qtcentre.org/threads/10425-QtScript-newFunction-won-t-work
QScriptValue that = scriptEngine.newQObject(this, QScriptEngine::QtOwnership, QScriptEngine::ExcludeChildObjects
| QScriptEngine::ExcludeSuperClassMethods | QScriptEngine::ExcludeSuperClassProperties);
scriptEngine.globalObject().setProperty("self",that);
//Log in console
scriptEngine.evaluate("function echo(str){self.scriptEcho(str);};");
//Add input
scriptEngine.evaluate("function addInputPort(str){self.scriptAddInputPort(str);};");
//Add output
scriptEngine.evaluate("function addOutputPort(str){self.scriptAddOutputPort(str);};");
//Set self starting
scriptEngine.evaluate("function setSelfStarting(str){self.scriptSetSelfStarting(str);};");
//Receive
scriptEngine.evaluate("function receive(str){return self.scriptReceive(str);};");
//Send
scriptEngine.evaluate("function send(str, val){self.scriptSend(str, val);};");
//Read file
scriptEngine.evaluate("function readFile(str){return self.scriptReadFile(str);};");
//------------------------------------------------------------------
// EVALUATE THE SCRIPT
//------------------------------------------------------------------
QScriptSyntaxCheckResult check = scriptEngine.checkSyntax(script);
if(check.state() != QScriptSyntaxCheckResult::Valid)
{
std::cerr << QString("Error in script line %1, column %2: %3")
.arg(check.errorLineNumber())
.arg(check.errorColumnNumber())
.arg(check.errorMessage())
.toStdString() << std::endl;
}
else if(!scriptEngine.canEvaluate(script))
{
std::cerr << QString("Can't evaluate script: unknown error.")
.toStdString() << std::endl;
}
else
{
scriptEngine.evaluate(script);
scriptEngine.evaluate("init()");
}
}
示例9: isApplied
bool QtScriptFemCondition3D::setCondition(QString script)
{
QString func = "function isApplied(x, y, z){\n";
func += "return " + script + ";\n}";
script_ = script;
QScriptSyntaxCheckResult chk = QScriptEngine::checkSyntax(func);
if (chk.state() != QScriptSyntaxCheckResult::Valid)
{
std::cout << "Ошибка анализа граничного условия: " << chk.errorMessage().toStdString() << std::endl;
return false;
}
object_ = engine_.evaluate(func);
if (object_.isError())return false;
return true;
}
示例10: loadEntityScript
QScriptValue EntityTreeRenderer::loadEntityScript(EntityItem* entity) {
if (!entity) {
return QScriptValue(); // no entity...
}
EntityItemID entityID = entity->getEntityItemID();
if (_entityScripts.contains(entityID)) {
EntityScriptDetails details = _entityScripts[entityID];
// check to make sure our script text hasn't changed on us since we last loaded it
if (details.scriptText == entity->getScript()) {
return details.scriptObject; // previously loaded
}
// if we got here, then we previously loaded a script, but the entity's script value
// has changed and so we need to reload it.
_entityScripts.remove(entityID);
}
if (entity->getScript().isEmpty()) {
return QScriptValue(); // no script
}
QString scriptContents = loadScriptContents(entity->getScript());
QScriptSyntaxCheckResult syntaxCheck = QScriptEngine::checkSyntax(scriptContents);
if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) {
qDebug() << "EntityTreeRenderer::loadEntityScript() entity:" << entityID;
qDebug() << " " << syntaxCheck.errorMessage() << ":"
<< syntaxCheck.errorLineNumber() << syntaxCheck.errorColumnNumber();
qDebug() << " SCRIPT:" << entity->getScript();
return QScriptValue(); // invalid script
}
QScriptValue entityScriptConstructor = _entitiesScriptEngine->evaluate(scriptContents);
if (!entityScriptConstructor.isFunction()) {
qDebug() << "EntityTreeRenderer::loadEntityScript() entity:" << entityID;
qDebug() << " NOT CONSTRUCTOR";
qDebug() << " SCRIPT:" << entity->getScript();
return QScriptValue(); // invalid script
}
QScriptValue entityScriptObject = entityScriptConstructor.construct();
EntityScriptDetails newDetails = { entity->getScript(), entityScriptObject };
_entityScripts[entityID] = newDetails;
return entityScriptObject; // newly constructed
}
示例11: evaluate
void CConsole::evaluate() {
QScriptSyntaxCheckResult result = m_engine->checkSyntax( m_text->toPlainText() );
switch (result.state()) {
case QScriptSyntaxCheckResult::Valid:
qDebug() << "Valid Syntax";
break;
case QScriptSyntaxCheckResult::Error:
case QScriptSyntaxCheckResult::Intermediate:
qDebug() << "Invalid Syntax at" << result.errorLineNumber() << result.errorMessage();
return;
break;
};
if(m_engine->canEvaluate( m_text->toPlainText() )) {
qDebug() << "Evaluatable";
} else {
qDebug() << "Non-evaluatable";
}
}
示例12: IncludeFile
void JavascriptInstance::IncludeFile(const QString &path)
{
for(uint i = 0; i < includedFiles.size(); ++i)
if (includedFiles[i].toLower() == path.toLower())
{
LogDebug("JavascriptInstance::IncludeFile: Not including already included file " + path);
return;
}
QString script = LoadScript(path);
QScriptContext *context = engine_->currentContext();
assert(context);
if (!context)
{
LogError("JavascriptInstance::IncludeFile: QScriptEngine::currentContext() returned null!");
return;
}
QScriptContext *parent = context->parentContext();
if (!parent)
{
LogError("JavascriptInstance::IncludeFile: QScriptEngine::parentContext() returned null!");
return;
}
context->setActivationObject(context->parentContext()->activationObject());
context->setThisObject(context->parentContext()->thisObject());
QScriptSyntaxCheckResult syntaxResult = engine_->checkSyntax(script);
if(syntaxResult.state() != QScriptSyntaxCheckResult::Valid)
{
LogError("JavascriptInstance::IncludeFile: Syntax error in " + path + ". " + syntaxResult.errorMessage() +
" In line:" + QString::number(syntaxResult.errorLineNumber()));
return;
}
QScriptValue result = engine_->evaluate(script, path);
includedFiles.push_back(path);
if (engine_->hasUncaughtException())
LogError(result.toString());
}
示例13: accept
void ScriptForm::accept()
{
m_script = textEdit->toPlainText();
QScriptEngine javaScriptParser;
int errorLineNumber = 0;
QString errorMessage;
#if QT_VERSION >= 0x040500
QScriptSyntaxCheckResult syntaxResult =
javaScriptParser.checkSyntax(m_script);
if (syntaxResult.state() != QScriptSyntaxCheckResult::Valid) {
errorLineNumber = syntaxResult.errorLineNumber();
errorMessage = syntaxResult.errorMessage();
if (errorMessage.isEmpty())
errorMessage = tr("Syntax Error");
}
#else
QScriptValue value(&javaScriptParser, 0);
javaScriptParser.globalObject().setProperty("cellRow", value);
javaScriptParser.globalObject().setProperty("cellColumn", value);
javaScriptParser.globalObject().setProperty("cellValue", value);
QScriptValue result = javaScriptParser.evaluate(m_script);
if (javaScriptParser.hasUncaughtException()) {
errorLineNumber = javaScriptParser
.uncaughtExceptionLineNumber();
errorMessage = javaScriptParser.uncaughtException()
.toString();
}
#endif
if (!errorMessage.isEmpty()) {
AQP::warning(this, tr("Error"),
tr("Invalid script on line %1:\n%2")
.arg(errorLineNumber).arg(errorMessage));
QTextCursor cursor = textEdit->textCursor();
cursor.clearSelection();
cursor.movePosition(QTextCursor::Start);
cursor.movePosition(QTextCursor::Down,
QTextCursor::MoveAnchor, errorLineNumber - 1);
cursor.select(QTextCursor::LineUnderCursor);
textEdit->setTextCursor(cursor);
}
else
QDialog::accept();
}
示例14: vehicleQueryComplete
void DroneshareUploadDialog::vehicleQueryComplete(const QString &jsonResponse)
{
QLOG_DEBUG() << "droneshare: Vehicle Query Complete"/* << jsonResponse*/;
QScriptSyntaxCheckResult syntaxCheck = QScriptEngine::checkSyntax(jsonResponse);
QScriptEngine engine;
QScriptValue result = engine.evaluate("("+jsonResponse+")");
if (engine.hasUncaughtException()){
QLOG_ERROR() << "Error evaluating version object";
QLOG_ERROR() << "Error @line#" << engine.uncaughtExceptionLineNumber();
QLOG_ERROR() << "Backtrace:" << engine.uncaughtExceptionBacktrace();
QLOG_ERROR() << "Syntax Check:" << syntaxCheck.errorMessage();
QLOG_ERROR() << "Syntax Check line:" << syntaxCheck.errorLineNumber()
<< " col:" << syntaxCheck.errorColumnNumber();
return;
}
ui->statusLabel->setText("Vehicle Query Complete.");
QMap<QString,QString> vehicleList;
QScriptValue entries = result.property("vehicles");
QScriptValueIterator it(entries);
while (it.hasNext()){
it.next();
QScriptValue entry = it.value();
QString uuid = entry.property("uuid").toString();
QString name = entry.property("name").toString();
vehicleList.insert(name,uuid);
}
bool ok = false;
QString item = QInputDialog::getItem(this, tr("Vehicle Selection"),tr("vehicle"),vehicleList.keys(),1,
false, &ok, Qt::Dialog, Qt::ImhNone);
if (ok){
startLogUpload(vehicleList.value(item));
}
m_droneshareQuery->deleteLater();
m_droneshareQuery = NULL;
}
示例15: writeProgram
void BluemonkeySink::writeProgram(QString program)
{
QScriptSyntaxCheckResult result = QScriptEngine::checkSyntax(program);
if(result.state() != QScriptSyntaxCheckResult::Valid)
{
DebugOut(DebugOut::Error)<<"Syntax error in program: "<<result.errorMessage().toStdString()<<endl;
return;
}
QFile file(configuration["customPrograms"].c_str());
if(!file.open(QIODevice::ReadWrite | QIODevice::Append))
{
DebugOut(DebugOut::Error)<<"failed to open file: "<<file.fileName().toStdString()<<endl;
return;
}
file.write(program.toUtf8());
file.write("\n");
file.close();
}