From 5811c2c7d50c10327565a23e19bf39c105593710 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 24 Jun 2022 16:32:44 -0700 Subject: [JS API] Avoid trying to read the offset if segment is passive (#4750) This avoids hitting an assertion. --- src/js/binaryen.js-post.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js index b6ea7dee1..f2e5c464e 100644 --- a/src/js/binaryen.js-post.js +++ b/src/js/binaryen.js-post.js @@ -2519,8 +2519,13 @@ function wrapModule(module, self = {}) { return Module['_BinaryenGetNumMemorySegments'](module); }; self['getMemorySegmentInfoByIndex'] = function(id) { + const passive = Boolean(Module['_BinaryenGetMemorySegmentPassive'](module, id)); + let offset = null; + if (!passive) { + offset = Module['_BinaryenGetMemorySegmentByteOffset'](module, id); + } return { - 'offset': Module['_BinaryenGetMemorySegmentByteOffset'](module, id), + 'offset': offset, 'data': (function(){ const size = Module['_BinaryenGetMemorySegmentByteLength'](module, id); const ptr = _malloc(size); @@ -2530,7 +2535,7 @@ function wrapModule(module, self = {}) { _free(ptr); return res.buffer; })(), - 'passive': Boolean(Module['_BinaryenGetMemorySegmentPassive'](module, id)) + 'passive': passive }; }; self['setStart'] = function(start) { -- cgit v1.2.3