wasm: Make sure all qstdweb classes have val()

These are sometimes needed for passing objects on
to native API.

Change-Id: I89a1a95e6d51932ae3b49eec072261bcb5dbb463
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
Morten Johan Sørvig 2021-11-10 12:30:58 +01:00
parent 8bca441b6f
commit 2d85244802
2 changed files with 30 additions and 2 deletions

View File

@ -68,6 +68,11 @@ uint32_t ArrayBuffer::byteLength() const
return m_arrayBuffer["byteLength"].as<uint32_t>();
}
emscripten::val ArrayBuffer::val()
{
return m_arrayBuffer;
}
Blob::Blob(const emscripten::val &blob)
:m_blob(blob)
{
@ -85,7 +90,7 @@ Blob Blob::copyFrom(const char *buffer, uint32_t size)
Uint8Array contentCopy = Uint8Array::copyFrom(buffer, size);
emscripten::val contentArray = emscripten::val::array();
contentArray.call<void>("push", contentCopy.m_uint8Array);
contentArray.call<void>("push", contentCopy.val());
emscripten::val type = emscripten::val::object();
type.set("type","application/octet-stream");
return Blob(emscripten::val::global("Blob").new_(contentArray, type));
@ -172,6 +177,11 @@ std::string File::type() const
return m_file["type"].as<std::string>();
}
emscripten::val File::val()
{
return m_file;
}
FileList::FileList(const emscripten::val &fileList)
:m_fileList(fileList)
{
@ -218,6 +228,11 @@ void FileReader::onAbort(const std::function<void(emscripten::val)> &onAbort)
m_onAbort.reset(new EventCallback(m_fileReader, "abort", onAbort));
}
emscripten::val FileReader::val()
{
return m_fileReader;
}
Uint8Array Uint8Array::heap()
{
return Uint8Array(heap_());
@ -293,6 +308,11 @@ Uint8Array Uint8Array::copyFrom(const char *buffer, uint32_t size)
return contentCopy;
}
emscripten::val Uint8Array::val()
{
return m_uint8Array;
}
emscripten::val Uint8Array::heap_()
{
return emscripten::val::module_property("HEAPU8");

View File

@ -62,6 +62,8 @@ namespace qstdweb {
// DOM API in C++, implemented using emscripten val.h and bind.h.
// This is private API and can be extended and changed as needed.
// The API mirrors that of the native API, with some extensions
// to ease usage from C++ code.
class ArrayBuffer;
class Blob;
@ -76,6 +78,7 @@ namespace qstdweb {
explicit ArrayBuffer(uint32_t size);
explicit ArrayBuffer(const emscripten::val &arrayBuffer);
uint32_t byteLength() const;
emscripten::val val();
private:
friend class Uint8Array;
@ -106,6 +109,7 @@ namespace qstdweb {
std::string type() const;
void stream(uint32_t offset, uint32_t length, char *buffer, const std::function<void ()> &completed) const;
void stream(char *buffer, const std::function<void ()> &completed) const;
emscripten::val val();
private:
emscripten::val m_file = emscripten::val::undefined();
@ -119,6 +123,7 @@ namespace qstdweb {
int length() const;
File item(int index) const;
File operator[](int index) const;
emscripten::val val();
private:
emscripten::val m_fileList = emscripten::val::undefined();
@ -132,6 +137,7 @@ namespace qstdweb {
void onLoad(const std::function<void(emscripten::val)> &onLoad);
void onError(const std::function<void(emscripten::val)> &onError);
void onAbort(const std::function<void(emscripten::val)> &onAbort);
emscripten::val val();
private:
emscripten::val m_fileReader = emscripten::val::global("FileReader").new_();
@ -156,8 +162,9 @@ namespace qstdweb {
void copyTo(char *destination) const;
static void copy(char *destination, const Uint8Array &source);
static Uint8Array copyFrom(const char *buffer, uint32_t size);
emscripten::val val();
private:
friend class Blob;
static emscripten::val heap_();
static emscripten::val constructor_();
emscripten::val m_uint8Array = emscripten::val::undefined();
@ -173,6 +180,7 @@ namespace qstdweb {
EventCallback(emscripten::val element, const std::string &name,
const std::function<void(emscripten::val)> &fn);
static void activate(emscripten::val event);
private:
static std::string contextPropertyName(const std::string &eventName);
emscripten::val m_element = emscripten::val::undefined();