polyinline.js 973 B

12345678910111213141516171819202122232425262728
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation and contributors. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. const buf = WebAssembly.wabt.convertWast2Wasm(`
  6. (module
  7. (func (export "min") (param f64 f64) (result f64)
  8. (f64.min (get_local 0) (get_local 1))
  9. )
  10. (func (export "max") (param f64 f64) (result f64)
  11. (f64.max (get_local 0) (get_local 1))
  12. )
  13. )`);
  14. const view = new Uint8Array(buf);
  15. view[buf.byteLength - 1] = 6;
  16. var mod = new WebAssembly.Module(buf);
  17. var {min, max} = new WebAssembly.Instance(mod).exports;
  18. function foo(fn) {
  19. fn();
  20. }
  21. try {foo(min);} catch (e) {}
  22. try {foo(max);} catch (e) {}
  23. try {foo(min);} catch (e) {}
  24. print("Pass");