summaryrefslogtreecommitdiff
path: root/src/js/binaryen.js-post.js
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2019-12-23 15:37:23 -0800
committerAlon Zakai <azakai@google.com>2019-12-23 15:37:23 -0800
commitaab879d12576177ae4ff3114adcf8f768544b704 (patch)
tree2150f23d166465e4c9a2bd9b729f8c3d59b29a32 /src/js/binaryen.js-post.js
parent604cda7fffadee6cc414121396f48e0192084785 (diff)
downloadbinaryen-aab879d12576177ae4ff3114adcf8f768544b704.tar.gz
binaryen-aab879d12576177ae4ff3114adcf8f768544b704.tar.bz2
binaryen-aab879d12576177ae4ff3114adcf8f768544b704.zip
Fix for binaryen.js getExpressionInfo on switch names (#2553)
Switch label names for br_table instructions were corrupted in the binaryen.js API layer, with each label cropped down to the number of characters that it is an index into the list. This was due to passing UTF8ToString as a callback method to Array.prototype.map, which passes the index as second parameter. The second parameter of UTF8ToString is the max number of bytes to copy, so the initial label came out as '', then 'l', then 'la', 'lab', etc. Corrected an existing test case that had the wrong output in it.
Diffstat (limited to 'src/js/binaryen.js-post.js')
-rw-r--r--src/js/binaryen.js-post.js5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/js/binaryen.js-post.js b/src/js/binaryen.js-post.js
index 96562e6e0..8cddc61c7 100644
--- a/src/js/binaryen.js-post.js
+++ b/src/js/binaryen.js-post.js
@@ -2376,7 +2376,10 @@ Module['getExpressionInfo'] = function(expr) {
return {
'id': id,
'type': type,
- 'names': getAllNested(expr, Module['_BinaryenSwitchGetNumNames'], Module['_BinaryenSwitchGetName']).map(UTF8ToString),
+ 'names': getAllNested(expr, Module['_BinaryenSwitchGetNumNames'], Module['_BinaryenSwitchGetName']).map(function (p) {
+ // Do not pass the index as the second parameter to UTF8ToString as that will cut off the string.
+ return UTF8ToString(p);
+ }),
'defaultName': UTF8ToString(Module['_BinaryenSwitchGetDefaultName'](expr)),
'condition': Module['_BinaryenSwitchGetCondition'](expr),
'value': Module['_BinaryenSwitchGetValue'](expr)