Intrinsics.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /*
  2. * Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Runtime/AggregateErrorConstructor.h>
  7. #include <LibJS/Runtime/AggregateErrorPrototype.h>
  8. #include <LibJS/Runtime/ArrayBufferConstructor.h>
  9. #include <LibJS/Runtime/ArrayBufferPrototype.h>
  10. #include <LibJS/Runtime/ArrayConstructor.h>
  11. #include <LibJS/Runtime/ArrayIteratorPrototype.h>
  12. #include <LibJS/Runtime/ArrayPrototype.h>
  13. #include <LibJS/Runtime/AsyncFromSyncIteratorPrototype.h>
  14. #include <LibJS/Runtime/AsyncFunctionConstructor.h>
  15. #include <LibJS/Runtime/AsyncFunctionPrototype.h>
  16. #include <LibJS/Runtime/AsyncGeneratorFunctionConstructor.h>
  17. #include <LibJS/Runtime/AsyncGeneratorFunctionPrototype.h>
  18. #include <LibJS/Runtime/AsyncGeneratorPrototype.h>
  19. #include <LibJS/Runtime/AsyncIteratorPrototype.h>
  20. #include <LibJS/Runtime/AtomicsObject.h>
  21. #include <LibJS/Runtime/BigIntConstructor.h>
  22. #include <LibJS/Runtime/BigIntPrototype.h>
  23. #include <LibJS/Runtime/BooleanConstructor.h>
  24. #include <LibJS/Runtime/BooleanPrototype.h>
  25. #include <LibJS/Runtime/ConsoleObject.h>
  26. #include <LibJS/Runtime/DataViewConstructor.h>
  27. #include <LibJS/Runtime/DataViewPrototype.h>
  28. #include <LibJS/Runtime/DateConstructor.h>
  29. #include <LibJS/Runtime/DatePrototype.h>
  30. #include <LibJS/Runtime/ErrorConstructor.h>
  31. #include <LibJS/Runtime/ErrorPrototype.h>
  32. #include <LibJS/Runtime/FinalizationRegistryConstructor.h>
  33. #include <LibJS/Runtime/FinalizationRegistryPrototype.h>
  34. #include <LibJS/Runtime/FunctionConstructor.h>
  35. #include <LibJS/Runtime/FunctionPrototype.h>
  36. #include <LibJS/Runtime/GeneratorFunctionConstructor.h>
  37. #include <LibJS/Runtime/GeneratorFunctionPrototype.h>
  38. #include <LibJS/Runtime/GeneratorPrototype.h>
  39. #include <LibJS/Runtime/Intl/CollatorConstructor.h>
  40. #include <LibJS/Runtime/Intl/CollatorPrototype.h>
  41. #include <LibJS/Runtime/Intl/DateTimeFormatConstructor.h>
  42. #include <LibJS/Runtime/Intl/DateTimeFormatPrototype.h>
  43. #include <LibJS/Runtime/Intl/DisplayNamesConstructor.h>
  44. #include <LibJS/Runtime/Intl/DisplayNamesPrototype.h>
  45. #include <LibJS/Runtime/Intl/DurationFormatConstructor.h>
  46. #include <LibJS/Runtime/Intl/DurationFormatPrototype.h>
  47. #include <LibJS/Runtime/Intl/Intl.h>
  48. #include <LibJS/Runtime/Intl/ListFormatConstructor.h>
  49. #include <LibJS/Runtime/Intl/ListFormatPrototype.h>
  50. #include <LibJS/Runtime/Intl/LocaleConstructor.h>
  51. #include <LibJS/Runtime/Intl/LocalePrototype.h>
  52. #include <LibJS/Runtime/Intl/NumberFormatConstructor.h>
  53. #include <LibJS/Runtime/Intl/NumberFormatPrototype.h>
  54. #include <LibJS/Runtime/Intl/PluralRulesConstructor.h>
  55. #include <LibJS/Runtime/Intl/PluralRulesPrototype.h>
  56. #include <LibJS/Runtime/Intl/RelativeTimeFormatConstructor.h>
  57. #include <LibJS/Runtime/Intl/RelativeTimeFormatPrototype.h>
  58. #include <LibJS/Runtime/Intl/SegmentIteratorPrototype.h>
  59. #include <LibJS/Runtime/Intl/SegmenterConstructor.h>
  60. #include <LibJS/Runtime/Intl/SegmenterPrototype.h>
  61. #include <LibJS/Runtime/Intl/SegmentsPrototype.h>
  62. #include <LibJS/Runtime/Intrinsics.h>
  63. #include <LibJS/Runtime/IteratorPrototype.h>
  64. #include <LibJS/Runtime/JSONObject.h>
  65. #include <LibJS/Runtime/MapConstructor.h>
  66. #include <LibJS/Runtime/MapIteratorPrototype.h>
  67. #include <LibJS/Runtime/MapPrototype.h>
  68. #include <LibJS/Runtime/MathObject.h>
  69. #include <LibJS/Runtime/NativeFunction.h>
  70. #include <LibJS/Runtime/NumberConstructor.h>
  71. #include <LibJS/Runtime/NumberPrototype.h>
  72. #include <LibJS/Runtime/ObjectConstructor.h>
  73. #include <LibJS/Runtime/ObjectPrototype.h>
  74. #include <LibJS/Runtime/PromiseConstructor.h>
  75. #include <LibJS/Runtime/PromisePrototype.h>
  76. #include <LibJS/Runtime/ProxyConstructor.h>
  77. #include <LibJS/Runtime/Realm.h>
  78. #include <LibJS/Runtime/ReflectObject.h>
  79. #include <LibJS/Runtime/RegExpConstructor.h>
  80. #include <LibJS/Runtime/RegExpPrototype.h>
  81. #include <LibJS/Runtime/RegExpStringIteratorPrototype.h>
  82. #include <LibJS/Runtime/SetConstructor.h>
  83. #include <LibJS/Runtime/SetIteratorPrototype.h>
  84. #include <LibJS/Runtime/SetPrototype.h>
  85. #include <LibJS/Runtime/ShadowRealmConstructor.h>
  86. #include <LibJS/Runtime/ShadowRealmPrototype.h>
  87. #include <LibJS/Runtime/Shape.h>
  88. #include <LibJS/Runtime/StringConstructor.h>
  89. #include <LibJS/Runtime/StringIteratorPrototype.h>
  90. #include <LibJS/Runtime/StringPrototype.h>
  91. #include <LibJS/Runtime/SymbolConstructor.h>
  92. #include <LibJS/Runtime/SymbolPrototype.h>
  93. #include <LibJS/Runtime/Temporal/CalendarConstructor.h>
  94. #include <LibJS/Runtime/Temporal/CalendarPrototype.h>
  95. #include <LibJS/Runtime/Temporal/DurationConstructor.h>
  96. #include <LibJS/Runtime/Temporal/DurationPrototype.h>
  97. #include <LibJS/Runtime/Temporal/InstantConstructor.h>
  98. #include <LibJS/Runtime/Temporal/InstantPrototype.h>
  99. #include <LibJS/Runtime/Temporal/PlainDateConstructor.h>
  100. #include <LibJS/Runtime/Temporal/PlainDatePrototype.h>
  101. #include <LibJS/Runtime/Temporal/PlainDateTimeConstructor.h>
  102. #include <LibJS/Runtime/Temporal/PlainDateTimePrototype.h>
  103. #include <LibJS/Runtime/Temporal/PlainMonthDayConstructor.h>
  104. #include <LibJS/Runtime/Temporal/PlainMonthDayPrototype.h>
  105. #include <LibJS/Runtime/Temporal/PlainTimeConstructor.h>
  106. #include <LibJS/Runtime/Temporal/PlainTimePrototype.h>
  107. #include <LibJS/Runtime/Temporal/PlainYearMonthConstructor.h>
  108. #include <LibJS/Runtime/Temporal/PlainYearMonthPrototype.h>
  109. #include <LibJS/Runtime/Temporal/Temporal.h>
  110. #include <LibJS/Runtime/Temporal/TimeZoneConstructor.h>
  111. #include <LibJS/Runtime/Temporal/TimeZonePrototype.h>
  112. #include <LibJS/Runtime/Temporal/ZonedDateTimeConstructor.h>
  113. #include <LibJS/Runtime/Temporal/ZonedDateTimePrototype.h>
  114. #include <LibJS/Runtime/TypedArray.h>
  115. #include <LibJS/Runtime/TypedArrayConstructor.h>
  116. #include <LibJS/Runtime/TypedArrayPrototype.h>
  117. #include <LibJS/Runtime/WeakMapConstructor.h>
  118. #include <LibJS/Runtime/WeakMapPrototype.h>
  119. #include <LibJS/Runtime/WeakRefConstructor.h>
  120. #include <LibJS/Runtime/WeakRefPrototype.h>
  121. #include <LibJS/Runtime/WeakSetConstructor.h>
  122. #include <LibJS/Runtime/WeakSetPrototype.h>
  123. namespace JS {
  124. static void initialize_constructor(VM& vm, PropertyKey const& property_key, Object& constructor, Object* prototype, PropertyAttributes constructor_property_attributes = Attribute::Writable | Attribute::Configurable)
  125. {
  126. constructor.define_direct_property(vm.names.name, js_string(vm, property_key.as_string()), Attribute::Configurable);
  127. if (prototype)
  128. prototype->define_direct_property(vm.names.constructor, &constructor, constructor_property_attributes);
  129. }
  130. // 9.3.2 CreateIntrinsics ( realmRec ), https://tc39.es/ecma262/#sec-createintrinsics
  131. Intrinsics* Intrinsics::create(Realm& realm)
  132. {
  133. auto& vm = realm.vm();
  134. // 1. Set realmRec.[[Intrinsics]] to a new Record.
  135. auto* intrinsics = vm.heap().allocate_without_realm<Intrinsics>();
  136. realm.set_intrinsics({}, *intrinsics);
  137. // 2. Set fields of realmRec.[[Intrinsics]] with the values listed in Table 6.
  138. // The field names are the names listed in column one of the table.
  139. // The value of each field is a new object value fully and recursively populated
  140. // with property values as defined by the specification of each object in
  141. // clauses 19 through 28. All object property values are newly created object
  142. // values. All values that are built-in function objects are created by performing
  143. // CreateBuiltinFunction(steps, length, name, slots, realmRec, prototype)
  144. // where steps is the definition of that function provided by this specification,
  145. // name is the initial value of the function's "name" property, length is the
  146. // initial value of the function's "length" property, slots is a list of the
  147. // names, if any, of the function's specified internal slots, and prototype
  148. // is the specified value of the function's [[Prototype]] internal slot. The
  149. // creation of the intrinsics and their properties must be ordered to avoid
  150. // any dependencies upon objects that have not yet been created.
  151. intrinsics->initialize_intrinsics(realm);
  152. // 3. Perform AddRestrictedFunctionProperties(realmRec.[[Intrinsics]].[[%Function.prototype%]], realmRec).
  153. add_restricted_function_properties(static_cast<FunctionObject&>(*realm.intrinsics().function_prototype()), realm);
  154. // 4. Return unused.
  155. return intrinsics;
  156. }
  157. void Intrinsics::initialize_intrinsics(Realm& realm)
  158. {
  159. auto& vm = this->vm();
  160. // These are done first since other prototypes depend on their presence.
  161. m_empty_object_shape = heap().allocate_without_realm<Shape>(realm);
  162. m_object_prototype = heap().allocate_without_realm<ObjectPrototype>(realm);
  163. m_function_prototype = heap().allocate_without_realm<FunctionPrototype>(realm);
  164. m_new_object_shape = heap().allocate_without_realm<Shape>(realm);
  165. m_new_object_shape->set_prototype_without_transition(m_object_prototype);
  166. m_new_ordinary_function_prototype_object_shape = heap().allocate_without_realm<Shape>(realm);
  167. m_new_ordinary_function_prototype_object_shape->set_prototype_without_transition(m_object_prototype);
  168. m_new_ordinary_function_prototype_object_shape->add_property_without_transition(vm.names.constructor, Attribute::Writable | Attribute::Configurable);
  169. // Normally Heap::allocate() takes care of this, but these are allocated via allocate_without_realm().
  170. static_cast<FunctionPrototype*>(m_function_prototype)->initialize(realm);
  171. static_cast<ObjectPrototype*>(m_object_prototype)->initialize(realm);
  172. #define __JS_ENUMERATE(ClassName, snake_name) \
  173. VERIFY(!m_##snake_name##_prototype); \
  174. m_##snake_name##_prototype = heap().allocate<ClassName##Prototype>(realm, realm);
  175. JS_ENUMERATE_ITERATOR_PROTOTYPES
  176. #undef __JS_ENUMERATE
  177. // These must be initialized separately as they have no companion constructor
  178. m_async_from_sync_iterator_prototype = heap().allocate<AsyncFromSyncIteratorPrototype>(realm, realm);
  179. m_async_generator_prototype = heap().allocate<AsyncGeneratorPrototype>(realm, realm);
  180. m_generator_prototype = heap().allocate<GeneratorPrototype>(realm, realm);
  181. m_intl_segments_prototype = heap().allocate<Intl::SegmentsPrototype>(realm, realm);
  182. // These must be initialized before allocating...
  183. // - AggregateErrorPrototype, which uses ErrorPrototype as its prototype
  184. // - AggregateErrorConstructor, which uses ErrorConstructor as its prototype
  185. // - AsyncFunctionConstructor, which uses FunctionConstructor as its prototype
  186. m_error_prototype = heap().allocate<ErrorPrototype>(realm, realm);
  187. m_error_constructor = heap().allocate<ErrorConstructor>(realm, realm);
  188. m_function_constructor = heap().allocate<FunctionConstructor>(realm, realm);
  189. // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype
  190. m_proxy_constructor = heap().allocate<ProxyConstructor>(realm, realm);
  191. // Global object functions
  192. m_eval_function = NativeFunction::create(realm, GlobalObject::eval, 1, vm.names.eval, &realm);
  193. m_is_finite_function = NativeFunction::create(realm, GlobalObject::is_finite, 1, vm.names.isFinite, &realm);
  194. m_is_nan_function = NativeFunction::create(realm, GlobalObject::is_nan, 1, vm.names.isNaN, &realm);
  195. m_parse_float_function = NativeFunction::create(realm, GlobalObject::parse_float, 1, vm.names.parseFloat, &realm);
  196. m_parse_int_function = NativeFunction::create(realm, GlobalObject::parse_int, 2, vm.names.parseInt, &realm);
  197. m_decode_uri_function = NativeFunction::create(realm, GlobalObject::decode_uri, 1, vm.names.decodeURI, &realm);
  198. m_decode_uri_component_function = NativeFunction::create(realm, GlobalObject::decode_uri_component, 1, vm.names.decodeURIComponent, &realm);
  199. m_encode_uri_function = NativeFunction::create(realm, GlobalObject::encode_uri, 1, vm.names.encodeURI, &realm);
  200. m_encode_uri_component_function = NativeFunction::create(realm, GlobalObject::encode_uri_component, 1, vm.names.encodeURIComponent, &realm);
  201. m_escape_function = NativeFunction::create(realm, GlobalObject::escape, 1, vm.names.escape, &realm);
  202. m_unescape_function = NativeFunction::create(realm, GlobalObject::unescape, 1, vm.names.unescape, &realm);
  203. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
  204. /* These are the prototypes allocated earlier, everything else must not yet exist.*/ \
  205. if constexpr (!IsOneOf<PrototypeName, ErrorPrototype, FunctionPrototype, ObjectPrototype>) { \
  206. VERIFY(!m_##snake_name##_prototype); \
  207. m_##snake_name##_prototype = heap().allocate<PrototypeName>(realm, realm); \
  208. } \
  209. if constexpr (!IsOneOf<ConstructorName, ErrorConstructor, FunctionConstructor>) { \
  210. VERIFY(!m_##snake_name##_constructor); \
  211. m_##snake_name##_constructor = heap().allocate<ConstructorName>(realm, realm); \
  212. }
  213. JS_ENUMERATE_BUILTIN_TYPES
  214. #undef __JS_ENUMERATE
  215. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
  216. VERIFY(!m_intl_##snake_name##_constructor); \
  217. VERIFY(!m_intl_##snake_name##_prototype); \
  218. m_intl_##snake_name##_prototype = heap().allocate<Intl::PrototypeName>(realm, realm); \
  219. m_intl_##snake_name##_constructor = heap().allocate<Intl::ConstructorName>(realm, realm); \
  220. initialize_constructor(vm, vm.names.ClassName, *m_intl_##snake_name##_constructor, m_intl_##snake_name##_prototype);
  221. JS_ENUMERATE_INTL_OBJECTS
  222. #undef __JS_ENUMERATE
  223. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
  224. VERIFY(!m_temporal_##snake_name##_constructor); \
  225. VERIFY(!m_temporal_##snake_name##_prototype); \
  226. m_temporal_##snake_name##_prototype = heap().allocate<Temporal::PrototypeName>(realm, realm); \
  227. m_temporal_##snake_name##_constructor = heap().allocate<Temporal::ConstructorName>(realm, realm); \
  228. initialize_constructor(vm, vm.names.ClassName, *m_temporal_##snake_name##_constructor, m_temporal_##snake_name##_prototype);
  229. JS_ENUMERATE_TEMPORAL_OBJECTS
  230. #undef __JS_ENUMERATE
  231. // 10.2.4.1 %ThrowTypeError% ( ), https://tc39.es/ecma262/#sec-%throwtypeerror%
  232. m_throw_type_error_function = NativeFunction::create(
  233. realm, [](VM& vm) {
  234. return vm.throw_completion<TypeError>(ErrorType::RestrictedFunctionPropertiesAccess);
  235. },
  236. 0, "", &realm);
  237. m_throw_type_error_function->define_direct_property(vm.names.length, Value(0), 0);
  238. m_throw_type_error_function->define_direct_property(vm.names.name, js_string(vm, ""), 0);
  239. MUST(m_throw_type_error_function->internal_prevent_extensions());
  240. #define __JS_ENUMERATE(ClassName, snake_name) \
  241. VERIFY(!m_##snake_name##_object); \
  242. m_##snake_name##_object = heap().allocate<ClassName>(realm, realm);
  243. JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS
  244. #undef __JS_ENUMERATE
  245. initialize_constructor(vm, vm.names.AggregateError, *m_aggregate_error_constructor, m_aggregate_error_prototype);
  246. initialize_constructor(vm, vm.names.Array, *m_array_constructor, m_array_prototype);
  247. initialize_constructor(vm, vm.names.ArrayBuffer, *m_array_buffer_constructor, m_array_buffer_prototype);
  248. initialize_constructor(vm, vm.names.BigInt, *m_bigint_constructor, m_bigint_prototype);
  249. initialize_constructor(vm, vm.names.Boolean, *m_boolean_constructor, m_boolean_prototype);
  250. initialize_constructor(vm, vm.names.DataView, *m_data_view_constructor, m_data_view_prototype);
  251. initialize_constructor(vm, vm.names.Date, *m_date_constructor, m_date_prototype);
  252. initialize_constructor(vm, vm.names.Error, *m_error_constructor, m_error_prototype);
  253. initialize_constructor(vm, vm.names.FinalizationRegistry, *m_finalization_registry_constructor, m_finalization_registry_prototype);
  254. initialize_constructor(vm, vm.names.Function, *m_function_constructor, m_function_prototype);
  255. initialize_constructor(vm, vm.names.Map, *m_map_constructor, m_map_prototype);
  256. initialize_constructor(vm, vm.names.Number, *m_number_constructor, m_number_prototype);
  257. initialize_constructor(vm, vm.names.Object, *m_object_constructor, m_object_prototype);
  258. initialize_constructor(vm, vm.names.Promise, *m_promise_constructor, m_promise_prototype);
  259. initialize_constructor(vm, vm.names.Proxy, *m_proxy_constructor, nullptr);
  260. initialize_constructor(vm, vm.names.RegExp, *m_regexp_constructor, m_regexp_prototype);
  261. initialize_constructor(vm, vm.names.Set, *m_set_constructor, m_set_prototype);
  262. initialize_constructor(vm, vm.names.ShadowRealm, *m_shadow_realm_constructor, m_shadow_realm_prototype);
  263. initialize_constructor(vm, vm.names.String, *m_string_constructor, m_string_prototype);
  264. initialize_constructor(vm, vm.names.Symbol, *m_symbol_constructor, m_symbol_prototype);
  265. initialize_constructor(vm, vm.names.TypedArray, *m_typed_array_constructor, m_typed_array_prototype);
  266. initialize_constructor(vm, vm.names.WeakMap, *m_weak_map_constructor, m_weak_map_prototype);
  267. initialize_constructor(vm, vm.names.WeakRef, *m_weak_ref_constructor, m_weak_ref_prototype);
  268. initialize_constructor(vm, vm.names.WeakSet, *m_weak_set_constructor, m_weak_set_prototype);
  269. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
  270. initialize_constructor(vm, vm.names.ClassName, *m_##snake_name##_constructor, m_##snake_name##_prototype);
  271. JS_ENUMERATE_NATIVE_ERRORS
  272. JS_ENUMERATE_TYPED_ARRAYS
  273. #undef __JS_ENUMERATE
  274. initialize_constructor(vm, vm.names.GeneratorFunction, *m_generator_function_constructor, m_generator_function_prototype, Attribute::Configurable);
  275. initialize_constructor(vm, vm.names.AsyncGeneratorFunction, *m_async_generator_function_constructor, m_async_generator_function_prototype, Attribute::Configurable);
  276. initialize_constructor(vm, vm.names.AsyncFunction, *m_async_function_constructor, m_async_function_prototype, Attribute::Configurable);
  277. // 27.5.1.1 Generator.prototype.constructor, https://tc39.es/ecma262/#sec-generator.prototype.constructor
  278. m_generator_prototype->define_direct_property(vm.names.constructor, m_generator_function_prototype, Attribute::Configurable);
  279. // 27.6.1.1 AsyncGenerator.prototype.constructor, https://tc39.es/ecma262/#sec-asyncgenerator-prototype-constructor
  280. m_async_generator_prototype->define_direct_property(vm.names.constructor, m_async_generator_function_prototype, Attribute::Configurable);
  281. m_array_prototype_values_function = &m_array_prototype->get_without_side_effects(vm.names.values).as_function();
  282. m_date_constructor_now_function = &m_date_constructor->get_without_side_effects(vm.names.now).as_function();
  283. m_json_parse_function = &m_json_object->get_without_side_effects(vm.names.parse).as_function();
  284. m_json_stringify_function = &m_json_object->get_without_side_effects(vm.names.stringify).as_function();
  285. m_object_prototype_to_string_function = &m_object_prototype->get_without_side_effects(vm.names.toString).as_function();
  286. }
  287. void Intrinsics::visit_edges(Visitor& visitor)
  288. {
  289. visitor.visit(m_empty_object_shape);
  290. visitor.visit(m_new_object_shape);
  291. visitor.visit(m_new_ordinary_function_prototype_object_shape);
  292. visitor.visit(m_proxy_constructor);
  293. visitor.visit(m_async_from_sync_iterator_prototype);
  294. visitor.visit(m_async_generator_prototype);
  295. visitor.visit(m_generator_prototype);
  296. visitor.visit(m_intl_segments_prototype);
  297. visitor.visit(m_array_prototype_values_function);
  298. visitor.visit(m_date_constructor_now_function);
  299. visitor.visit(m_eval_function);
  300. visitor.visit(m_json_parse_function);
  301. visitor.visit(m_json_stringify_function);
  302. visitor.visit(m_object_prototype_to_string_function);
  303. visitor.visit(m_throw_type_error_function);
  304. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
  305. visitor.visit(m_##snake_name##_constructor); \
  306. visitor.visit(m_##snake_name##_prototype);
  307. JS_ENUMERATE_BUILTIN_TYPES
  308. #undef __JS_ENUMERATE
  309. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
  310. visitor.visit(m_intl_##snake_name##_constructor); \
  311. visitor.visit(m_intl_##snake_name##_prototype);
  312. JS_ENUMERATE_INTL_OBJECTS
  313. #undef __JS_ENUMERATE
  314. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
  315. visitor.visit(m_temporal_##snake_name##_constructor); \
  316. visitor.visit(m_temporal_##snake_name##_prototype);
  317. JS_ENUMERATE_TEMPORAL_OBJECTS
  318. #undef __JS_ENUMERATE
  319. #define __JS_ENUMERATE(ClassName, snake_name) \
  320. visitor.visit(m_##snake_name##_object);
  321. JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS
  322. #undef __JS_ENUMERATE
  323. #define __JS_ENUMERATE(ClassName, snake_name) \
  324. visitor.visit(m_##snake_name##_prototype);
  325. JS_ENUMERATE_ITERATOR_PROTOTYPES
  326. #undef __JS_ENUMERATE
  327. }
  328. // 10.2.4 AddRestrictedFunctionProperties ( F, realm ), https://tc39.es/ecma262/#sec-addrestrictedfunctionproperties
  329. void add_restricted_function_properties(FunctionObject& function, Realm& realm)
  330. {
  331. auto& vm = realm.vm();
  332. // 1. Assert: realm.[[Intrinsics]].[[%ThrowTypeError%]] exists and has been initialized.
  333. VERIFY(realm.intrinsics().throw_type_error_function());
  334. // 2. Let thrower be realm.[[Intrinsics]].[[%ThrowTypeError%]].
  335. auto* thrower = realm.intrinsics().throw_type_error_function();
  336. // 3. Perform ! DefinePropertyOrThrow(F, "caller", PropertyDescriptor { [[Get]]: thrower, [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: true }).
  337. function.define_direct_accessor(vm.names.caller, thrower, thrower, Attribute::Configurable);
  338. // 4. Perform ! DefinePropertyOrThrow(F, "arguments", PropertyDescriptor { [[Get]]: thrower, [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: true }).
  339. function.define_direct_accessor(vm.names.arguments, thrower, thrower, Attribute::Configurable);
  340. // 5. Return unused.
  341. }
  342. }