Forward.h 16 KB

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