History

Some more script checks

Atlante45 committed 11 years ago

Commit 3e43a3c1 parent 13b7fa61 file · +9 −17Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 1 file). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+9−17
@@ -79,7 +79,6 @@ void avatarDataFromScriptValue(const QScriptValue &object, AvatarData* &out) { · 78 unmodified lines
79QScriptValue inputControllerToScriptValue(QScriptEngine *engine, AbstractInputController* const &in) {79QScriptValue inputControllerToScriptValue(QScriptEngine *engine, AbstractInputController* const &in) {
80 return engine->newQObject(in);80 return engine->newQObject(in);
81}81}
82
83void inputControllerFromScriptValue(const QScriptValue &object, AbstractInputController* &out) {82void inputControllerFromScriptValue(const QScriptValue &object, AbstractInputController* &out) {
84 out = qobject_cast<AbstractInputController*>(object.toQObject());83 out = qobject_cast<AbstractInputController*>(object.toQObject());
85}84}
@@ -95,9 +94,6 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam · 9 unmodified lines
95 _wantSignals(wantSignals),94 _wantSignals(wantSignals),
96 _controllerScriptingInterface(controllerScriptingInterface),95 _controllerScriptingInterface(controllerScriptingInterface),
97 _fileNameString(fileNameString),96 _fileNameString(fileNameString),
98 _quatLibrary(),
99 _vec3Library(),
100 _uuidLibrary(),
101 _isUserLoaded(false),97 _isUserLoaded(false),
102 _isReloading(false),98 _isReloading(false),
103 _arrayBufferClass(new ArrayBufferClass(this))99 _arrayBufferClass(new ArrayBufferClass(this))
@@ -654,7 +650,9 @@ void ScriptEngine::run() { · 550 unmodified lines
654 }650 }
655 lastUpdate = now;651 lastUpdate = now;
656 652
657 checkExceptions(this, _fileNameString);653 if (!checkExceptions(this, _fileNameString)) {
654 stop();
655 }
658 }656 }
659 657
660 stopAllTimers(); // make sure all our timers are stopped if the script is ending658 stopAllTimers(); // make sure all our timers are stopped if the script is ending
@@ -891,7 +889,6 @@ void ScriptEngine::load(const QString& loadFile) { · 230 unmodified lines
891 }889 }
892}890}
893 891
894
895bool ScriptEngine::checkSyntax(const QScriptProgram& program) {892bool ScriptEngine::checkSyntax(const QScriptProgram& program) {
896 const auto syntaxCheck = QScriptEngine::checkSyntax(program.sourceCode());893 const auto syntaxCheck = QScriptEngine::checkSyntax(program.sourceCode());
897 if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) {894 if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) {
@@ -1005,14 +1002,10 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 107 unmodified lines
1005 1002
1006 auto scriptCache = DependencyManager::get<ScriptCache>();1003 auto scriptCache = DependencyManager::get<ScriptCache>();
1007 bool isFileUrl = isURL && scriptOrURL.startsWith("file://");1004 bool isFileUrl = isURL && scriptOrURL.startsWith("file://");
1005 auto fileName = QString("(EntityID:%1, %2)").arg(entityID.toString(), isURL ? scriptOrURL : "EmbededEntityScript");
1008 1006
1009 // first check the syntax of the script contents1007 QScriptProgram program(contents, fileName);
1010 QScriptSyntaxCheckResult syntaxCheck = QScriptEngine::checkSyntax(contents);1008 if (!checkSyntax(program)) {
1011 if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) {
1012 qCDebug(scriptengine) << "ScriptEngine::loadEntityScript() entity:" << entityID;
1013 qCDebug(scriptengine) << " " << syntaxCheck.errorMessage() << ":"
1014 << syntaxCheck.errorLineNumber() << syntaxCheck.errorColumnNumber();
1015 qCDebug(scriptengine) << " SCRIPT:" << scriptOrURL;
1016 if (!isFileUrl) {1009 if (!isFileUrl) {
1017 scriptCache->addScriptToBadScriptList(scriptOrURL);1010 scriptCache->addScriptToBadScriptList(scriptOrURL);
1018 }1011 }
@@ -1027,9 +1020,9 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 8 unmodified lines
1027 QScriptValue testConstructor = sandbox.evaluate(contents);1020 QScriptValue testConstructor = sandbox.evaluate(contents);
1028 1021
1029 if (!testConstructor.isFunction()) {1022 if (!testConstructor.isFunction()) {
1030 qCDebug(scriptengine) << "ScriptEngine::loadEntityScript() entity:" << entityID;1023 qCDebug(scriptengine) << "ScriptEngine::loadEntityScript() entity:" << entityID << "\n"
1031 qCDebug(scriptengine) << " NOT CONSTRUCTOR";1024 " NOT CONSTRUCTOR\n"
1032 qCDebug(scriptengine) << " SCRIPT:" << scriptOrURL;1025 " SCRIPT:" << scriptOrURL;
1033 if (!isFileUrl) {1026 if (!isFileUrl) {
1034 scriptCache->addScriptToBadScriptList(scriptOrURL);1027 scriptCache->addScriptToBadScriptList(scriptOrURL);
1035 }1028 }
@@ -1042,7 +1035,6 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 6 unmodified lines
1042 lastModified = (quint64)QFileInfo(file).lastModified().toMSecsSinceEpoch();1035 lastModified = (quint64)QFileInfo(file).lastModified().toMSecsSinceEpoch();
1043 }1036 }
1044 1037
1045 auto fileName = QString("(EntityID:%1, %2)").arg(entityID.toString(), isURL ? scriptOrURL : "EmbededEntityScript");
1046 QScriptValue entityScriptConstructor = evaluate(contents, fileName);1038 QScriptValue entityScriptConstructor = evaluate(contents, fileName);
1047 QScriptValue entityScriptObject = entityScriptConstructor.construct();1039 QScriptValue entityScriptObject = entityScriptConstructor.construct();
1048 EntityScriptDetails newDetails = { scriptOrURL, entityScriptObject, lastModified };1040 EntityScriptDetails newDetails = { scriptOrURL, entityScriptObject, lastModified };