6#include <private/qqmlengine_p.h>
7#include <private/qqmlexpression_p.h>
8#include <private/qjsvalue_p.h>
10#include <QtCore/qcoreevent.h>
11#include <QtCore/qcoreapplication.h>
12#include <QtCore/qdebug.h>
13#include <QtQml/qjsengine.h>
14#include <QtCore/qmutex.h>
15#include <QtCore/qwaitcondition.h>
16#include <QtCore/qfile.h>
17#include <QtCore/qdatetime.h>
18#include <QtQml/qqmlinfo.h>
19#include <QtQml/qqmlfile.h>
20#if QT_CONFIG(qml_network)
21#include <QtNetwork/qnetworkaccessmanager.h>
25#include <private/qv4serialize_p.h>
27#include <private/qv4value_p.h>
28#include <private/qv4functionobject_p.h>
29#include <private/qv4script_p.h>
30#include <private/qv4scopedvalue_p.h>
31#include <private/qv4jscall_p.h>
100#if QT_CONFIG(qml_network)
141 void processLoad(
int,
const QUrl &);
146: qmlengine(
engine), m_nextId(0)
171 processMessage(workerEvent->
workerId(), workerEvent->
data());
175 processLoad(workerEvent->
workerId(), workerEvent->
url());
206 script->
owner = owner;
212void QQuickWorkerScriptEnginePrivate::processMessage(
int id,
const QByteArray &
data)
231 *jsCallData.thisObject =
engine->global();
232 jsCallData.args[0] =
value;
233 onmessage->call(jsCallData);
234 if (scope.hasException()) {
237 reportScriptException(script,
error);
241void QQuickWorkerScriptEnginePrivate::processLoad(
int id,
const QUrl &
url)
257 if (module.compiled) {
258 if (module.compiled->instantiate(
engine))
260 }
else if (module.native) {
272 if (!
error.isEmpty())
277 if (!
engine->hasException)
282 reportScriptException(script,
engine->catchExceptionAsQmlError());
285void QQuickWorkerScriptEnginePrivate::reportScriptException(
WorkerScript *script,
380 engine->initQmlGlobalObject();
389 api->put(sendMessageName, sendMessage);
393#if QT_CONFIG(qml_network)
396 if (workerScript->scriptLocalNAM)
397 return workerScript->scriptLocalNAM.get();
398 if (
auto *namFactory = workerScript->
p->
qmlengine->networkAccessManagerFactory())
399 workerScript->scriptLocalNAM.reset(namFactory->create(workerScript->
p));
402 return workerScript->scriptLocalNAM.get();
426 workerScriptExtension(
engine)->owner =
nullptr;
560 return m_engine !=
nullptr;
586 qWarning(
"QQuickWorkerScript: Attempt to send message before WorkerScript establishment");
600 m_componentComplete =
false;
605 if (m_engine)
return m_engine;
606 if (m_componentComplete) {
610 qWarning(
"QQuickWorkerScript: engine() called without qmlEngine() set");
615 if (enginePrivate->workerScriptEngine ==
nullptr)
617 m_engine = qobject_cast<QQuickWorkerScriptEngine *>(enginePrivate->workerScriptEngine);
633 m_componentComplete =
true;
665#include <qquickworkerscript.moc>
667#include "moc_qquickworkerscript_p.cpp"
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Processes some pending events for the calling thread according to the specified flags.
static void postEvent(QObject *receiver, QEvent *event, int priority=Qt::NormalEventPriority)
Type
This enum type defines the valid event types in Qt.
iterator begin()
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in the hash.
iterator find(const Key &key)
Returns an iterator pointing to the item with the key in the hash.
iterator erase(const_iterator it)
iterator end() noexcept
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last ...
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Removes all items from the hash and frees up all memory used by it.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
QV4::ExecutionEngine * handle() const
void throwError(const QString &message)
Throws a run-time error (exception) with the given message.
QJSValue globalObject() const
Returns this engine's Global Object.
QJSValue newObject()
Creates a JavaScript object of class Object.
QJSValue evaluate(const QString &program, const QString &fileName=QString(), int lineNumber=1, QStringList *exceptionStackTrace=nullptr)
Evaluates program, using lineNumber as the base line number, and returns the result of the evaluation...
static QJSValue fromReturnedValue(QV4::ReturnedValue d)
qsizetype length() const noexcept
void unlock() noexcept
Unlocks the mutex.
void lock() noexcept
Locks the mutex.
The QNetworkAccessManager class allows the application to send network requests and receive replies.
void moveToThread(QThread *thread)
Changes the thread affinity for this object and its children.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
virtual bool event(QEvent *event)
This virtual function receives events to an object and should return true if the event e was recogniz...
The QQmlContext class defines a context within a QML engine.
void warning(const QQmlError &)
static QQmlEnginePrivate * get(QQmlEngine *e)
The QQmlEngine class provides an environment for instantiating QML components.
The QQmlError class encapsulates a QML error.
static QString urlToLocalFileOrQrc(const QString &)
If url is a local file returns a path suitable for passing to QFile.
bool event(QEvent *) override
This virtual function receives events to an object and should return true if the event e was recogniz...
QQuickWorkerScriptEnginePrivate(QQmlEngine *eng)
static QV4::ReturnedValue method_sendMessage(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
QV4::ExecutionEngine * workerEngine(int id)
QHash< int, QBiPointer< QV4::ExecutionEngine, QQuickWorkerScript > > workers
void executeUrl(int, const QUrl &)
~QQuickWorkerScriptEngine()
QQuickWorkerScriptEngine(QQmlEngine *parent=nullptr)
void sendMessage(int, const QByteArray &)
void removeWorkerScript(int)
int registerWorkerScript(QQuickWorkerScript *)
void message(const QJSValue &messageObject)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void sendMessage(QQmlV4Function *)
\qmlmethod WorkerScript::sendMessage(jsobject message)
bool event(QEvent *) override
\qmlsignal WorkerScript::message(jsobject msg)
QQuickWorkerScript(QObject *parent=nullptr)
\qmltype WorkerScript \instantiates QQuickWorkerScript\inqmlmodule QtQml.WorkerScript
void classBegin() override
Invoked after class creation, but before any properties have been set.
void setSource(const QUrl &)
\macro QT_RESTRICTED_CAST_FROM_ASCII
void start(Priority=InheritPriority)
static void yieldCurrentThread()
bool isRelative() const
Returns true if the URL is relative; otherwise returns false.
bool isValid() const
Returns true if the URL is non-empty and valid; otherwise returns false.
static ReturnedValue deserialize(const QByteArray &, ExecutionEngine *)
static QByteArray serialize(const Value &, ExecutionEngine *)
bool wait(QMutex *, QDeadlineTimer=QDeadlineTimer(QDeadlineTimer::Forever))
virtual ~WorkerDataEvent()
WorkerDataEvent(int workerId, const QByteArray &data)
WorkerErrorEvent(const QQmlError &error)
WorkerLoadEvent(int workerId, const QUrl &url)
WorkerRemoveEvent(int workerId)
QSet< QString >::iterator it
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLsizei GLsizei GLchar * source
QQmlEngine * qmlEngine(const QObject *obj)
QQmlContext * qmlContext(const QObject *obj)
#define QStringLiteral(str)
#define V4_DEFINE_EXTENSION(dataclass, datafunction)
QUrl url("example.com")
[constructor-url-reference]
static constexpr ReturnedValue undefined()
static Heap::FunctionObject * createBuiltinFunction(ExecutionEngine *engine, StringOrSymbol *nameOrSymbol, VTable::Call code, int argumentCount)
static Script * createFromFileOrCache(ExecutionEngine *engine, QmlContext *qmlContext, const QString &fileName, const QUrl &originalUrl, QString *error)
static constexpr Value undefinedValue()
QQuickWorkerScriptEnginePrivate * p
QQuickWorkerScript * owner
WorkerScript(QV4::ExecutionEngine *)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent