Bug 1346010: Properly render the name of func imports when there's at least one non-func import; r?yury draft
authorBenjamin Bouvier <benj@benj.me>
Fri, 10 Mar 2017 12:21:39 +0100
changeset 496657 ba90218e61955b8b2ff11d4394c3a50becb4dc56
parent 496656 67bd3d804a0ac29efc8c4fbbe43c540ffcfe3665
child 548658 c31872edfb319224f7f56f71ee0b746159e76515
push id48647
push userbbouvier@mozilla.com
push dateFri, 10 Mar 2017 11:22:08 +0000
reviewersyury
bugs1346010
milestone55.0a1
Bug 1346010: Properly render the name of func imports when there's at least one non-func import; r?yury MozReview-Commit-ID: JqMfC1KrgTY
js/src/jit-test/tests/wasm/full-cycle.js
js/src/wasm/WasmBinaryToAST.cpp
--- a/js/src/jit-test/tests/wasm/full-cycle.js
+++ b/js/src/jit-test/tests/wasm/full-cycle.js
@@ -14,16 +14,23 @@ wasmFullPass(`(module
         i32.const 0
         call 3
         i32.const 42
         i32.add
     )
     (func) (func) (func)
 (export "run" 0))`, 43);
 
+wasmFullPass(`
+(module
+  (import "env" "a" (global $a i32))
+  (import "env" "b" (func $b (param i32) (result i32)))
+  (func (export "run") (param $0 i32) (result i32) get_local 0 call $b)
+)`, 43, { env: { a: 1337, b: x => x+1 } }, 42);
+
 // Global section.
 wasmFullPass(`(module
  (import $imported "globals" "x" (global i32))
  (global $mut_local (mut i32) (i32.const 0))
  (global $imm_local i32 (i32.const 37))
  (global $imm_local_2 i32 (get_global 0))
  (func $get (result i32)
   i32.const 13
--- a/js/src/wasm/WasmBinaryToAST.cpp
+++ b/js/src/wasm/WasmBinaryToAST.cpp
@@ -297,18 +297,17 @@ AstDecodeCall(AstDecodeContext& c)
     if (!c.iter().readCall(&funcIndex, &unusedArgs))
         return false;
 
     if (c.iter().currentBlockHasPolymorphicBase())
         return true;
 
     AstRef funcRef;
     if (funcIndex < c.module().numFuncImports()) {
-        AstImport* import = c.module().imports()[funcIndex];
-        funcRef = AstRef(import->name());
+        funcRef = AstRef(c.module().funcImportNames()[funcIndex]);
     } else {
         if (!GenerateRef(c, AstName(u"func"), funcIndex, &funcRef))
             return false;
     }
 
     const SigWithId* sig = c.env().funcSigs[funcIndex];
 
     AstExprVector args(c.lifo);
@@ -1540,16 +1539,17 @@ AstCreateImports(AstDecodeContext& c)
     }
 
     for (size_t importIndex = 0; importIndex < c.env().imports.length(); importIndex++) {
         const Import& import = c.env().imports[importIndex];
 
         AstName moduleName;
         if (!ToAstName(c, import.module.get(), &moduleName))
             return false;
+
         AstName fieldName;
         if (!ToAstName(c, import.field.get(), &fieldName))
             return false;
 
         AstImport* ast = nullptr;
         switch (import.kind) {
           case DefinitionKind::Function: {
             AstName importName;