TypeError: WebAssembly Instantiation: Imports argument must be present and must be an object

假装没事ソ 提交于 2021-02-10 09:51:10

问题


I'm following this hello world tutorial: https://steemit.com/eos/@skenan/eos-development-for-beginners-webassembly

and I get this error: TypeError: WebAssembly Instantiation: Imports argument must be present and must be an object

Any idea what might be causing it?

Thanks!


回答1:


The reason you got this error is probably because: when you initiate a webassembly instance, you need to specify the import object as well. Just like:

WebAssembly.instantiate(module, imports);

Well, here I'm just giving a simple example to demonstrate the steps:

    imports.env = imports.env || {}

    Object.assign(imports.env, {
      tableBase: module.tableBase,
      table: new WebAssembly.Table({
        initial: 4,
        element: 'anyfunc',
      }),
      print:function(msg){
        console.log(msg);
      }
    });
    return new WebAssembly.Instance(module, imports)



回答2:


I am not able to reproduce this error by following the tutorial. It works fine for me. Did you make any changes to the C source or JavaScript loading code?

The error you are seeing occurs if you instantiate a module without giving it all its required imports. But a module without imports like the one in the tutorial can be instantiated without an imports object. Documentation is here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate#Parameters.



来源:https://stackoverflow.com/questions/49635240/typeerror-webassembly-instantiation-imports-argument-must-be-present-and-must

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!