Forward.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #pragma once
  27. #define JS_DECLARE_NATIVE_FUNCTION(name) \
  28. static JS::Value name(JS::VM&, JS::GlobalObject&)
  29. #define JS_DECLARE_NATIVE_GETTER(name) \
  30. static JS::Value name(JS::VM&, JS::GlobalObject&)
  31. #define JS_DECLARE_NATIVE_SETTER(name) \
  32. static void name(JS::VM&, JS::GlobalObject&, JS::Value)
  33. #define JS_DEFINE_NATIVE_FUNCTION(name) \
  34. JS::Value name([[maybe_unused]] JS::VM& vm, [[maybe_unused]] JS::GlobalObject& global_object)
  35. #define JS_DEFINE_NATIVE_GETTER(name) \
  36. JS::Value name([[maybe_unused]] JS::VM& vm, [[maybe_unused]] JS::GlobalObject& global_object)
  37. #define JS_DEFINE_NATIVE_SETTER(name) \
  38. void name([[maybe_unused]] JS::VM& vm, [[maybe_unused]] JS::GlobalObject& global_object, [[maybe_unused]] JS::Value value)
  39. // NOTE: Proxy is not included here as it doesn't have a prototype - m_proxy_constructor is initialized separately.
  40. #define JS_ENUMERATE_NATIVE_OBJECTS_EXCLUDING_TEMPLATES \
  41. __JS_ENUMERATE(Array, array, ArrayPrototype, ArrayConstructor, void) \
  42. __JS_ENUMERATE(ArrayBuffer, array_buffer, ArrayBufferPrototype, ArrayBufferConstructor, void) \
  43. __JS_ENUMERATE(BigIntObject, bigint, BigIntPrototype, BigIntConstructor, void) \
  44. __JS_ENUMERATE(BooleanObject, boolean, BooleanPrototype, BooleanConstructor, void) \
  45. __JS_ENUMERATE(Date, date, DatePrototype, DateConstructor, void) \
  46. __JS_ENUMERATE(Error, error, ErrorPrototype, ErrorConstructor, void) \
  47. __JS_ENUMERATE(Function, function, FunctionPrototype, FunctionConstructor, void) \
  48. __JS_ENUMERATE(NumberObject, number, NumberPrototype, NumberConstructor, void) \
  49. __JS_ENUMERATE(Object, object, ObjectPrototype, ObjectConstructor, void) \
  50. __JS_ENUMERATE(RegExpObject, regexp, RegExpPrototype, RegExpConstructor, void) \
  51. __JS_ENUMERATE(StringObject, string, StringPrototype, StringConstructor, void) \
  52. __JS_ENUMERATE(SymbolObject, symbol, SymbolPrototype, SymbolConstructor, void)
  53. #define JS_ENUMERATE_NATIVE_OBJECTS \
  54. JS_ENUMERATE_NATIVE_OBJECTS_EXCLUDING_TEMPLATES \
  55. __JS_ENUMERATE(TypedArray, typed_array, TypedArrayPrototype, TypedArrayConstructor, void)
  56. #define JS_ENUMERATE_ERROR_SUBCLASSES \
  57. __JS_ENUMERATE(EvalError, eval_error, EvalErrorPrototype, EvalErrorConstructor, void) \
  58. __JS_ENUMERATE(InternalError, internal_error, InternalErrorPrototype, InternalErrorConstructor, void) \
  59. __JS_ENUMERATE(InvalidCharacterError, invalid_character_error, InvalidCharacterErrorPrototype, InvalidCharacterErrorConstructor, void) \
  60. __JS_ENUMERATE(RangeError, range_error, RangeErrorPrototype, RangeErrorConstructor, void) \
  61. __JS_ENUMERATE(ReferenceError, reference_error, ReferenceErrorPrototype, ReferenceErrorConstructor, void) \
  62. __JS_ENUMERATE(SyntaxError, syntax_error, SyntaxErrorPrototype, SyntaxErrorConstructor, void) \
  63. __JS_ENUMERATE(TypeError, type_error, TypeErrorPrototype, TypeErrorConstructor, void) \
  64. __JS_ENUMERATE(URIError, uri_error, URIErrorPrototype, URIErrorConstructor, void)
  65. #define JS_ENUMERATE_TYPED_ARRAYS \
  66. __JS_ENUMERATE(Uint8Array, uint8_array, Uint8ArrayPrototype, Uint8ArrayConstructor, u8) \
  67. __JS_ENUMERATE(Uint16Array, uint16_array, Uint16ArrayPrototype, Uint16ArrayConstructor, u16) \
  68. __JS_ENUMERATE(Uint32Array, uint32_array, Uint32ArrayPrototype, Uint32ArrayConstructor, u32) \
  69. __JS_ENUMERATE(Int8Array, int8_array, Int8ArrayPrototype, Int8ArrayConstructor, i8) \
  70. __JS_ENUMERATE(Int16Array, int16_array, Int16ArrayPrototype, Int16ArrayConstructor, i16) \
  71. __JS_ENUMERATE(Int32Array, int32_array, Int32ArrayPrototype, Int32ArrayConstructor, i32) \
  72. __JS_ENUMERATE(Float32Array, float32_array, Float32ArrayPrototype, Float32ArrayConstructor, float) \
  73. __JS_ENUMERATE(Float64Array, float64_array, Float64ArrayPrototype, Float64ArrayConstructor, double)
  74. #define JS_ENUMERATE_ITERATOR_PROTOTYPES \
  75. __JS_ENUMERATE(Iterator, iterator) \
  76. __JS_ENUMERATE(ArrayIterator, array_iterator) \
  77. __JS_ENUMERATE(StringIterator, string_iterator)
  78. #define JS_ENUMERATE_BUILTIN_TYPES \
  79. JS_ENUMERATE_NATIVE_OBJECTS \
  80. JS_ENUMERATE_ERROR_SUBCLASSES \
  81. JS_ENUMERATE_TYPED_ARRAYS
  82. #define JS_ENUMERATE_WELL_KNOWN_SYMBOLS \
  83. __JS_ENUMERATE(iterator, iterator) \
  84. __JS_ENUMERATE(asyncIterator, async_iterator) \
  85. __JS_ENUMERATE(match, match) \
  86. __JS_ENUMERATE(matchAll, match_all) \
  87. __JS_ENUMERATE(replace, replace) \
  88. __JS_ENUMERATE(search, search) \
  89. __JS_ENUMERATE(split, split) \
  90. __JS_ENUMERATE(hasInstance, has_instance) \
  91. __JS_ENUMERATE(isConcatSpreadable, is_concat_spreadable) \
  92. __JS_ENUMERATE(unscopables, unscopables) \
  93. __JS_ENUMERATE(species, species) \
  94. __JS_ENUMERATE(toPrimitive, to_primitive) \
  95. __JS_ENUMERATE(toStringTag, to_string_tag)
  96. #define JS_ENUMERATE_REGEXP_FLAGS \
  97. __JS_ENUMERATE(global, global, g, Global) \
  98. __JS_ENUMERATE(ignoreCase, ignore_case, i, Insensitive) \
  99. __JS_ENUMERATE(multiline, multiline, m, Multiline) \
  100. __JS_ENUMERATE(dotAll, dot_all, s, SingleLine) \
  101. __JS_ENUMERATE(unicode, unicode, u, Unicode) \
  102. __JS_ENUMERATE(sticky, sticky, y, Sticky)
  103. namespace JS {
  104. class ASTNode;
  105. class Allocator;
  106. class BigInt;
  107. class BoundFunction;
  108. class Cell;
  109. class Console;
  110. class DeferGC;
  111. class Error;
  112. class Exception;
  113. class Expression;
  114. class Accessor;
  115. class GlobalObject;
  116. class HandleImpl;
  117. class Heap;
  118. class HeapBlock;
  119. class Interpreter;
  120. class LexicalEnvironment;
  121. class MarkedValueList;
  122. class NativeFunction;
  123. class NativeProperty;
  124. class PrimitiveString;
  125. class PropertyName;
  126. class Reference;
  127. class ScopeNode;
  128. class ScopeObject;
  129. class Shape;
  130. class Statement;
  131. class Symbol;
  132. class Token;
  133. class Uint8ClampedArray;
  134. class VM;
  135. class Value;
  136. enum class DeclarationKind;
  137. // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype
  138. class ProxyObject;
  139. class ProxyConstructor;
  140. class TypedArrayConstructor;
  141. class TypedArrayPrototype;
  142. #define __JS_ENUMERATE(ClassName, snake_name, ConstructorName, PrototypeName, ArrayType) \
  143. class ClassName; \
  144. class ConstructorName; \
  145. class PrototypeName;
  146. JS_ENUMERATE_NATIVE_OBJECTS_EXCLUDING_TEMPLATES
  147. JS_ENUMERATE_ERROR_SUBCLASSES
  148. JS_ENUMERATE_TYPED_ARRAYS
  149. #undef __JS_ENUMERATE
  150. template<class T>
  151. class Handle;
  152. }