52 static void read(File file,
char *buffer, uint32_t offset, uint32_t end,
60 ChunkedFileReader(uint32_t end,
std::function<
void()> onCompleted, File file)
72 const uint32_t nextChunkBegin =
std::min(chunkBegin + result.byteLength(), end);
448 Q_ASSERT_X(!!callbacks.catchFunc || !!callbacks.finallyFunc || !!callbacks.thenFunc,
449 "Promise::adoptPromise",
"must provide at least one callback function");
451 QWasmSuspendResumeControl *suspendResume = QWasmSuspendResumeControl::get();
452 Q_ASSERT(suspendResume);
456 auto registerCallback = [suspendResume](std::function<
void(emscripten::val)> cb) -> std::optional<uint32_t>{
459 return std::optional<uint32_t>{suspendResume->registerEventHandler(std::move(cb))};
467 std::optional<uint32_t> thenIndex = registerCallback(std::move(callbacks.thenFunc));
468 std::optional<uint32_t> catchIndex = registerCallback(std::move(callbacks.catchFunc));
469 std::shared_ptr<uint32_t> finallyIndex = std::make_shared<uint32_t>();;
470 auto finallyFunc = callbacks.finallyFunc;
473 auto finally = [suspendResume, thenIndex, catchIndex, finallyIndex, finallyFunc](emscripten::val){
477 suspendResume->removeEventHandler(*thenIndex);
479 suspendResume->removeEventHandler(*catchIndex);
486 suspendResume->removeEventHandler(*finallyIndex);
489 *finallyIndex = suspendResume->registerEventHandler(std::move(finally));
494 promise.call<emscripten::val>(
"then", suspendResume->jsEventHandlerAt(*thenIndex));
497 promise = promise.call<emscripten::val>(
"catch",
498 suspendResume->jsEventHandlerAt(*catchIndex));
500 promise = promise.call<emscripten::val>(
"finally",
501 suspendResume->jsEventHandlerAt(*finallyIndex));
625 uint64_t begin = QIODevice::pos();
626 uint64_t end = std::min<uint64_t>(begin + maxSize, size());
627 uint64_t size = end - begin;
629 m_array.subarray(begin, end).set(Uint8Array(data, size));