From f5841ad54bb2217491666c8f400e20d152a21149 Mon Sep 17 00:00:00 2001 From: Yahweasel Date: Fri, 27 Sep 2024 23:33:31 -0400 Subject: [PATCH] Once and for all fixing this errno-transfer issue --- extern-post.js | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/extern-post.js b/extern-post.js index 828bdec5..669cd4d5 100644 --- a/extern-post.js +++ b/extern-post.js @@ -48,41 +48,42 @@ if (/* We're in a worker */ var fun = e.data[1]; var args = e.data.slice(2); var ret = void 0; - var transfer = []; var succ = true; + + function reply() { + var transfer = []; + if (ret && ret.libavjsTransfer) + transfer = ret.libavjsTransfer + try { + postMessage([id, fun, succ, ret], transfer); + } catch (ex) { + try { + ret = JSON.parse(JSON.stringify( + ret, function(k, v) { return v; } + )); + postMessage([id, fun, succ, ret], transfer); + } catch (ex) { + postMessage([id, fun, succ, "" + ret]); + } + } + } + try { ret = libav[fun].apply(libav, args); } catch (ex) { succ = false; ret = ex; } - if (succ && typeof ret === "object" && ret !== null && ret.then) { + if (succ && ret && ret.then) { // Let the promise resolve ret.then(function(res) { ret = res; }).catch(function(ex) { succ = false; ret = ex; - }).then(function() { - if (typeof ret === "object" && ret && ret.libavjsTransfer) - transfer = ret.libavjsTransfer; - try { - postMessage([id, fun, succ, ret], transfer); - } catch (ex) { - postMessage([id, fun, succ, "" + ret]); - } - }); + }).then(reply); - } else { - if (typeof ret === "object" && ret && ret.libavjsTransfer) - transfer = ret.libavjsTransfer; - try { - postMessage([id, fun, succ, ret], transfer); - } catch (ex) { - postMessage([id, fun, succ, "" + ret]); - } - - } + } else reply(); }; libav.onwrite = function(name, pos, buf) {