Symbol.hx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. @:native("Symbol")
  24. extern class Symbol {
  25. /**
  26. To create a new primitive symbol, use `new Symbol()` with an optional string as its `description`.
  27. NOTE: Unlike in plain JavaScript, `new Symbol()` syntax is used in Haxe. This generates a `Symbol(...)`
  28. expression as required by the JavaScript specification.
  29. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol
  30. **/
  31. @:pure @:selfCall function new(?description:String);
  32. /**
  33. The Symbol.for(key) method searches for existing symbols in a
  34. runtime-wide symbol registry with the given key and returns it if found.
  35. Otherwise a new symbol gets created in the global symbol registry with
  36. this key.
  37. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for
  38. **/
  39. @:native("for") static function for_(key:String):Symbol;
  40. /**
  41. The Symbol.keyFor(sym) method retrieves a shared symbol key from the
  42. global symbol registry for the given symbol.
  43. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/keyFor
  44. **/
  45. @:pure static function keyFor(sym:Symbol):Null<String>;
  46. /**
  47. Returns a string containing the description of the Symbol.
  48. **/
  49. @:pure function toString():String;
  50. /**
  51. A method returning the default iterator for an object.
  52. **/
  53. static var iterator(default, null):Symbol;
  54. /**
  55. A method that returns the default AsyncIterator for an object.
  56. **/
  57. static var asyncIterator(default, null):Symbol;
  58. /**
  59. A method that matches against a string, also used to determine if an
  60. object may be used as a regular expression. Used by
  61. String.prototype.match().
  62. **/
  63. static var match(default, null):Symbol;
  64. /**
  65. A method that replaces matched substrings of a string. Used by
  66. String.prototype.replace().
  67. **/
  68. static var replace(default, null):Symbol;
  69. /**
  70. A method that returns the index within a string that matches the regular
  71. expression. Used by String.prototype.search().
  72. **/
  73. static var search(default, null):Symbol;
  74. /**
  75. A method that splits a string at the indices that match a regular
  76. expression. Used by String.prototype.split().
  77. **/
  78. static var split(default, null):Symbol;
  79. /**
  80. A method determining if a constructor object recognizes an object as its
  81. instance. Used by instanceof.
  82. **/
  83. static var hasInstance(default, null):Symbol;
  84. /**
  85. A Boolean value indicating if an object should be flattened to its array
  86. elements. Used by Array.prototype.concat().
  87. **/
  88. static var isConcatSpreadable(default, null):Symbol;
  89. /**
  90. An object value of whose own and inherited property names are excluded
  91. from the with environment bindings of the associated object.
  92. **/
  93. static var unscopables(default, null):Symbol;
  94. /**
  95. A constructor function that is used to create derived objects.
  96. **/
  97. static var species(default, null):Symbol;
  98. /**
  99. A method converting an object to a primitive value.
  100. **/
  101. static var toPrimitive(default, null):Symbol;
  102. /**
  103. A string value used for the default description of an object. Used by
  104. Object.prototype.toString().
  105. **/
  106. static var toStringTag(default, null):Symbol;
  107. /**
  108. Retrieve symbol from a given `object`.
  109. NOTE: This is a Haxe-specific method that generates an `object[symbol]` expression.
  110. **/
  111. inline function ofObject<T>(object:{}):Null<T>
  112. return (cast object)[cast this];
  113. }