WebAssembly.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const { TextEncoder } = require("util");
  2. const data =
  3. "\u0000asm\u0001\u0000\u0000\u0000\u0001\b\u0002`\u0001\u007f\u0000`\u0000" +
  4. "\u0000\u0002\u0019\u0001\u0007imports\rimported_func\u0000\u0000\u0003" +
  5. "\u0002\u0001\u0001\u0007\u0011\u0001\rexported_func\u0000\u0001\n\b\u0001" +
  6. "\u0006\u0000A*\u0010\u0000\u000b";
  7. const encoder = new TextEncoder();
  8. const wasmArray = encoder.encode(data);
  9. function getWasmArray() {
  10. return wasmArray;
  11. }
  12. function getTableObject() {
  13. return { element: "anyfunc", initial: 1 }
  14. }
  15. function getInvalidTableObject() {
  16. return { element: "anyfunc", initial: 1, maximum: 0 }
  17. }
  18. function getImports() {
  19. return {
  20. imports: {
  21. imported_func: function () {
  22. return 1;
  23. }
  24. }
  25. };
  26. }
  27. // Polyfill `WebAssembly.instantiateStreaming` for node.
  28. if (!global.WebAssembly.instantiateStreaming) {
  29. global.WebAssembly.instantiateStreaming =
  30. (response, imports) => response.then(buf => WebAssembly.instantiate(buf, imports));
  31. }
  32. module.exports = {
  33. getInvalidTableObject,
  34. getTableObject,
  35. getWasmArray,
  36. getImports,
  37. };