Intrinsics.cpp 20 KB

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