WebAssembly.hx 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (C)2005-2019 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. package js.lib;
  23. import js.lib.webassembly.Module;
  24. import js.lib.webassembly.Instance;
  25. import js.html.Response;
  26. /**
  27. The WebAssembly JavaScript object acts as the namespace for all WebAssembly-related functionality.
  28. Documentation [WebAssembly](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly) by [Mozilla Contributors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly$history), licensed under [CC-BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/).
  29. **/
  30. @:native("WebAssembly")
  31. extern class WebAssembly {
  32. /**
  33. The `WebAssembly.instantiate()` function allows you to compile and instantiate WebAssembly code.
  34. This function has two overloads:
  35. - The primary overload takes the WebAssembly binary code, in the form of a typed array or ArrayBuffer,
  36. and performs both compilation and instantiation in one step. The returned Promise resolves to both
  37. a compiled WebAssembly.Module and its first WebAssembly.Instance.
  38. - The secondary overload takes an already-compiled WebAssembly.Module and returns a Promise that resolves
  39. to an Instance of that Module. This overload is useful if the Module has already been compiled.
  40. **/
  41. @:overload(function(module:Module, importObject:{}):Promise<Instance> {})
  42. @:pure static function instantiate(bufferSource:BufferSource, importObject:{}):Promise<WebAssemblyInstantiatedSource>;
  43. /**
  44. The `WebAssembly.instantiateStreaming()` function compiles and instantiates a WebAssembly module
  45. directly from a streamed underlying source. This is the most efficient, optimized way to load wasm code.
  46. **/
  47. @:pure static function instantiateStreaming(source:Response, importObject:{}):Promise<WebAssemblyInstantiatedSource>;
  48. /**
  49. The `WebAssembly.compile()` function compiles a WebAssembly `Module` from WebAssembly binary code.
  50. This function is useful if it is necessary to a compile a module before it can be instantiated
  51. (otherwise, the `WebAssembly.instantiate()` function should be used).
  52. **/
  53. @:pure static function compile(bufferSource:BufferSource):Promise<Module>;
  54. /**
  55. The `WebAssembly.compileStreaming()` function compiles a WebAssembly `Module` directly from a streamed
  56. underlying source. This function is useful if it is necessary to a compile a module before it can
  57. be instantiated (otherwise, the `WebAssembly.instantiateStreaming()` function should be used).
  58. **/
  59. @:pure static function compileStreaming(source:Response):Promise<Module>;
  60. /**
  61. The `WebAssembly.validate()` function validates a given typed array of WebAssembly binary code,
  62. returning whether the bytes form a valid wasm module (`true`) or not (`false`).
  63. **/
  64. @:pure static function validate(bufferSource:BufferSource):Bool;
  65. }
  66. typedef WebAssemblyInstantiatedSource = {
  67. final module:Module;
  68. final instance:Instance;
  69. }