History

Timeout long sandbox scripts

Zach Pomerantz committed 10 years ago

Commit e1c130d1 parent 11078821 file · +16 −1Browse 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+16−1
@@ -1292,8 +1292,23 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 1291 unmodified lines
1292 setParentURL(scriptOrURL);1292 setParentURL(scriptOrURL);
1293 }1293 }
1294 1294
1295 const int SANDBOX_TIMEOUT = 0.25 * MSECS_PER_SECOND;
1295 QScriptEngine sandbox;1296 QScriptEngine sandbox;
1296 QScriptValue testConstructor = sandbox.evaluate(program);1297 sandbox.setProcessEventsInterval(SANDBOX_TIMEOUT);
1298 QScriptValue testConstructor;
1299 {
1300 QTimer timeout;
1301 timeout.setSingleShot(true);
1302 timeout.start(SANDBOX_TIMEOUT);
1303 connect(&timeout, &QTimer::timeout, [&sandbox, SANDBOX_TIMEOUT]{
1304 auto context = sandbox.currentContext();
1305 if (context) {
1306 // Guard against infinite loops and non-performant code
1307 context->throwError(QString("Timed out (entity constructors are limited to %1ms)").arg(SANDBOX_TIMEOUT));
1308 }
1309 });
1310 testConstructor = sandbox.evaluate(program);
1311 }
1297 if (hadUncaughtExceptions(sandbox, program.fileName())) {1312 if (hadUncaughtExceptions(sandbox, program.fileName())) {
1298 return;1313 return;
1299 }1314 }