summaryrefslogtreecommitdiff
path: root/src/websockets/qwebsocket_wasm_p.cpp
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-09-17 03:00:26 +0200
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-09-17 03:00:26 +0200
commite7e257274fada00a99f17357c5e0fff9a3603d49 (patch)
tree49035dc32c3d10ba6fb31f1657d629c4e07546e6 /src/websockets/qwebsocket_wasm_p.cpp
parent87a5151adfc9947f2ab2e560fea7da0088eb59c6 (diff)
parent24a9e0f961d84af037999771948d3d3d9c683a6c (diff)
downloadqtwebsockets-e7e257274fada00a99f17357c5e0fff9a3603d49.tar.gz
Merge remote-tracking branch 'origin/5.13' into 5.14
Change-Id: I4052a4c238a0c59b1a0fc01ad3fd6ee6b714595b
Diffstat (limited to 'src/websockets/qwebsocket_wasm_p.cpp')
-rw-r--r--src/websockets/qwebsocket_wasm_p.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/websockets/qwebsocket_wasm_p.cpp b/src/websockets/qwebsocket_wasm_p.cpp
index 199fe44..85fcab2 100644
--- a/src/websockets/qwebsocket_wasm_p.cpp
+++ b/src/websockets/qwebsocket_wasm_p.cpp
@@ -137,11 +137,19 @@ qint64 QWebSocketPrivate::sendTextMessage(const QString &message)
qint64 QWebSocketPrivate::sendBinaryMessage(const QByteArray &data)
{
- socketContext.call<void>("send",
- val(typed_memory_view(data.size(),
- reinterpret_cast<const unsigned char *>
- (data.constData()))));
+ // Make a copy of the payload data; we don't know how long WebSocket.send() will
+ // retain the memory view, while the QByteArray passed to this function may be
+ // destroyed as soon as this function returns. In addition, the WebSocket.send()
+ // API does not accept data from a view backet by a SharedArrayBuffer, which will
+ // be the case for the view produced by typed_memory_view() when threads are enabled.
+ val Uint8Array = val::global("Uint8Array");
+ val dataCopy = Uint8Array.new_(data.size());
+ val dataView = val(typed_memory_view(data.size(),
+ reinterpret_cast<const unsigned char *>
+ (data.constData())));
+ dataCopy.call<void>("set", dataView);
+ socketContext.call<void>("send", dataCopy);
return data.length();
}