History

Added simple compile test function

ksuprynowicz committed 4 years ago

Commit 827ddf51 parent 38064b97 files · +83 −19Browse files

Showing the changes to libraries/script-engine/src/v8/ScriptEngineV8.cpp (1 of 7 files). Show all

Unified · Split

libraries/script-engine/src/v8/ScriptEngineV8.cpp+38−11
@@ -134,7 +134,7 @@ ScriptValue ScriptEngineV8::makeError(const ScriptValue& _other, const QString& · 133 unmodified lines
134134 }
135135
136136 // check syntax and when there are issues returns an actual "SyntaxError" with the details
137−ScriptValue ScriptEngineV8::cheskScriptSyntax(ScriptProgramPointer program) {
137+ScriptValue ScriptEngineV8::checkScriptSyntax(ScriptProgramPointer program) {
138138 if (!IS_THREADSAFE_INVOCATION(thread(), __FUNCTION__)) {
139139 return nullValue();
140140 }
@@ -375,10 +375,13 @@ ScriptEngineV8::ScriptEngineV8(ScriptManager* scriptManager) : · 234 unmodified lines
375375 //_arrayBufferClass(new ArrayBufferClass(this))
376376 {
377377 _v8InitMutex.lock();
378− std::call_once ( _v8InitOnceFlag, [ ]{
378+ std::call_once ( _v8InitOnceFlag, [ ]{
379+ v8::V8::InitializeExternalStartupData("");
380+ //V8TODO might cause crashes if it's too much
381+ v8::V8::SetFlagsFromString("--stack-size=900000");
379382 v8::Platform* platform = getV8Platform();
380383 v8::V8::InitializePlatform(platform);
381− v8::V8::Initialize();
384+ v8::V8::Initialize(); qCDebug(scriptengine) << "V8 platform initialized";
382385 } );
383386 _v8InitMutex.unlock();
384387 {
@@ -391,7 +394,8 @@ ScriptEngineV8::ScriptEngineV8(ScriptManager* scriptManager) : · 6 unmodified lines
391394 Q_ASSERT(!context.IsEmpty());
392395 v8::Context::Scope contextScope(context);
393396 _v8Context = v8::UniquePersistent<v8::Context>(_v8Isolate, context);
394−
397+
398+
395399 V8ScriptValue nullScriptValue(_v8Isolate, v8::Null(_v8Isolate));
396400 _nullValue = ScriptValue(new ScriptValueV8Wrapper(this, nullScriptValue));
397401
@@ -427,7 +431,7 @@ ScriptEngineV8::ScriptEngineV8(ScriptManager* scriptManager) : · 29 unmodified lines
427431 }
428432 }, Qt::DirectConnection);*/
429433 //moveToThread(scriptManager->thread());
430− setThread(scriptManager->thread());
434+ //setThread(scriptManager->thread());
431435 }
432436 }
433437
@@ -789,6 +793,7 @@ ScriptValue ScriptEngineV8::evaluate(const QString& sourceCode, const QString& f · 355 unmodified lines
789793 }
790794 // Compile and check syntax
791795 // V8TODO: Could these all be replaced with checkSyntax function from wrapper?
796+ Q_ASSERT(!_v8Isolate->IsDead());
792797 v8::HandleScope handleScope(_v8Isolate);
793798 v8::Context::Scope contextScope(_v8Context.Get(_v8Isolate));
794799 v8::TryCatch tryCatch(getIsolate());
@@ -799,7 +804,8 @@ ScriptValue ScriptEngineV8::evaluate(const QString& sourceCode, const QString& f · 4 unmodified lines
799804 int errorLineNumber = 0;
800805 QString errorMessage = "";
801806 QString errorBacktrace = "";
802− v8::String::Utf8Value utf8Value(getIsolate(), tryCatch.Exception());
807+ //v8::String::Utf8Value utf8Value(getIsolate(), tryCatch.Exception());
808+ v8::String::Utf8Value utf8Value(getIsolate(), tryCatch.Message()->Get());
803809 errorMessage = QString(*utf8Value);
804810 v8::Local<v8::Message> exceptionMessage = tryCatch.Message();
805811 if (!exceptionMessage.IsEmpty()) {
@@ -811,12 +817,14 @@ ScriptValue ScriptEngineV8::evaluate(const QString& sourceCode, const QString& f · 5 unmodified lines
811817 v8::String::Utf8Value backtraceUtf8Value(getIsolate(), backtraceV8String);
812818 errorBacktrace = *backtraceUtf8Value;
813819 }
820+ qCDebug(scriptengine) << "Compiling script \"" << fileName << "\" failed on line " << errorLineNumber << " column " << errorColumnNumber << " with message: \"" << errorMessage <<"\" backtrace: " << errorBacktrace;
814821 }
815822 auto err = makeError(newValue(errorMessage));
816823 raiseException(err);
817824 maybeEmitUncaughtException("compile");
818825 return err;
819826 }
827+ qCDebug(scriptengine) << "Script compilation succesful: " << fileName;
820828
821829 //V8TODO
822830 /*auto syntaxError = lintScript(sourceCode, fileName);
@@ -1170,16 +1178,20 @@ QThread* ScriptEngineV8::thread() const { · 347 unmodified lines
11701178 }
11711179
11721180 void ScriptEngineV8::setThread(QThread* thread) {
1173− qDebug() << "Moved script engine " << objectName() << " to different thread";
1174− _v8Isolate->Exit();
1181+ if (_v8Isolate->IsCurrent()) {
1182+ _v8Isolate->Exit();
1183+ qDebug() << "Script engine " << objectName() << " exited isolate";
1184+ }
11751185 moveToThread(thread);
1176− QMetaObject::invokeMethod(this, "enterIsolateOnThisThread");
1186+ qDebug() << "Moved script engine " << objectName() << " to different thread";
11771187 }
11781188
11791189 void ScriptEngineV8::enterIsolateOnThisThread() {
11801190 Q_ASSERT(thread() == QThread::currentThread());
1181− _v8Isolate->Enter();
1182− qDebug() << "Script engine " << objectName() << " entered isolate on a new thread";
1191+ if (!_v8Isolate->IsCurrent()) {
1192+ _v8Isolate->Enter();
1193+ qDebug() << "Script engine " << objectName() << " entered isolate on a new thread";
1194+ }
11831195 }
11841196
11851197
@@ -1238,3 +1250,18 @@ QVariant ScriptEngineV8::convert(const ScriptValue& value, int typeId) { · 52 unmodified lines
12381250 return var;
12391251 return QVariant();
12401252 }
1253+
1254+void ScriptEngineV8::compileTest() {
1255+ v8::Locker locker(_v8Isolate);
1256+ v8::Isolate::Scope isolateScope(_v8Isolate);
1257+ v8::HandleScope handleScope(_v8Isolate);
1258+ v8::Context::Scope contextScope(_v8Context.Get(_v8Isolate));
1259+ v8::Local<v8::Script> script;
1260+ v8::ScriptOrigin scriptOrigin(getIsolate(), v8::String::NewFromUtf8(getIsolate(),"test").ToLocalChecked());
1261+ if (v8::Script::Compile(getContext(), v8::String::NewFromUtf8(getIsolate(), "print(\"hello world\");").ToLocalChecked(), &scriptOrigin).ToLocal(&script)) {
1262+ qCDebug(scriptengine) << "Compile test succesful";
1263+ } else {
1264+ qCDebug(scriptengine) << "Compile test failed";
1265+ Q_ASSERT(false);
1266+ }
1267+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t