Forward.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /*
  2. * Copyright (c) 2020-2021, Andreas Kling <andreas@ladybird.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(Float16Array, float16_array, Float16ArrayPrototype, Float16ArrayConstructor, f16) \
  67. __JS_ENUMERATE(Float32Array, float32_array, Float32ArrayPrototype, Float32ArrayConstructor, float) \
  68. __JS_ENUMERATE(Float64Array, float64_array, Float64ArrayPrototype, Float64ArrayConstructor, double)
  69. #define JS_ENUMERATE_INTL_OBJECTS \
  70. __JS_ENUMERATE(Collator, collator, CollatorPrototype, CollatorConstructor) \
  71. __JS_ENUMERATE(DateTimeFormat, date_time_format, DateTimeFormatPrototype, DateTimeFormatConstructor) \
  72. __JS_ENUMERATE(DisplayNames, display_names, DisplayNamesPrototype, DisplayNamesConstructor) \
  73. __JS_ENUMERATE(DurationFormat, duration_format, DurationFormatPrototype, DurationFormatConstructor) \
  74. __JS_ENUMERATE(ListFormat, list_format, ListFormatPrototype, ListFormatConstructor) \
  75. __JS_ENUMERATE(Locale, locale, LocalePrototype, LocaleConstructor) \
  76. __JS_ENUMERATE(NumberFormat, number_format, NumberFormatPrototype, NumberFormatConstructor) \
  77. __JS_ENUMERATE(PluralRules, plural_rules, PluralRulesPrototype, PluralRulesConstructor) \
  78. __JS_ENUMERATE(RelativeTimeFormat, relative_time_format, RelativeTimeFormatPrototype, RelativeTimeFormatConstructor) \
  79. __JS_ENUMERATE(Segmenter, segmenter, SegmenterPrototype, SegmenterConstructor)
  80. #define JS_ENUMERATE_TEMPORAL_OBJECTS \
  81. __JS_ENUMERATE(Calendar, calendar, CalendarPrototype, CalendarConstructor) \
  82. __JS_ENUMERATE(Duration, duration, DurationPrototype, DurationConstructor) \
  83. __JS_ENUMERATE(Instant, instant, InstantPrototype, InstantConstructor) \
  84. __JS_ENUMERATE(PlainDate, plain_date, PlainDatePrototype, PlainDateConstructor) \
  85. __JS_ENUMERATE(PlainDateTime, plain_date_time, PlainDateTimePrototype, PlainDateTimeConstructor) \
  86. __JS_ENUMERATE(PlainMonthDay, plain_month_day, PlainMonthDayPrototype, PlainMonthDayConstructor) \
  87. __JS_ENUMERATE(PlainTime, plain_time, PlainTimePrototype, PlainTimeConstructor) \
  88. __JS_ENUMERATE(PlainYearMonth, plain_year_month, PlainYearMonthPrototype, PlainYearMonthConstructor) \
  89. __JS_ENUMERATE(TimeZone, time_zone, TimeZonePrototype, TimeZoneConstructor) \
  90. __JS_ENUMERATE(ZonedDateTime, zoned_date_time, ZonedDateTimePrototype, ZonedDateTimeConstructor)
  91. #define JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS \
  92. __JS_ENUMERATE(AtomicsObject, atomics) \
  93. __JS_ENUMERATE(ConsoleObject, console) \
  94. __JS_ENUMERATE(Intl::Intl, intl) \
  95. __JS_ENUMERATE(JSONObject, json) \
  96. __JS_ENUMERATE(MathObject, math) \
  97. __JS_ENUMERATE(ReflectObject, reflect) \
  98. __JS_ENUMERATE(Temporal::Temporal, temporal)
  99. #define JS_ENUMERATE_ITERATOR_PROTOTYPES \
  100. __JS_ENUMERATE(ArrayIterator, array_iterator) \
  101. __JS_ENUMERATE(AsyncIterator, async_iterator) \
  102. __JS_ENUMERATE(Intl::SegmentIterator, intl_segment_iterator) \
  103. __JS_ENUMERATE(IteratorHelper, iterator_helper) \
  104. __JS_ENUMERATE(MapIterator, map_iterator) \
  105. __JS_ENUMERATE(RegExpStringIterator, regexp_string_iterator) \
  106. __JS_ENUMERATE(SetIterator, set_iterator) \
  107. __JS_ENUMERATE(StringIterator, string_iterator)
  108. #define JS_ENUMERATE_BUILTIN_TYPES \
  109. JS_ENUMERATE_NATIVE_OBJECTS \
  110. JS_ENUMERATE_NATIVE_ERRORS \
  111. JS_ENUMERATE_TYPED_ARRAYS
  112. #define JS_ENUMERATE_WELL_KNOWN_SYMBOLS \
  113. __JS_ENUMERATE(iterator, iterator) \
  114. __JS_ENUMERATE(asyncIterator, async_iterator) \
  115. __JS_ENUMERATE(match, match) \
  116. __JS_ENUMERATE(matchAll, match_all) \
  117. __JS_ENUMERATE(replace, replace) \
  118. __JS_ENUMERATE(replaceAll, replace_all) \
  119. __JS_ENUMERATE(search, search) \
  120. __JS_ENUMERATE(split, split) \
  121. __JS_ENUMERATE(hasInstance, has_instance) \
  122. __JS_ENUMERATE(isConcatSpreadable, is_concat_spreadable) \
  123. __JS_ENUMERATE(unscopables, unscopables) \
  124. __JS_ENUMERATE(species, species) \
  125. __JS_ENUMERATE(toPrimitive, to_primitive) \
  126. __JS_ENUMERATE(toStringTag, to_string_tag) \
  127. __JS_ENUMERATE(dispose, dispose)
  128. #define JS_ENUMERATE_REGEXP_FLAGS \
  129. __JS_ENUMERATE(HasIndices, hasIndices, has_indices, d) \
  130. __JS_ENUMERATE(Global, global, global, g) \
  131. __JS_ENUMERATE(IgnoreCase, ignoreCase, ignore_case, i) \
  132. __JS_ENUMERATE(Multiline, multiline, multiline, m) \
  133. __JS_ENUMERATE(DotAll, dotAll, dot_all, s) \
  134. __JS_ENUMERATE(UnicodeSets, unicodeSets, unicode_sets, v) \
  135. __JS_ENUMERATE(Unicode, unicode, unicode, u) \
  136. __JS_ENUMERATE(Sticky, sticky, sticky, y)
  137. namespace JS {
  138. class ASTNode;
  139. class Accessor;
  140. struct AsyncGeneratorRequest;
  141. class BigInt;
  142. class BoundFunction;
  143. struct CachedSourceRange;
  144. class Cell;
  145. class ClassExpression;
  146. struct ClassFieldDefinition;
  147. class Completion;
  148. class Console;
  149. class CyclicModule;
  150. class DeclarativeEnvironment;
  151. class ECMAScriptFunctionObject;
  152. class Environment;
  153. class Error;
  154. class ErrorType;
  155. struct ExecutionContext;
  156. struct ExportEntry;
  157. class ExportStatement;
  158. class Expression;
  159. class ForStatement;
  160. class FunctionEnvironment;
  161. class FunctionNode;
  162. struct FunctionParameter;
  163. class GlobalEnvironment;
  164. class GlobalObject;
  165. struct GraphLoadingState;
  166. struct ImportEntry;
  167. class ImportStatement;
  168. class Identifier;
  169. class Intrinsics;
  170. class IteratorRecord;
  171. class MemberExpression;
  172. class MetaProperty;
  173. class Module;
  174. struct ModuleRequest;
  175. class NativeFunction;
  176. class ObjectEnvironment;
  177. class Parser;
  178. struct ParserError;
  179. class PrimitiveString;
  180. class Program;
  181. class PromiseCapability;
  182. class PromiseReaction;
  183. class PropertyAttributes;
  184. class PropertyDescriptor;
  185. class PropertyKey;
  186. class Realm;
  187. class Reference;
  188. class ScopeNode;
  189. class Script;
  190. class Shape;
  191. class Statement;
  192. class StringOrSymbol;
  193. class SourceCode;
  194. struct SourceRange;
  195. class SourceTextModule;
  196. class Symbol;
  197. class Token;
  198. class Utf16String;
  199. class VM;
  200. class PrototypeChainValidity;
  201. class Value;
  202. class WrappedFunction;
  203. enum class DeclarationKind;
  204. struct AlreadyResolved;
  205. class JobCallback;
  206. struct ModuleRequest;
  207. struct ModuleWithSpecifier;
  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 TypedArrayBase;
  218. class TypedArrayConstructor;
  219. class TypedArrayPrototype;
  220. class AtomicsObject;
  221. class ConsoleObject;
  222. class JSONObject;
  223. class MathObject;
  224. class ReflectObject;
  225. // Tag type used to differentiate between u8 as used by Uint8Array and u8 as used by Uint8ClampedArray.
  226. struct ClampedU8;
  227. #define __JS_ENUMERATE(ClassName, snake_name, ConstructorName, PrototypeName, ArrayType) \
  228. class ClassName; \
  229. class ConstructorName; \
  230. class PrototypeName;
  231. JS_ENUMERATE_NATIVE_OBJECTS_EXCLUDING_TEMPLATES
  232. JS_ENUMERATE_NATIVE_ERRORS
  233. JS_ENUMERATE_TYPED_ARRAYS
  234. #undef __JS_ENUMERATE
  235. #define __JS_ENUMERATE(ClassName, snake_name) \
  236. class ClassName; \
  237. JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS
  238. #undef __JS_ENUMERATE
  239. namespace Intl {
  240. #define __JS_ENUMERATE(ClassName, snake_name, ConstructorName, PrototypeName) \
  241. class ClassName; \
  242. class ConstructorName; \
  243. class PrototypeName;
  244. JS_ENUMERATE_INTL_OBJECTS
  245. #undef __JS_ENUMERATE
  246. class Intl;
  247. class MathematicalValue;
  248. // Not included in JS_ENUMERATE_INTL_OBJECTS due to missing distinct constructor
  249. class Segments;
  250. class SegmentsPrototype;
  251. };
  252. namespace Temporal {
  253. #define __JS_ENUMERATE(ClassName, snake_name, ConstructorName, PrototypeName) \
  254. class ClassName; \
  255. class ConstructorName; \
  256. class PrototypeName;
  257. JS_ENUMERATE_TEMPORAL_OBJECTS
  258. #undef __JS_ENUMERATE
  259. class Temporal;
  260. struct CalendarMethods;
  261. struct DurationRecord;
  262. struct DateDurationRecord;
  263. struct TimeDurationRecord;
  264. struct TimeZoneMethods;
  265. struct PartialDurationRecord;
  266. };
  267. template<typename T>
  268. requires(!IsLvalueReference<T>)
  269. class ThrowCompletionOr;
  270. namespace Bytecode {
  271. class BasicBlock;
  272. enum class Builtin : u8;
  273. class Executable;
  274. class Generator;
  275. class Instruction;
  276. class Interpreter;
  277. class Operand;
  278. class RegexTable;
  279. class Register;
  280. }
  281. }