Forward.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Types.h>
  8. #define JS_DECLARE_NATIVE_FUNCTION(name) \
  9. static JS::ThrowCompletionOr<JS::Value> name(JS::VM&, JS::GlobalObject&)
  10. #define JS_DEFINE_NATIVE_FUNCTION(name) \
  11. JS::ThrowCompletionOr<JS::Value> name([[maybe_unused]] JS::VM& vm, [[maybe_unused]] JS::GlobalObject& global_object)
  12. // NOTE: Proxy is not included here as it doesn't have a prototype - m_proxy_constructor is initialized separately.
  13. #define JS_ENUMERATE_NATIVE_OBJECTS_EXCLUDING_TEMPLATES \
  14. __JS_ENUMERATE(AggregateError, aggregate_error, AggregateErrorPrototype, AggregateErrorConstructor, void) \
  15. __JS_ENUMERATE(Array, array, ArrayPrototype, ArrayConstructor, void) \
  16. __JS_ENUMERATE(ArrayBuffer, array_buffer, ArrayBufferPrototype, ArrayBufferConstructor, void) \
  17. __JS_ENUMERATE(AsyncFunction, async_function, AsyncFunctionPrototype, AsyncFunctionConstructor, void) \
  18. __JS_ENUMERATE(AsyncGeneratorFunction, async_generator_function, AsyncGeneratorFunctionPrototype, AsyncGeneratorFunctionConstructor, void) \
  19. __JS_ENUMERATE(BigIntObject, bigint, BigIntPrototype, BigIntConstructor, void) \
  20. __JS_ENUMERATE(BooleanObject, boolean, BooleanPrototype, BooleanConstructor, void) \
  21. __JS_ENUMERATE(DataView, data_view, DataViewPrototype, DataViewConstructor, void) \
  22. __JS_ENUMERATE(Date, date, DatePrototype, DateConstructor, void) \
  23. __JS_ENUMERATE(Error, error, ErrorPrototype, ErrorConstructor, void) \
  24. __JS_ENUMERATE(FinalizationRegistry, finalization_registry, FinalizationRegistryPrototype, FinalizationRegistryConstructor, void) \
  25. __JS_ENUMERATE(FunctionObject, function, FunctionPrototype, FunctionConstructor, void) \
  26. __JS_ENUMERATE(GeneratorFunction, generator_function, GeneratorFunctionPrototype, GeneratorFunctionConstructor, void) \
  27. __JS_ENUMERATE(Map, map, MapPrototype, MapConstructor, void) \
  28. __JS_ENUMERATE(NumberObject, number, NumberPrototype, NumberConstructor, void) \
  29. __JS_ENUMERATE(Object, object, ObjectPrototype, ObjectConstructor, void) \
  30. __JS_ENUMERATE(Promise, promise, PromisePrototype, PromiseConstructor, void) \
  31. __JS_ENUMERATE(RegExpObject, regexp, RegExpPrototype, RegExpConstructor, void) \
  32. __JS_ENUMERATE(Set, set, SetPrototype, SetConstructor, void) \
  33. __JS_ENUMERATE(ShadowRealm, shadow_realm, ShadowRealmPrototype, ShadowRealmConstructor, void) \
  34. __JS_ENUMERATE(StringObject, string, StringPrototype, StringConstructor, void) \
  35. __JS_ENUMERATE(SymbolObject, symbol, SymbolPrototype, SymbolConstructor, void) \
  36. __JS_ENUMERATE(WeakMap, weak_map, WeakMapPrototype, WeakMapConstructor, void) \
  37. __JS_ENUMERATE(WeakRef, weak_ref, WeakRefPrototype, WeakRefConstructor, void) \
  38. __JS_ENUMERATE(WeakSet, weak_set, WeakSetPrototype, WeakSetConstructor, void)
  39. #define JS_ENUMERATE_NATIVE_OBJECTS \
  40. JS_ENUMERATE_NATIVE_OBJECTS_EXCLUDING_TEMPLATES \
  41. __JS_ENUMERATE(TypedArray, typed_array, TypedArrayPrototype, TypedArrayConstructor, void)
  42. #define JS_ENUMERATE_NATIVE_ERRORS \
  43. __JS_ENUMERATE(EvalError, eval_error, EvalErrorPrototype, EvalErrorConstructor, void) \
  44. __JS_ENUMERATE(InternalError, internal_error, InternalErrorPrototype, InternalErrorConstructor, void) \
  45. __JS_ENUMERATE(InvalidCharacterError, invalid_character_error, InvalidCharacterErrorPrototype, InvalidCharacterErrorConstructor, void) \
  46. __JS_ENUMERATE(RangeError, range_error, RangeErrorPrototype, RangeErrorConstructor, void) \
  47. __JS_ENUMERATE(ReferenceError, reference_error, ReferenceErrorPrototype, ReferenceErrorConstructor, void) \
  48. __JS_ENUMERATE(SyntaxError, syntax_error, SyntaxErrorPrototype, SyntaxErrorConstructor, void) \
  49. __JS_ENUMERATE(TypeError, type_error, TypeErrorPrototype, TypeErrorConstructor, void) \
  50. __JS_ENUMERATE(URIError, uri_error, URIErrorPrototype, URIErrorConstructor, void)
  51. #define JS_ENUMERATE_TYPED_ARRAYS \
  52. __JS_ENUMERATE(Uint8Array, uint8_array, Uint8ArrayPrototype, Uint8ArrayConstructor, u8) \
  53. __JS_ENUMERATE(Uint8ClampedArray, uint8_clamped_array, Uint8ClampedArrayPrototype, Uint8ClampedArrayConstructor, ClampedU8) \
  54. __JS_ENUMERATE(Uint16Array, uint16_array, Uint16ArrayPrototype, Uint16ArrayConstructor, u16) \
  55. __JS_ENUMERATE(Uint32Array, uint32_array, Uint32ArrayPrototype, Uint32ArrayConstructor, u32) \
  56. __JS_ENUMERATE(BigUint64Array, big_uint64_array, BigUint64ArrayPrototype, BigUint64ArrayConstructor, u64) \
  57. __JS_ENUMERATE(Int8Array, int8_array, Int8ArrayPrototype, Int8ArrayConstructor, i8) \
  58. __JS_ENUMERATE(Int16Array, int16_array, Int16ArrayPrototype, Int16ArrayConstructor, i16) \
  59. __JS_ENUMERATE(Int32Array, int32_array, Int32ArrayPrototype, Int32ArrayConstructor, i32) \
  60. __JS_ENUMERATE(BigInt64Array, big_int64_array, BigInt64ArrayPrototype, BigInt64ArrayConstructor, i64) \
  61. __JS_ENUMERATE(Float32Array, float32_array, Float32ArrayPrototype, Float32ArrayConstructor, float) \
  62. __JS_ENUMERATE(Float64Array, float64_array, Float64ArrayPrototype, Float64ArrayConstructor, double)
  63. #define JS_ENUMERATE_INTL_OBJECTS \
  64. __JS_ENUMERATE(Collator, collator, CollatorPrototype, CollatorConstructor) \
  65. __JS_ENUMERATE(DateTimeFormat, date_time_format, DateTimeFormatPrototype, DateTimeFormatConstructor) \
  66. __JS_ENUMERATE(DisplayNames, display_names, DisplayNamesPrototype, DisplayNamesConstructor) \
  67. __JS_ENUMERATE(ListFormat, list_format, ListFormatPrototype, ListFormatConstructor) \
  68. __JS_ENUMERATE(Locale, locale, LocalePrototype, LocaleConstructor) \
  69. __JS_ENUMERATE(NumberFormat, number_format, NumberFormatPrototype, NumberFormatConstructor) \
  70. __JS_ENUMERATE(PluralRules, plural_rules, PluralRulesPrototype, PluralRulesConstructor) \
  71. __JS_ENUMERATE(RelativeTimeFormat, relative_time_format, RelativeTimeFormatPrototype, RelativeTimeFormatConstructor) \
  72. __JS_ENUMERATE(Segmenter, segmenter, SegmenterPrototype, SegmenterConstructor)
  73. #define JS_ENUMERATE_TEMPORAL_OBJECTS \
  74. __JS_ENUMERATE(Calendar, calendar, CalendarPrototype, CalendarConstructor) \
  75. __JS_ENUMERATE(Duration, duration, DurationPrototype, DurationConstructor) \
  76. __JS_ENUMERATE(Instant, instant, InstantPrototype, InstantConstructor) \
  77. __JS_ENUMERATE(PlainDate, plain_date, PlainDatePrototype, PlainDateConstructor) \
  78. __JS_ENUMERATE(PlainDateTime, plain_date_time, PlainDateTimePrototype, PlainDateTimeConstructor) \
  79. __JS_ENUMERATE(PlainMonthDay, plain_month_day, PlainMonthDayPrototype, PlainMonthDayConstructor) \
  80. __JS_ENUMERATE(PlainTime, plain_time, PlainTimePrototype, PlainTimeConstructor) \
  81. __JS_ENUMERATE(PlainYearMonth, plain_year_month, PlainYearMonthPrototype, PlainYearMonthConstructor) \
  82. __JS_ENUMERATE(TimeZone, time_zone, TimeZonePrototype, TimeZoneConstructor) \
  83. __JS_ENUMERATE(ZonedDateTime, zoned_date_time, ZonedDateTimePrototype, ZonedDateTimeConstructor)
  84. #define JS_ENUMERATE_ITERATOR_PROTOTYPES \
  85. __JS_ENUMERATE(Iterator, iterator) \
  86. __JS_ENUMERATE(ArrayIterator, array_iterator) \
  87. __JS_ENUMERATE(AsyncIterator, async_iterator) \
  88. __JS_ENUMERATE(Intl::SegmentIterator, intl_segment_iterator) \
  89. __JS_ENUMERATE(MapIterator, map_iterator) \
  90. __JS_ENUMERATE(RegExpStringIterator, regexp_string_iterator) \
  91. __JS_ENUMERATE(SetIterator, set_iterator) \
  92. __JS_ENUMERATE(StringIterator, string_iterator)
  93. #define JS_ENUMERATE_BUILTIN_TYPES \
  94. JS_ENUMERATE_NATIVE_OBJECTS \
  95. JS_ENUMERATE_NATIVE_ERRORS \
  96. JS_ENUMERATE_TYPED_ARRAYS
  97. #define JS_ENUMERATE_WELL_KNOWN_SYMBOLS \
  98. __JS_ENUMERATE(iterator, iterator) \
  99. __JS_ENUMERATE(asyncIterator, async_iterator) \
  100. __JS_ENUMERATE(match, match) \
  101. __JS_ENUMERATE(matchAll, match_all) \
  102. __JS_ENUMERATE(replace, replace) \
  103. __JS_ENUMERATE(replaceAll, replace_all) \
  104. __JS_ENUMERATE(search, search) \
  105. __JS_ENUMERATE(split, split) \
  106. __JS_ENUMERATE(hasInstance, has_instance) \
  107. __JS_ENUMERATE(isConcatSpreadable, is_concat_spreadable) \
  108. __JS_ENUMERATE(unscopables, unscopables) \
  109. __JS_ENUMERATE(species, species) \
  110. __JS_ENUMERATE(toPrimitive, to_primitive) \
  111. __JS_ENUMERATE(toStringTag, to_string_tag)
  112. #define JS_ENUMERATE_REGEXP_FLAGS \
  113. __JS_ENUMERATE(hasIndices, has_indices, d) \
  114. __JS_ENUMERATE(global, global, g) \
  115. __JS_ENUMERATE(ignoreCase, ignore_case, i) \
  116. __JS_ENUMERATE(multiline, multiline, m) \
  117. __JS_ENUMERATE(dotAll, dot_all, s) \
  118. __JS_ENUMERATE(unicode, unicode, u) \
  119. __JS_ENUMERATE(sticky, sticky, y)
  120. namespace JS {
  121. class ASTNode;
  122. class Accessor;
  123. class BigInt;
  124. class BoundFunction;
  125. class Cell;
  126. class CellAllocator;
  127. class ClassExpression;
  128. struct ClassFieldDefinition;
  129. class Completion;
  130. class Console;
  131. class DeclarativeEnvironment;
  132. class DeferGC;
  133. class ECMAScriptFunctionObject;
  134. class Environment;
  135. class Error;
  136. class ErrorType;
  137. struct ExecutionContext;
  138. class Expression;
  139. class FunctionEnvironment;
  140. class FunctionNode;
  141. class GlobalEnvironment;
  142. class GlobalObject;
  143. class HandleImpl;
  144. class Heap;
  145. class HeapBlock;
  146. class Interpreter;
  147. class Module;
  148. class NativeFunction;
  149. class ObjectEnvironment;
  150. class PrimitiveString;
  151. class PromiseReaction;
  152. class PromiseReactionJob;
  153. class PromiseResolveThenableJob;
  154. class PropertyAttributes;
  155. class PropertyDescriptor;
  156. class PropertyKey;
  157. class Realm;
  158. class Reference;
  159. class ScopeNode;
  160. class Script;
  161. class Shape;
  162. class Statement;
  163. class StringOrSymbol;
  164. class SourceTextModule;
  165. class Symbol;
  166. class Token;
  167. class Utf16String;
  168. class VM;
  169. class Value;
  170. class WeakContainer;
  171. class WrappedFunction;
  172. enum class DeclarationKind;
  173. struct AlreadyResolved;
  174. struct JobCallback;
  175. struct ModuleRequest;
  176. struct PromiseCapability;
  177. // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype
  178. class ProxyObject;
  179. class ProxyConstructor;
  180. // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct constructor
  181. class AsyncFromSyncIteratorPrototype;
  182. class AsyncGenerator;
  183. class AsyncGeneratorPrototype;
  184. class GeneratorPrototype;
  185. class TypedArrayConstructor;
  186. class TypedArrayPrototype;
  187. // Tag type used to differentiate between u8 as used by Uint8Array and u8 as used by Uint8ClampedArray.
  188. struct ClampedU8;
  189. #define __JS_ENUMERATE(ClassName, snake_name, ConstructorName, PrototypeName, ArrayType) \
  190. class ClassName; \
  191. class ConstructorName; \
  192. class PrototypeName;
  193. JS_ENUMERATE_NATIVE_OBJECTS_EXCLUDING_TEMPLATES
  194. JS_ENUMERATE_NATIVE_ERRORS
  195. JS_ENUMERATE_TYPED_ARRAYS
  196. #undef __JS_ENUMERATE
  197. namespace Intl {
  198. #define __JS_ENUMERATE(ClassName, snake_name, ConstructorName, PrototypeName) \
  199. class ClassName; \
  200. class ConstructorName; \
  201. class PrototypeName;
  202. JS_ENUMERATE_INTL_OBJECTS
  203. #undef __JS_ENUMERATE
  204. // Not included in JS_ENUMERATE_INTL_OBJECTS due to missing distinct constructor
  205. class Segments;
  206. class SegmentsPrototype;
  207. };
  208. namespace Temporal {
  209. #define __JS_ENUMERATE(ClassName, snake_name, ConstructorName, PrototypeName) \
  210. class ClassName; \
  211. class ConstructorName; \
  212. class PrototypeName;
  213. JS_ENUMERATE_TEMPORAL_OBJECTS
  214. #undef __JS_ENUMERATE
  215. struct DurationRecord;
  216. struct DateDurationRecord;
  217. struct TimeDurationRecord;
  218. struct PartialDurationRecord;
  219. };
  220. template<typename T>
  221. class ThrowCompletionOr;
  222. template<class T>
  223. class Handle;
  224. template<class T, size_t inline_capacity = 32>
  225. class MarkedVector;
  226. namespace Bytecode {
  227. class BasicBlock;
  228. struct Executable;
  229. class Generator;
  230. class Instruction;
  231. class Interpreter;
  232. class Register;
  233. }
  234. }