summaryrefslogtreecommitdiff
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
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.
-rw-r--r--src/js/binaryen.js-post.js5
-rw-r--r--test/binaryen.js/kitchen-sink.js2
-rw-r--r--test/binaryen.js/kitchen-sink.js.txt2
3 files changed, 6 insertions, 3 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)
diff --git a/test/binaryen.js/kitchen-sink.js b/test/binaryen.js/kitchen-sink.js
index e8cf3e0f5..a44cd9116 100644
--- a/test/binaryen.js/kitchen-sink.js
+++ b/test/binaryen.js/kitchen-sink.js
@@ -970,7 +970,7 @@ function test_expression_info() {
console.log("getExpressionInfo(memory.grow)=" + JSON.stringify(Binaryen.getExpressionInfo(module.memory.grow(1))));
// Issue #2396
- console.log("getExpressionInfo(memory.grow)=" + JSON.stringify(Binaryen.getExpressionInfo(module.switch([ "label" ], "label", 0))));
+ console.log("getExpressionInfo(switch)=" + JSON.stringify(Binaryen.getExpressionInfo(module.switch([ "label" ], "label", 0))));
module.dispose();
}
diff --git a/test/binaryen.js/kitchen-sink.js.txt b/test/binaryen.js/kitchen-sink.js.txt
index bb6c92f72..b08dbfdfb 100644
--- a/test/binaryen.js/kitchen-sink.js.txt
+++ b/test/binaryen.js/kitchen-sink.js.txt
@@ -10230,4 +10230,4 @@ sizeof Literal: 24
)
getExpressionInfo(memory.grow)={"id":20,"type":2,"op":1,"nameOperand":"","operands":[1]}
-getExpressionInfo(memory.grow)={"id":5,"type":1,"names":[""],"defaultName":"label","condition":0,"value":0}
+getExpressionInfo(switch)={"id":5,"type":1,"names":["label"],"defaultName":"label","condition":0,"value":0}