diff options
author | Blaine Bublitz <blaine.bublitz@gmail.com> | 2022-06-24 16:32:44 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-24 16:32:44 -0700 |
commit | 5811c2c7d50c10327565a23e19bf39c105593710 (patch) | |
tree | b07af8e460790171ab6be501c8da79f70c46693e /src | |
parent | efea05006b4179db159d8850c33a4b54cf04d317 (diff) | |
download | binaryen-5811c2c7d50c10327565a23e19bf39c105593710.tar.gz binaryen-5811c2c7d50c10327565a23e19bf39c105593710.tar.bz2 binaryen-5811c2c7d50c10327565a23e19bf39c105593710.zip |
[JS API] Avoid trying to read the offset if segment is passive (#4750)
This avoids hitting an assertion.
Diffstat (limited to 'src')
-rw-r--r-- | src/js/binaryen.js-post.js | 9 |
1 files changed, 7 insertions, 2 deletions
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) { |