History

rework ScriptValue to act like a stack variable rather than a pointer

Heather Anderson committed 5 years ago

Commit 85810221 parent f209c51170 files · +2837 −2594Browse files

Showing the changes to libraries/script-engine/src/qtscript/ScriptEngineQtScript.cpp (1 of 170 files). Show all

Unified · Split

libraries/script-engine/src/qtscript/ScriptEngineQtScript.cpp+94−94
@@ -62,7 +62,7 @@ static const QScriptValue::PropertyFlags READONLY_HIDDEN_PROP_FLAGS { READONLY_P · 61 unmodified lines
62 62
63static const bool HIFI_AUTOREFRESH_FILE_SCRIPTS { true };63static const bool HIFI_AUTOREFRESH_FILE_SCRIPTS { true };
64 64
65Q_DECLARE_METATYPE(ScriptValuePointer);65Q_DECLARE_METATYPE(ScriptValue);
66 66
67Q_DECLARE_METATYPE(QScriptEngine::FunctionSignature)67Q_DECLARE_METATYPE(QScriptEngine::FunctionSignature)
68int qfunctionSignatureMetaID = qRegisterMetaType<QScriptEngine::FunctionSignature>();68int qfunctionSignatureMetaID = qRegisterMetaType<QScriptEngine::FunctionSignature>();
@@ -120,26 +120,26 @@ QScriptValue ScriptEngineQtScript::makeError(const QScriptValue& _other, const Q · 51 unmodified lines
120 return err;120 return err;
121}121}
122 122
123ScriptValuePointer ScriptEngineQtScript::makeError(const ScriptValuePointer& _other, const QString& type) {123ScriptValue ScriptEngineQtScript::makeError(const ScriptValue& _other, const QString& type) {
124 if (!IS_THREADSAFE_INVOCATION(thread(), __FUNCTION__)) {124 if (!IS_THREADSAFE_INVOCATION(thread(), __FUNCTION__)) {
125 return nullValue();125 return nullValue();
126 }126 }
127 ScriptValueQtWrapper* unwrapped = ScriptValueQtWrapper::unwrap(_other);127 ScriptValueQtWrapper* unwrapped = ScriptValueQtWrapper::unwrap(_other);
128 QScriptValue other;128 QScriptValue other;
129 if (_other->isString()) {129 if (_other.isString()) {
130 other = QScriptEngine::newObject();130 other = QScriptEngine::newObject();
131 other.setProperty("message", _other->toString());131 other.setProperty("message", _other.toString());
132 } else if (unwrapped) {132 } else if (unwrapped) {
133 other = unwrapped->toQtValue();133 other = unwrapped->toQtValue();
134 } else {134 } else {
135 other = QScriptEngine::newVariant(_other->toVariant());135 other = QScriptEngine::newVariant(_other.toVariant());
136 }136 }
137 QScriptValue result = makeError(other, type);137 QScriptValue result = makeError(other, type);
138 return ScriptValuePointer(new ScriptValueQtWrapper(this, std::move(result)));138 return ScriptValue(new ScriptValueQtWrapper(this, std::move(result)));
139}139}
140 140
141// check syntax and when there are issues returns an actual "SyntaxError" with the details141// check syntax and when there are issues returns an actual "SyntaxError" with the details
142ScriptValuePointer ScriptEngineQtScript::lintScript(const QString& sourceCode, const QString& fileName, const int lineNumber) {142ScriptValue ScriptEngineQtScript::lintScript(const QString& sourceCode, const QString& fileName, const int lineNumber) {
143 if (!IS_THREADSAFE_INVOCATION(thread(), __FUNCTION__)) {143 if (!IS_THREADSAFE_INVOCATION(thread(), __FUNCTION__)) {
144 return nullValue();144 return nullValue();
145 }145 }
@@ -158,13 +158,13 @@ ScriptValuePointer ScriptEngineQtScript::lintScript(const QString& sourceCode, c · 12 unmodified lines
158 const auto message = QString("[SyntaxError] %1 in %2:%3(%4)").arg(error, fileName, line, column);158 const auto message = QString("[SyntaxError] %1 in %2:%3(%4)").arg(error, fileName, line, column);
159 err.setProperty("formatted", message);159 err.setProperty("formatted", message);
160 }160 }
161 return ScriptValuePointer(new ScriptValueQtWrapper(this, std::move(err)));161 return ScriptValue(new ScriptValueQtWrapper(this, std::move(err)));
162 }162 }
163 return undefinedValue();163 return undefinedValue();
164}164}
165 165
166// this pulls from the best available information to create a detailed snapshot of the current exception166// this pulls from the best available information to create a detailed snapshot of the current exception
167ScriptValuePointer ScriptEngineQtScript::cloneUncaughtException(const QString& extraDetail) {167ScriptValue ScriptEngineQtScript::cloneUncaughtException(const QString& extraDetail) {
168 if (!IS_THREADSAFE_INVOCATION(thread(), __FUNCTION__)) {168 if (!IS_THREADSAFE_INVOCATION(thread(), __FUNCTION__)) {
169 return nullValue();169 return nullValue();
170 }170 }
@@ -178,17 +178,17 @@ ScriptValuePointer ScriptEngineQtScript::cloneUncaughtException(const QString& e · 7 unmodified lines
178 // not sure why Qt does't offer uncaughtExceptionFileName -- but the line number178 // not sure why Qt does't offer uncaughtExceptionFileName -- but the line number
179 // on its own is often useless/wrong if arbitrarily married to a filename.179 // on its own is often useless/wrong if arbitrarily married to a filename.
180 // when the error object already has this info, it seems to be the most reliable180 // when the error object already has this info, it seems to be the most reliable
181 auto fileName = exception->property("fileName")->toString();181 auto fileName = exception.property("fileName").toString();
182 auto lineNumber = exception->property("lineNumber")->toInt32();182 auto lineNumber = exception.property("lineNumber").toInt32();
183 183
184 // the backtrace, on the other hand, seems most reliable taken from uncaughtExceptionBacktrace184 // the backtrace, on the other hand, seems most reliable taken from uncaughtExceptionBacktrace
185 auto backtrace = uncaughtExceptionBacktrace();185 auto backtrace = uncaughtExceptionBacktrace();
186 if (backtrace.isEmpty()) {186 if (backtrace.isEmpty()) {
187 // fallback to the error object187 // fallback to the error object
188 backtrace = exception->property("stack")->toString().split(ScriptManager::SCRIPT_BACKTRACE_SEP);188 backtrace = exception.property("stack").toString().split(ScriptManager::SCRIPT_BACKTRACE_SEP);
189 }189 }
190 // the ad hoc "detail" property can be used now to embed additional clues190 // the ad hoc "detail" property can be used now to embed additional clues
191 auto detail = exception->property("detail")->toString();191 auto detail = exception.property("detail").toString();
192 if (detail.isEmpty()) {192 if (detail.isEmpty()) {
193 detail = extraDetail;193 detail = extraDetail;
194 } else if (!extraDetail.isEmpty()) {194 } else if (!extraDetail.isEmpty()) {
@@ -212,15 +212,15 @@ ScriptValuePointer ScriptEngineQtScript::cloneUncaughtException(const QString& e · 17 unmodified lines
212 }212 }
213 }213 }
214 }214 }
215 err->setProperty("fileName", fileName);215 err.setProperty("fileName", fileName);
216 err->setProperty("lineNumber", lineNumber);216 err.setProperty("lineNumber", lineNumber);
217 err->setProperty("detail", detail);217 err.setProperty("detail", detail);
218 err->setProperty("stack", backtrace.join(ScriptManager::SCRIPT_BACKTRACE_SEP));218 err.setProperty("stack", backtrace.join(ScriptManager::SCRIPT_BACKTRACE_SEP));
219 219
220#ifdef DEBUG_JS_EXCEPTIONS220#ifdef DEBUG_JS_EXCEPTIONS
221 err->setProperty("_fileName", exception.property("fileName").toString());221 err.setProperty("_fileName", exception.property("fileName").toString());
222 err->setProperty("_stack", uncaughtExceptionBacktrace().join(SCRIPT_BACKTRACE_SEP));222 err.setProperty("_stack", uncaughtExceptionBacktrace().join(SCRIPT_BACKTRACE_SEP));
223 err->setProperty("_lineNumber", uncaughtExceptionLineNumber());223 err.setProperty("_lineNumber", uncaughtExceptionLineNumber());
224#endif224#endif
225 return err;225 return err;
226}226}
@@ -237,7 +237,7 @@ bool ScriptEngineQtScript::raiseException(const QScriptValue& exception) { · 10 unmodified lines
237 // we are within a pure C++ stack frame (ie: being called directly by other C++ code)237 // we are within a pure C++ stack frame (ie: being called directly by other C++ code)
238 // in this case no context information is available so just emit the exception for reporting238 // in this case no context information is available so just emit the exception for reporting
239 QScriptValue thrown = makeError(exception);239 QScriptValue thrown = makeError(exception);
240 emit _manager->unhandledException(ScriptValuePointer(new ScriptValueQtWrapper(this, std::move(thrown))));240 emit _manager->unhandledException(ScriptValue(new ScriptValueQtWrapper(this, std::move(thrown))));
241 }241 }
242 return false;242 return false;
243}243}
@@ -383,13 +383,13 @@ static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine) { · 139 unmodified lines
383 return QScriptValue();383 return QScriptValue();
384}384}
385 385
386static QScriptValue ScriptValueToQScriptValue(QScriptEngine* engine, const ScriptValuePointer& src) {386static QScriptValue ScriptValueToQScriptValue(QScriptEngine* engine, const ScriptValue& src) {
387 return ScriptValueQtWrapper::fullUnwrap(static_cast<ScriptEngineQtScript*>(engine), src);387 return ScriptValueQtWrapper::fullUnwrap(static_cast<ScriptEngineQtScript*>(engine), src);
388}388}
389 389
390static void ScriptValueFromQScriptValue(const QScriptValue& src, ScriptValuePointer& dest) {390static void ScriptValueFromQScriptValue(const QScriptValue& src, ScriptValue& dest) {
391 ScriptEngineQtScript* engine = static_cast<ScriptEngineQtScript*>(src.engine());391 ScriptEngineQtScript* engine = static_cast<ScriptEngineQtScript*>(src.engine());
392 dest = ScriptValuePointer(new ScriptValueQtWrapper(engine, src));392 dest = ScriptValue(new ScriptValueQtWrapper(engine, src));
393}393}
394 394
395ScriptEngineQtScript::ScriptEngineQtScript(ScriptManager* scriptManager) :395ScriptEngineQtScript::ScriptEngineQtScript(ScriptManager* scriptManager) :
@@ -408,17 +408,17 @@ ScriptEngineQtScript::ScriptEngineQtScript(ScriptManager* scriptManager) : · 12 unmodified lines
408 } else {408 } else {
409 // ... but may not always be available -- so if needed we fallback to the passed exception409 // ... but may not always be available -- so if needed we fallback to the passed exception
410 QScriptValue thrown = makeError(exception);410 QScriptValue thrown = makeError(exception);
411 emit _manager->unhandledException(ScriptValuePointer(new ScriptValueQtWrapper(this, std::move(thrown))));411 emit _manager->unhandledException(ScriptValue(new ScriptValueQtWrapper(this, std::move(thrown))));
412 }412 }
413 }, Qt::DirectConnection);413 }, Qt::DirectConnection);
414 moveToThread(scriptManager->thread());414 moveToThread(scriptManager->thread());
415 }415 }
416 416
417 QScriptValue null = QScriptEngine::nullValue();417 QScriptValue null = QScriptEngine::nullValue();
418 _nullValue = ScriptValuePointer(new ScriptValueQtWrapper(const_cast<ScriptEngineQtScript*>(this), std::move(null)));418 _nullValue = ScriptValue(new ScriptValueQtWrapper(const_cast<ScriptEngineQtScript*>(this), std::move(null)));
419 419
420 QScriptValue undefined = QScriptEngine::undefinedValue();420 QScriptValue undefined = QScriptEngine::undefinedValue();
421 _undefinedValue = ScriptValuePointer(new ScriptValueQtWrapper(const_cast<ScriptEngineQtScript*>(this), std::move(undefined)));421 _undefinedValue = ScriptValue(new ScriptValueQtWrapper(const_cast<ScriptEngineQtScript*>(this), std::move(undefined)));
422 422
423 QScriptEngine::setProcessEventsInterval(MSECS_PER_SECOND);423 QScriptEngine::setProcessEventsInterval(MSECS_PER_SECOND);
424}424}
@@ -478,14 +478,14 @@ void ScriptEngineQtScript::registerValue(const QString& valueName, QScriptValue · 53 unmodified lines
478 478
479 QStringList pathToValue = valueName.split(".");479 QStringList pathToValue = valueName.split(".");
480 int partsToGo = pathToValue.length();480 int partsToGo = pathToValue.length();
481 QScriptValue partObject = globalObject();481 QScriptValue partObject = QScriptEngine::globalObject();
482 482
483 for (const auto& pathPart : pathToValue) {483 for (const auto& pathPart : pathToValue) {
484 partsToGo--;484 partsToGo--;
485 if (!partObject.property(pathPart).isValid()) {485 if (!partObject.property(pathPart).isValid()) {
486 if (partsToGo > 0) {486 if (partsToGo > 0) {
487 //QObject *object = new QObject;487 //QObject *object = new QObject;
488 QScriptValue partValue = newArray(); //newQObject(object, QScriptEngine::ScriptOwnership);488 QScriptValue partValue = QScriptEngine::newArray(); //newQObject(object, QScriptEngine::ScriptOwnership);
489 partObject.setProperty(pathPart, partValue);489 partObject.setProperty(pathPart, partValue);
490 } else {490 } else {
491 partObject.setProperty(pathPart, value);491 partObject.setProperty(pathPart, value);
@@ -554,7 +554,7 @@ void ScriptEngineQtScript::registerFunction(const QString& name, ScriptEngine::F · 62 unmodified lines
554#endif554#endif
555 555
556 auto scriptFun = newFunction(functionSignature, numArguments);556 auto scriptFun = newFunction(functionSignature, numArguments);
557 globalObject()->setProperty(name, scriptFun);557 globalObject().setProperty(name, scriptFun);
558}558}
559 559
560void ScriptEngineQtScript::registerFunction(const QString& parent, const QString& name, QScriptEngine::FunctionSignature functionSignature, int numArguments) {560void ScriptEngineQtScript::registerFunction(const QString& parent, const QString& name, QScriptEngine::FunctionSignature functionSignature, int numArguments) {
@@ -594,10 +594,10 @@ void ScriptEngineQtScript::registerFunction(const QString& parent, const QString · 33 unmodified lines
594 qCDebug(scriptengine) << "ScriptEngineQtScript::registerFunction() called on thread [" << QThread::currentThread() << "] parent:" << parent << "name:" << name;594 qCDebug(scriptengine) << "ScriptEngineQtScript::registerFunction() called on thread [" << QThread::currentThread() << "] parent:" << parent << "name:" << name;
595#endif595#endif
596 596
597 auto object = globalObject()->property(parent);597 auto object = globalObject().property(parent);
598 if (object->isValid()) {598 if (object.isValid()) {
599 auto scriptFun = newFunction(functionSignature, numArguments);599 auto scriptFun = newFunction(functionSignature, numArguments);
600 object->setProperty(name, scriptFun);600 object.setProperty(name, scriptFun);
601 }601 }
602}602}
603 603
@@ -656,18 +656,18 @@ void ScriptEngineQtScript::registerGetterSetter(const QString& name, ScriptEngin · 52 unmodified lines
656 auto getterFunction = newFunction(getter);656 auto getterFunction = newFunction(getter);
657 657
658 if (!parent.isNull() && !parent.isEmpty()) {658 if (!parent.isNull() && !parent.isEmpty()) {
659 auto object = globalObject()->property(parent);659 auto object = globalObject().property(parent);
660 if (object->isValid()) {660 if (object.isValid()) {
661 object->setProperty(name, setterFunction, ScriptValue::PropertySetter);661 object.setProperty(name, setterFunction, ScriptValue::PropertySetter);
662 object->setProperty(name, getterFunction, ScriptValue::PropertyGetter);662 object.setProperty(name, getterFunction, ScriptValue::PropertyGetter);
663 }663 }
664 } else {664 } else {
665 globalObject()->setProperty(name, setterFunction, ScriptValue::PropertySetter);665 globalObject().setProperty(name, setterFunction, ScriptValue::PropertySetter);
666 globalObject()->setProperty(name, getterFunction, ScriptValue::PropertyGetter);666 globalObject().setProperty(name, getterFunction, ScriptValue::PropertyGetter);
667 }667 }
668}668}
669 669
670ScriptValuePointer ScriptEngineQtScript::evaluateInClosure(const ScriptValuePointer& _closure,670ScriptValue ScriptEngineQtScript::evaluateInClosure(const ScriptValue& _closure,
671 const ScriptProgramPointer& _program) {671 const ScriptProgramPointer& _program) {
672 PROFILE_RANGE(script, "evaluateInClosure");672 PROFILE_RANGE(script, "evaluateInClosure");
673 if (!IS_THREADSAFE_INVOCATION(thread(), __FUNCTION__)) {673 if (!IS_THREADSAFE_INVOCATION(thread(), __FUNCTION__)) {
@@ -712,7 +712,7 @@ ScriptValuePointer ScriptEngineQtScript::evaluateInClosure(const ScriptValuePoin · 38 unmodified lines
712#ifdef DEBUG_JS712#ifdef DEBUG_JS
713 qCDebug(shared) << QString("[%1] evaluateInClosure %2").arg(isEvaluating()).arg(shortName);713 qCDebug(shared) << QString("[%1] evaluateInClosure %2").arg(isEvaluating()).arg(shortName);
714#endif714#endif
715 ScriptValuePointer result;715 ScriptValue result;
716 {716 {
717 auto qResult = QScriptEngine::evaluate(program);717 auto qResult = QScriptEngine::evaluate(program);
718 718
@@ -724,7 +724,7 @@ ScriptValuePointer ScriptEngineQtScript::evaluateInClosure(const ScriptValuePoin · 5 unmodified lines
724#endif724#endif
725 result = err;725 result = err;
726 } else {726 } else {
727 result = ScriptValuePointer(new ScriptValueQtWrapper(this, std::move(qResult)));727 result = ScriptValue(new ScriptValueQtWrapper(this, std::move(qResult)));
728 }728 }
729 }729 }
730#ifdef DEBUG_JS730#ifdef DEBUG_JS
@@ -742,19 +742,19 @@ ScriptValuePointer ScriptEngineQtScript::evaluateInClosure(const ScriptValuePoin · 11 unmodified lines
742 return result;742 return result;
743}743}
744 744
745ScriptValuePointer ScriptEngineQtScript::evaluate(const QString& sourceCode, const QString& fileName) {745ScriptValue ScriptEngineQtScript::evaluate(const QString& sourceCode, const QString& fileName) {
746 if (_manager && _manager->isStopped()) {746 if (_manager && _manager->isStopped()) {
747 return undefinedValue(); // bail early747 return undefinedValue(); // bail early
748 }748 }
749 749
750 if (QThread::currentThread() != QScriptEngine::thread()) {750 if (QThread::currentThread() != QScriptEngine::thread()) {
751 ScriptValuePointer result;751 ScriptValue result;
752#ifdef THREAD_DEBUGGING752#ifdef THREAD_DEBUGGING
753 qCDebug(scriptengine) << "*** WARNING *** ScriptEngineQtScript::evaluate() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "753 qCDebug(scriptengine) << "*** WARNING *** ScriptEngineQtScript::evaluate() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "
754 "sourceCode:" << sourceCode << " fileName:" << fileName;754 "sourceCode:" << sourceCode << " fileName:" << fileName;
755#endif755#endif
756 BLOCKING_INVOKE_METHOD(this, "evaluate",756 BLOCKING_INVOKE_METHOD(this, "evaluate",
757 Q_RETURN_ARG(ScriptValuePointer, result),757 Q_RETURN_ARG(ScriptValue, result),
758 Q_ARG(const QString&, sourceCode),758 Q_ARG(const QString&, sourceCode),
759 Q_ARG(const QString&, fileName));759 Q_ARG(const QString&, fileName));
760 return result;760 return result;
@@ -762,9 +762,9 @@ ScriptValuePointer ScriptEngineQtScript::evaluate(const QString& sourceCode, con · 1 unmodified line
762 762
763 // Check syntax763 // Check syntax
764 auto syntaxError = lintScript(sourceCode, fileName);764 auto syntaxError = lintScript(sourceCode, fileName);
765 if (syntaxError->isError()) {765 if (syntaxError.isError()) {
766 if (!isEvaluating()) {766 if (!isEvaluating()) {
767 syntaxError->setProperty("detail", "evaluate");767 syntaxError.setProperty("detail", "evaluate");
768 }768 }
769 raiseException(syntaxError);769 raiseException(syntaxError);
770 maybeEmitUncaughtException("lint");770 maybeEmitUncaughtException("lint");
@@ -782,22 +782,22 @@ ScriptValuePointer ScriptEngineQtScript::evaluate(const QString& sourceCode, con · 11 unmodified lines
782 QScriptValue result = QScriptEngine::evaluate(program);782 QScriptValue result = QScriptEngine::evaluate(program);
783 maybeEmitUncaughtException("evaluate");783 maybeEmitUncaughtException("evaluate");
784 784
785 return ScriptValuePointer(new ScriptValueQtWrapper(this, std::move(result)));785 return ScriptValue(new ScriptValueQtWrapper(this, std::move(result)));
786}786}
787 787
788Q_INVOKABLE ScriptValuePointer ScriptEngineQtScript::evaluate(const ScriptProgramPointer& program) {788Q_INVOKABLE ScriptValue ScriptEngineQtScript::evaluate(const ScriptProgramPointer& program) {
789 if (_manager && _manager->isStopped()) {789 if (_manager && _manager->isStopped()) {
790 return undefinedValue(); // bail early790 return undefinedValue(); // bail early
791 }791 }
792 792
793 if (QThread::currentThread() != QScriptEngine::thread()) {793 if (QThread::currentThread() != QScriptEngine::thread()) {
794 ScriptValuePointer result;794 ScriptValue result;
795#ifdef THREAD_DEBUGGING795#ifdef THREAD_DEBUGGING
796 qCDebug(scriptengine) << "*** WARNING *** ScriptEngineQtScript::evaluate() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "796 qCDebug(scriptengine) << "*** WARNING *** ScriptEngineQtScript::evaluate() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] "
797 "sourceCode:" << sourceCode << " fileName:" << fileName;797 "sourceCode:" << sourceCode << " fileName:" << fileName;
798#endif798#endif
799 BLOCKING_INVOKE_METHOD(this, "evaluate",799 BLOCKING_INVOKE_METHOD(this, "evaluate",
800 Q_RETURN_ARG(ScriptValuePointer, result),800 Q_RETURN_ARG(ScriptValue, result),
801 Q_ARG(const ScriptProgramPointer&, program));801 Q_ARG(const ScriptProgramPointer&, program));
802 return result;802 return result;
803 }803 }
@@ -822,7 +822,7 @@ Q_INVOKABLE ScriptValuePointer ScriptEngineQtScript::evaluate(const ScriptProgra · 18 unmodified lines
822 QScriptValue result = QScriptEngine::evaluate(qProgram);822 QScriptValue result = QScriptEngine::evaluate(qProgram);
823 maybeEmitUncaughtException("evaluate");823 maybeEmitUncaughtException("evaluate");
824 824
825 return ScriptValuePointer(new ScriptValueQtWrapper(this, std::move(result)));825 return ScriptValue(new ScriptValueQtWrapper(this, std::move(result)));
826}826}
827 827
828 828
@@ -849,21 +849,21 @@ void ScriptEngineQtScript::print(const QString& message) { · 20 unmodified lines
849////////////////////////////////////////////////////////////////////////////////////////////////////////////////////849////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
850// ScriptEngine implementation850// ScriptEngine implementation
851 851
852ScriptValuePointer ScriptEngineQtScript::globalObject() const {852ScriptValue ScriptEngineQtScript::globalObject() const {
853 QScriptValue global = QScriptEngine::globalObject(); // can't cache the value as it may change853 QScriptValue global = QScriptEngine::globalObject(); // can't cache the value as it may change
854 return ScriptValuePointer(new ScriptValueQtWrapper(const_cast < ScriptEngineQtScript*>(this), std::move(global)));854 return ScriptValue(new ScriptValueQtWrapper(const_cast < ScriptEngineQtScript*>(this), std::move(global)));
855}855}
856 856
857ScriptManager* ScriptEngineQtScript::manager() const {857ScriptManager* ScriptEngineQtScript::manager() const {
858 return _manager;858 return _manager;
859}859}
860 860
861ScriptValuePointer ScriptEngineQtScript::newArray(uint length) {861ScriptValue ScriptEngineQtScript::newArray(uint length) {
862 QScriptValue result = QScriptEngine::newArray(length);862 QScriptValue result = QScriptEngine::newArray(length);
863 return ScriptValuePointer(new ScriptValueQtWrapper(this, std::move(result)));863 return ScriptValue(new ScriptValueQtWrapper(this, std::move(result)));
864}864}
865 865
866ScriptValuePointer ScriptEngineQtScript::newArrayBuffer(const QByteArray& message) {866ScriptValue ScriptEngineQtScript::newArrayBuffer(const QByteArray& message) {
867 QScriptValue data = QScriptEngine::newVariant(QVariant::fromValue(message));867 QScriptValue data = QScriptEngine::newVariant(QVariant::fromValue(message));
868 QScriptValue ctor = QScriptEngine::globalObject().property("ArrayBuffer");868 QScriptValue ctor = QScriptEngine::globalObject().property("ArrayBuffer");
869 auto array = qscriptvalue_cast<ArrayBufferClass*>(ctor.data());869 auto array = qscriptvalue_cast<ArrayBufferClass*>(ctor.data());
@@ -871,12 +871,12 @@ ScriptValuePointer ScriptEngineQtScript::newArrayBuffer(const QByteArray& messag · 1 unmodified line
871 return undefinedValue();871 return undefinedValue();
872 }872 }
873 QScriptValue result = QScriptEngine::newObject(array, data);873 QScriptValue result = QScriptEngine::newObject(array, data);
874 return ScriptValuePointer(new ScriptValueQtWrapper(this, std::move(result)));874 return ScriptValue(new ScriptValueQtWrapper(this, std::move(result)));
875}875}
876 876
877ScriptValuePointer ScriptEngineQtScript::newObject() {877ScriptValue ScriptEngineQtScript::newObject() {
878 QScriptValue result = QScriptEngine::newObject();878 QScriptValue result = QScriptEngine::newObject();
879 return ScriptValuePointer(new ScriptValueQtWrapper(this, std::move(result)));879 return ScriptValue(new ScriptValueQtWrapper(this, std::move(result)));
880}880}
881 881
882ScriptProgramPointer ScriptEngineQtScript::newProgram(const QString& sourceCode, const QString& fileName) {882ScriptProgramPointer ScriptEngineQtScript::newProgram(const QString& sourceCode, const QString& fileName) {
@@ -884,66 +884,66 @@ ScriptProgramPointer ScriptEngineQtScript::newProgram(const QString& sourceCode, · 1 unmodified line
884 return ScriptProgramPointer(new ScriptProgramQtWrapper(this, result));884 return ScriptProgramPointer(new ScriptProgramQtWrapper(this, result));
885}885}
886 886
887ScriptValuePointer ScriptEngineQtScript::newQObject(QObject* object,887ScriptValue ScriptEngineQtScript::newQObject(QObject* object,
888 ScriptEngine::ValueOwnership ownership,888 ScriptEngine::ValueOwnership ownership,
889 const ScriptEngine::QObjectWrapOptions& options) {889 const ScriptEngine::QObjectWrapOptions& options) {
890 QScriptValue result = QScriptEngine::newQObject(object, static_cast<QScriptEngine::ValueOwnership>(ownership),890 QScriptValue result = QScriptEngine::newQObject(object, static_cast<QScriptEngine::ValueOwnership>(ownership),
891 (QScriptEngine::QObjectWrapOptions)((int)options | DEFAULT_QOBJECT_WRAP_OPTIONS));891 (QScriptEngine::QObjectWrapOptions)((int)options | DEFAULT_QOBJECT_WRAP_OPTIONS));
892 return ScriptValuePointer(new ScriptValueQtWrapper(this, std::move(result)));892 return ScriptValue(new ScriptValueQtWrapper(this, std::move(result)));
893}893}
894 894
895ScriptValuePointer ScriptEngineQtScript::newValue(bool value) {895ScriptValue ScriptEngineQtScript::newValue(bool value) {
896 QScriptValue result(this, value);896 QScriptValue result(this, value);
897 return ScriptValuePointer(new ScriptValueQtWrapper(this, std::move(result)));897 return ScriptValue(new ScriptValueQtWrapper(this, std::move(result)));
898}898}
899 899
900ScriptValuePointer ScriptEngineQtScript::newValue(int value) {900ScriptValue ScriptEngineQtScript::newValue(int value) {
901 QScriptValue result(this, value);901 QScriptValue result(this, value);
902 return ScriptValuePointer(new ScriptValueQtWrapper(this, std::move(result)));902 return ScriptValue(new ScriptValueQtWrapper(this, std::move(result)));
903}903}
904 904
905ScriptValuePointer ScriptEngineQtScript::newValue(uint value) {905ScriptValue ScriptEngineQtScript::newValue(uint value) {
906 QScriptValue result(this, value);906 QScriptValue result(this, value);
907 return ScriptValuePointer(new ScriptValueQtWrapper(this, std::move(result)));907 return ScriptValue(new ScriptValueQtWrapper(this, std::move(result)));
908}908}
909 909
910ScriptValuePointer ScriptEngineQtScript::newValue(double value) {910ScriptValue ScriptEngineQtScript::newValue(double value) {
911 QScriptValue result(this, value);911 QScriptValue result(this, value);
912 return ScriptValuePointer(new ScriptValueQtWrapper(this, std::move(result)));912 return ScriptValue(new ScriptValueQtWrapper(this, std::move(result)));
913}913}
914 914
915ScriptValuePointer ScriptEngineQtScript::newValue(const QString& value) {915ScriptValue ScriptEngineQtScript::newValue(const QString& value) {
916 QScriptValue result(this, value);916 QScriptValue result(this, value);
917 return ScriptValuePointer(new ScriptValueQtWrapper(this, std::move(result)));917 return ScriptValue(new ScriptValueQtWrapper(this, std::move(result)));
918}918}
919 919
920ScriptValuePointer ScriptEngineQtScript::newValue(const QLatin1String& value) {920ScriptValue ScriptEngineQtScript::newValue(const QLatin1String& value) {
921 QScriptValue result(this, value);921 QScriptValue result(this, value);
922 return ScriptValuePointer(new ScriptValueQtWrapper(this, std::move(result)));922 return ScriptValue(new ScriptValueQtWrapper(this, std::move(result)));
923}923}
924 924
925ScriptValuePointer ScriptEngineQtScript::newValue(const char* value) {925ScriptValue ScriptEngineQtScript::newValue(const char* value) {
926 QScriptValue result(this, value);926 QScriptValue result(this, value);
927 return ScriptValuePointer(new ScriptValueQtWrapper(this, std::move(result)));927 return ScriptValue(new ScriptValueQtWrapper(this, std::move(result)));
928}928}
929 929
930ScriptValuePointer ScriptEngineQtScript::newVariant(const QVariant& value) {930ScriptValue ScriptEngineQtScript::newVariant(const QVariant& value) {
931 QScriptValue result = QScriptEngine::newVariant(value);931 QScriptValue result = QScriptEngine::newVariant(value);
932 return ScriptValuePointer(new ScriptValueQtWrapper(this, std::move(result)));932 return ScriptValue(new ScriptValueQtWrapper(this, std::move(result)));
933}933}
934 934
935ScriptValuePointer ScriptEngineQtScript::nullValue() {935ScriptValue ScriptEngineQtScript::nullValue() {
936 return _nullValue;936 return _nullValue;
937}937}
938 938
939void ScriptEngineQtScript::setDefaultPrototype(int metaTypeId, const ScriptValuePointer& prototype){939void ScriptEngineQtScript::setDefaultPrototype(int metaTypeId, const ScriptValue& prototype){
940 ScriptValueQtWrapper* unwrappedPrototype = ScriptValueQtWrapper::unwrap(prototype);940 ScriptValueQtWrapper* unwrappedPrototype = ScriptValueQtWrapper::unwrap(prototype);
941 if (unwrappedPrototype) {941 if (unwrappedPrototype) {
942 QScriptEngine::setDefaultPrototype(metaTypeId, unwrappedPrototype->toQtValue());942 QScriptEngine::setDefaultPrototype(metaTypeId, unwrappedPrototype->toQtValue());
943 }943 }
944}944}
945 945
946ScriptValuePointer ScriptEngineQtScript::undefinedValue() {946ScriptValue ScriptEngineQtScript::undefinedValue() {
947 return _undefinedValue;947 return _undefinedValue;
948}948}
949 949
@@ -974,14 +974,14 @@ bool ScriptEngineQtScript::isEvaluating() const { · 24 unmodified lines
974 return QScriptEngine::isEvaluating();974 return QScriptEngine::isEvaluating();
975}975}
976 976
977ScriptValuePointer ScriptEngineQtScript::newFunction(ScriptEngine::FunctionSignature fun, int length) {977ScriptValue ScriptEngineQtScript::newFunction(ScriptEngine::FunctionSignature fun, int length) {
978 auto innerFunc = [](QScriptContext* _context, QScriptEngine* _engine) -> QScriptValue {978 auto innerFunc = [](QScriptContext* _context, QScriptEngine* _engine) -> QScriptValue {
979 auto callee = _context->callee();979 auto callee = _context->callee();
980 QVariant funAddr = callee.property("_func").toVariant();980 QVariant funAddr = callee.property("_func").toVariant();
981 ScriptEngine::FunctionSignature fun = reinterpret_cast<ScriptEngine::FunctionSignature>(funAddr.toULongLong());981 ScriptEngine::FunctionSignature fun = reinterpret_cast<ScriptEngine::FunctionSignature>(funAddr.toULongLong());
982 ScriptEngineQtScript* engine = static_cast<ScriptEngineQtScript*>(_engine);982 ScriptEngineQtScript* engine = static_cast<ScriptEngineQtScript*>(_engine);
983 ScriptContextQtWrapper context(engine, _context);983 ScriptContextQtWrapper context(engine, _context);
984 ScriptValuePointer result = fun(&context, engine);984 ScriptValue result = fun(&context, engine);
985 ScriptValueQtWrapper* unwrapped = ScriptValueQtWrapper::unwrap(result);985 ScriptValueQtWrapper* unwrapped = ScriptValueQtWrapper::unwrap(result);
986 return unwrapped ? unwrapped->toQtValue() : QScriptValue();986 return unwrapped ? unwrapped->toQtValue() : QScriptValue();
987 };987 };
@@ -989,7 +989,7 @@ ScriptValuePointer ScriptEngineQtScript::newFunction(ScriptEngine::FunctionSigna · 1 unmodified line
989 QScriptValue result = QScriptEngine::newFunction(innerFunc, length);989 QScriptValue result = QScriptEngine::newFunction(innerFunc, length);
990 auto funAddr = QScriptEngine::newVariant(QVariant(reinterpret_cast<qulonglong>(fun)));990 auto funAddr = QScriptEngine::newVariant(QVariant(reinterpret_cast<qulonglong>(fun)));
991 result.setProperty("_func", funAddr, QScriptValue::PropertyFlags(QScriptValue::ReadOnly + QScriptValue::Undeletable + QScriptValue::SkipInEnumeration));991 result.setProperty("_func", funAddr, QScriptValue::PropertyFlags(QScriptValue::ReadOnly + QScriptValue::Undeletable + QScriptValue::SkipInEnumeration));
992 return ScriptValuePointer(new ScriptValueQtWrapper(this, std::move(result)));992 return ScriptValue(new ScriptValueQtWrapper(this, std::move(result)));
993}993}
994 994
995void ScriptEngineQtScript::setObjectName(const QString& name) {995void ScriptEngineQtScript::setObjectName(const QString& name) {
@@ -1012,9 +1012,9 @@ void ScriptEngineQtScript::setThread(QThread* thread) { · 16 unmodified lines
1012 moveToThread(thread);1012 moveToThread(thread);
1013}1013}
1014 1014
1015ScriptValuePointer ScriptEngineQtScript::uncaughtException() const {1015ScriptValue ScriptEngineQtScript::uncaughtException() const {
1016 QScriptValue result = QScriptEngine::uncaughtException();1016 QScriptValue result = QScriptEngine::uncaughtException();
1017 return ScriptValuePointer(new ScriptValueQtWrapper(const_cast<ScriptEngineQtScript*>(this), std::move(result)));1017 return ScriptValue(new ScriptValueQtWrapper(const_cast<ScriptEngineQtScript*>(this), std::move(result)));
1018}1018}
1019 1019
1020QStringList ScriptEngineQtScript::uncaughtExceptionBacktrace() const {1020QStringList ScriptEngineQtScript::uncaughtExceptionBacktrace() const {
@@ -1025,18 +1025,18 @@ int ScriptEngineQtScript::uncaughtExceptionLineNumber() const { · 4 unmodified lines
1025 return QScriptEngine::uncaughtExceptionLineNumber();1025 return QScriptEngine::uncaughtExceptionLineNumber();
1026}1026}
1027 1027
1028bool ScriptEngineQtScript::raiseException(const ScriptValuePointer& exception) {1028bool ScriptEngineQtScript::raiseException(const ScriptValue& exception) {
1029 ScriptValueQtWrapper* unwrapped = ScriptValueQtWrapper::unwrap(exception);1029 ScriptValueQtWrapper* unwrapped = ScriptValueQtWrapper::unwrap(exception);
1030 QScriptValue qException = unwrapped ? unwrapped->toQtValue() : QScriptEngine::newVariant(exception->toVariant());1030 QScriptValue qException = unwrapped ? unwrapped->toQtValue() : QScriptEngine::newVariant(exception.toVariant());
1031 return raiseException(qException);1031 return raiseException(qException);
1032}1032}
1033 1033
1034ScriptValuePointer ScriptEngineQtScript::create(int type, const void* ptr) {1034ScriptValue ScriptEngineQtScript::create(int type, const void* ptr) {
1035 QScriptValue result = qScriptValueFromValue_helper(this, type, ptr);1035 QScriptValue result = qScriptValueFromValue_helper(this, type, ptr);
1036 return ScriptValuePointer(new ScriptValueQtWrapper(const_cast<ScriptEngineQtScript*>(this), std::move(result)));1036 return ScriptValue(new ScriptValueQtWrapper(const_cast<ScriptEngineQtScript*>(this), std::move(result)));
1037}1037}
1038 1038
1039bool ScriptEngineQtScript::convert(const ScriptValuePointer& value, int type, void* ptr) {1039bool ScriptEngineQtScript::convert(const ScriptValue& value, int type, void* ptr) {
1040 ScriptValueQtWrapper* unwrapped = ScriptValueQtWrapper::unwrap(value);1040 ScriptValueQtWrapper* unwrapped = ScriptValueQtWrapper::unwrap(value);
1041 if (unwrapped == nullptr) {1041 if (unwrapped == nullptr) {
1042 return false;1042 return false;
@@ -1052,13 +1052,13 @@ public: · 9 unmodified lines
1052 1052
1053 static QScriptValue internalMarshalFunc(QScriptEngine* engine, const void* src) {1053 static QScriptValue internalMarshalFunc(QScriptEngine* engine, const void* src) {
1054 ScriptEngineQtScript* unwrappedEngine = static_cast<ScriptEngineQtScript*>(engine);1054 ScriptEngineQtScript* unwrappedEngine = static_cast<ScriptEngineQtScript*>(engine);
1055 ScriptValuePointer dest = marshalFunc(unwrappedEngine, src);1055 ScriptValue dest = marshalFunc(unwrappedEngine, src);
1056 return ScriptValueQtWrapper::fullUnwrap(unwrappedEngine, dest);1056 return ScriptValueQtWrapper::fullUnwrap(unwrappedEngine, dest);
1057 }1057 }
1058 1058
1059 static void internalDemarshalFunc(const QScriptValue& src, void* dest) {1059 static void internalDemarshalFunc(const QScriptValue& src, void* dest) {
1060 ScriptEngineQtScript* unwrappedEngine = static_cast<ScriptEngineQtScript*>(src.engine());1060 ScriptEngineQtScript* unwrappedEngine = static_cast<ScriptEngineQtScript*>(src.engine());
1061 ScriptValuePointer wrappedSrc(new ScriptValueQtWrapper(unwrappedEngine, src));1061 ScriptValue wrappedSrc(new ScriptValueQtWrapper(unwrappedEngine, src));
1062 demarshalFunc(wrappedSrc, dest);1062 demarshalFunc(wrappedSrc, dest);
1063 }1063 }
1064};1064};
@@ -1094,7 +1094,7 @@ ScriptEngine::DemarshalFunction CustomTypeInstance<i>::demarshalFunc; · 29 unmodified lines
1094void ScriptEngineQtScript::registerCustomType(int type,1094void ScriptEngineQtScript::registerCustomType(int type,
1095 ScriptEngine::MarshalFunction marshalFunc,1095 ScriptEngine::MarshalFunction marshalFunc,
1096 ScriptEngine::DemarshalFunction demarshalFunc,1096 ScriptEngine::DemarshalFunction demarshalFunc,
1097 const ScriptValuePointer& prototype)1097 const ScriptValue& prototype)
1098{1098{
1099 QScriptValue unwrapped = ScriptValueQtWrapper::fullUnwrap(this, prototype);1099 QScriptValue unwrapped = ScriptValueQtWrapper::fullUnwrap(this, prototype);
1100 QScriptEngine::MarshalFunction internalMarshalFunc;1100 QScriptEngine::MarshalFunction internalMarshalFunc;

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