wasm: fix crash in case network js event becomes null or undefined
also fix data progress Task-number: QTBUG-75489 Change-Id: I5222fda64d258a6ae78ba0ca20194b81c289c27e Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
parent
83dccf00cc
commit
762d4afdc1
@ -59,6 +59,9 @@ using namespace emscripten;
|
|||||||
|
|
||||||
static void q_requestErrorCallback(val event)
|
static void q_requestErrorCallback(val event)
|
||||||
{
|
{
|
||||||
|
if (event.isNull() || event.isUndefined())
|
||||||
|
return;
|
||||||
|
|
||||||
val xhr = event["target"];
|
val xhr = event["target"];
|
||||||
|
|
||||||
quintptr func = xhr["data-handler"].as<quintptr>();
|
quintptr func = xhr["data-handler"].as<quintptr>();
|
||||||
@ -77,19 +80,24 @@ static void q_requestErrorCallback(val event)
|
|||||||
|
|
||||||
static void q_progressCallback(val event)
|
static void q_progressCallback(val event)
|
||||||
{
|
{
|
||||||
|
if (event.isNull() || event.isUndefined())
|
||||||
|
return;
|
||||||
|
|
||||||
val xhr = event["target"];
|
val xhr = event["target"];
|
||||||
|
|
||||||
QNetworkReplyWasmImplPrivate *reply =
|
QNetworkReplyWasmImplPrivate *reply =
|
||||||
reinterpret_cast<QNetworkReplyWasmImplPrivate*>(xhr["data-handler"].as<quintptr>());
|
reinterpret_cast<QNetworkReplyWasmImplPrivate*>(xhr["data-handler"].as<quintptr>());
|
||||||
Q_ASSERT(reply);
|
Q_ASSERT(reply);
|
||||||
|
|
||||||
if (xhr["lengthComputable"].as<bool>() && xhr["status"].as<int>() < 400)
|
if (xhr["status"].as<int>() < 400)
|
||||||
reply->emitDataReadProgress(xhr["loaded"].as<qint64>(), xhr["total"].as<qint64>());
|
reply->emitDataReadProgress(event["loaded"].as<int>(), event["total"].as<int>());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void q_loadCallback(val event)
|
static void q_loadCallback(val event)
|
||||||
{
|
{
|
||||||
|
if (event.isNull() || event.isUndefined())
|
||||||
|
return;
|
||||||
|
|
||||||
val xhr = event["target"];
|
val xhr = event["target"];
|
||||||
|
|
||||||
QNetworkReplyWasmImplPrivate *reply =
|
QNetworkReplyWasmImplPrivate *reply =
|
||||||
@ -121,6 +129,7 @@ static void q_loadCallback(val event)
|
|||||||
reader.set("data-handler", xhr["data-handler"]);
|
reader.set("data-handler", xhr["data-handler"]);
|
||||||
|
|
||||||
reader.call<void>("readAsArrayBuffer", blob);
|
reader.call<void>("readAsArrayBuffer", blob);
|
||||||
|
val::global("Module").delete_(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -136,6 +145,9 @@ static void q_loadCallback(val event)
|
|||||||
|
|
||||||
static void q_responseHeadersCallback(val event)
|
static void q_responseHeadersCallback(val event)
|
||||||
{
|
{
|
||||||
|
if (event.isNull() || event.isUndefined())
|
||||||
|
return;
|
||||||
|
|
||||||
val xhr = event["target"];
|
val xhr = event["target"];
|
||||||
|
|
||||||
if (xhr["readyState"].as<int>() == 2) { // HEADERS_RECEIVED
|
if (xhr["readyState"].as<int>() == 2) { // HEADERS_RECEIVED
|
||||||
@ -152,12 +164,18 @@ static void q_responseHeadersCallback(val event)
|
|||||||
|
|
||||||
static void q_readBinary(val event)
|
static void q_readBinary(val event)
|
||||||
{
|
{
|
||||||
|
if (event.isNull() || event.isUndefined())
|
||||||
|
return;
|
||||||
|
|
||||||
val fileReader = event["target"];
|
val fileReader = event["target"];
|
||||||
|
|
||||||
QNetworkReplyWasmImplPrivate *reply =
|
QNetworkReplyWasmImplPrivate *reply =
|
||||||
reinterpret_cast<QNetworkReplyWasmImplPrivate*>(fileReader["data-handler"].as<quintptr>());
|
reinterpret_cast<QNetworkReplyWasmImplPrivate*>(fileReader["data-handler"].as<quintptr>());
|
||||||
Q_ASSERT(reply);
|
Q_ASSERT(reply);
|
||||||
|
|
||||||
|
if (reply->state == QNetworkReplyPrivate::Finished || reply->state == QNetworkReplyPrivate::Aborted)
|
||||||
|
return;
|
||||||
|
|
||||||
// Set up source typed array
|
// Set up source typed array
|
||||||
val result = fileReader["result"]; // ArrayBuffer
|
val result = fileReader["result"]; // ArrayBuffer
|
||||||
val Uint8Array = val::global("Uint8Array");
|
val Uint8Array = val::global("Uint8Array");
|
||||||
@ -171,6 +189,10 @@ static void q_readBinary(val event)
|
|||||||
reinterpret_cast<quintptr>(buffer.data()), size);
|
reinterpret_cast<quintptr>(buffer.data()), size);
|
||||||
destinationTypedArray.call<void>("set", sourceTypedArray);
|
destinationTypedArray.call<void>("set", sourceTypedArray);
|
||||||
reply->dataReceived(buffer, buffer.size());
|
reply->dataReceived(buffer, buffer.size());
|
||||||
|
|
||||||
|
event.delete_(fileReader);
|
||||||
|
Uint8Array.delete_(sourceTypedArray);
|
||||||
|
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,14 +216,21 @@ QNetworkReplyWasmImplPrivate::QNetworkReplyWasmImplPrivate()
|
|||||||
|
|
||||||
QNetworkReplyWasmImplPrivate::~QNetworkReplyWasmImplPrivate()
|
QNetworkReplyWasmImplPrivate::~QNetworkReplyWasmImplPrivate()
|
||||||
{
|
{
|
||||||
}
|
m_xhr.set("onerror", val::null());
|
||||||
|
m_xhr.set("onload", val::null());
|
||||||
QNetworkReplyWasmImpl::~QNetworkReplyWasmImpl()
|
m_xhr.set("onprogress", val::null());
|
||||||
{
|
m_xhr.set("onreadystatechange", val::null());
|
||||||
|
m_xhr.set("data-handler", val::null());
|
||||||
}
|
}
|
||||||
|
|
||||||
QNetworkReplyWasmImpl::QNetworkReplyWasmImpl(QObject *parent)
|
QNetworkReplyWasmImpl::QNetworkReplyWasmImpl(QObject *parent)
|
||||||
: QNetworkReply(*new QNetworkReplyWasmImplPrivate(), parent)
|
: QNetworkReply(*new QNetworkReplyWasmImplPrivate(), parent)
|
||||||
|
{
|
||||||
|
Q_D( QNetworkReplyWasmImpl);
|
||||||
|
d->state = QNetworkReplyPrivate::Idle;
|
||||||
|
}
|
||||||
|
|
||||||
|
QNetworkReplyWasmImpl::~QNetworkReplyWasmImpl()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,19 +255,23 @@ QByteArray QNetworkReplyWasmImpl::methodName() const
|
|||||||
|
|
||||||
void QNetworkReplyWasmImpl::close()
|
void QNetworkReplyWasmImpl::close()
|
||||||
{
|
{
|
||||||
|
QNetworkReply::close();
|
||||||
setFinished(true);
|
setFinished(true);
|
||||||
emit finished();
|
emit finished();
|
||||||
|
|
||||||
QNetworkReply::close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QNetworkReplyWasmImpl::abort()
|
void QNetworkReplyWasmImpl::abort()
|
||||||
{
|
{
|
||||||
Q_D(const QNetworkReplyWasmImpl);
|
Q_D( QNetworkReplyWasmImpl);
|
||||||
setError( QNetworkReply::OperationCanceledError, QStringLiteral("Operation canceled"));
|
if (d->state == QNetworkReplyPrivate::Finished || d->state == QNetworkReplyPrivate::Aborted)
|
||||||
|
return;
|
||||||
|
|
||||||
|
setError(QNetworkReply::OperationCanceledError, QStringLiteral("Operation canceled"));
|
||||||
|
|
||||||
d->doAbort();
|
d->doAbort();
|
||||||
|
|
||||||
close();
|
close();
|
||||||
|
d->state = QNetworkReplyPrivate::Aborted;
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 QNetworkReplyWasmImpl::bytesAvailable() const
|
qint64 QNetworkReplyWasmImpl::bytesAvailable() const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user