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);
446 Q_ASSERT_X(!!callbacks.catchFunc || !!callbacks.finallyFunc || !!callbacks.thenFunc,
447 "Promise::adoptPromise",
"must provide at least one callback function");
449 QWasmSuspendResumeControl *suspendResume = QWasmSuspendResumeControl::get();
450 Q_ASSERT(suspendResume);
454 auto registerCallback = [suspendResume](std::function<
void(emscripten::val)> cb) -> std::optional<uint32_t>{
457 return std::optional<uint32_t>{suspendResume->registerEventHandler(std::move(cb))};
465 std::optional<uint32_t> thenIndex = registerCallback(std::move(callbacks.thenFunc));
466 std::optional<uint32_t> catchIndex = registerCallback(std::move(callbacks.catchFunc));
467 std::shared_ptr<uint32_t> finallyIndex = std::make_shared<uint32_t>();;
468 auto finallyFunc = callbacks.finallyFunc;
471 auto finally = [suspendResume, thenIndex, catchIndex, finallyIndex, finallyFunc](emscripten::val){
475 suspendResume->removeEventHandler(*thenIndex);
477 suspendResume->removeEventHandler(*catchIndex);
484 suspendResume->removeEventHandler(*finallyIndex);
487 *finallyIndex = suspendResume->registerEventHandler(std::move(finally));
492 promise.call<emscripten::val>(
"then", suspendResume->jsEventHandlerAt(*thenIndex));
495 promise = promise.call<emscripten::val>(
"catch",
496 suspendResume->jsEventHandlerAt(*catchIndex));
498 promise = promise.call<emscripten::val>(
"finally",
499 suspendResume->jsEventHandlerAt(*finallyIndex));
501 return *finallyIndex;
633 uint64_t begin = QIODevice::pos();
634 uint64_t end = std::min<uint64_t>(begin + maxSize, size());
635 uint64_t size = end - begin;
637 m_array.subarray(begin, end).set(Uint8Array(data, size));