2
0

Table.hx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.webassembly;
  23. import haxe.Constraints.Function;
  24. /**
  25. A Table object of the given size and element type.
  26. This is a JavaScript wrapper object — an array-like structure representing a WebAssembly Table,
  27. which stores function references. A table created by JavaScript or in WebAssembly code will be
  28. accessible and mutable from both JavaScript and WebAssembly.
  29. Documentation [Table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table) by [Mozilla Contributors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table$history), licensed under [CC-BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/).
  30. **/
  31. @:native("WebAssembly.Table")
  32. extern class Table {
  33. /**
  34. Returns the length of the table, i.e. the number of elements.
  35. **/
  36. var length:Int;
  37. @:pure function new(tableDescriptor:TableDescriptor):Void;
  38. /**
  39. Accessor function — gets the element stored at a given index.
  40. **/
  41. @:pure function get(index:Int):Function;
  42. /**
  43. Increases the size of the Table instance by a specified number of elements.
  44. **/
  45. function grow(number:Int):Int;
  46. /**
  47. Sets an element stored at a given index to a given value.
  48. **/
  49. function set(index:Int, value:Function):Void;
  50. }
  51. typedef TableDescriptor = {
  52. /**
  53. A string representing the type of value to be stored in the table.
  54. At the moment this can only have a value of `Anyfunc` (functions).
  55. **/
  56. var element:TableKind;
  57. /**
  58. The initial number of elements of the WebAssembly Table.
  59. **/
  60. var initial:Int;
  61. /**
  62. The maximum number of elements the WebAssembly Table is allowed to grow to.
  63. **/
  64. var ?maximum:Int;
  65. }
  66. enum abstract TableKind(String) {
  67. var Anyfunc = "anyfunc";
  68. }