Intrinsics.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibJS/Forward.h>
  8. #include <LibJS/Heap/Cell.h>
  9. namespace JS {
  10. class Intrinsics final : public Cell {
  11. JS_CELL(Intrinsics, Cell);
  12. public:
  13. static NonnullGCPtr<Intrinsics> create(Realm&);
  14. Shape* empty_object_shape() { return m_empty_object_shape; }
  15. Shape* new_object_shape() { return m_new_object_shape; }
  16. Shape* new_ordinary_function_prototype_object_shape() { return m_new_ordinary_function_prototype_object_shape; }
  17. // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype
  18. ProxyConstructor* proxy_constructor() { return m_proxy_constructor; }
  19. // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct constructor
  20. Object* async_from_sync_iterator_prototype() { return m_async_from_sync_iterator_prototype; }
  21. Object* async_generator_prototype() { return m_async_generator_prototype; }
  22. Object* generator_prototype() { return m_generator_prototype; }
  23. // Alias for the AsyncGenerator Prototype Object used by the spec (%AsyncGeneratorFunction.prototype.prototype%)
  24. Object* async_generator_function_prototype_prototype() { return m_async_generator_prototype; }
  25. // Alias for the Generator Prototype Object used by the spec (%GeneratorFunction.prototype.prototype%)
  26. Object* generator_function_prototype_prototype() { return m_generator_prototype; }
  27. // Not included in JS_ENUMERATE_INTL_OBJECTS due to missing distinct constructor
  28. Object* intl_segments_prototype() { return m_intl_segments_prototype; }
  29. // Global object functions
  30. FunctionObject* eval_function() const { return m_eval_function; }
  31. FunctionObject* is_finite_function() const { return m_is_finite_function; }
  32. FunctionObject* is_nan_function() const { return m_is_nan_function; }
  33. FunctionObject* parse_float_function() const { return m_parse_float_function; }
  34. FunctionObject* parse_int_function() const { return m_parse_int_function; }
  35. FunctionObject* decode_uri_function() const { return m_decode_uri_function; }
  36. FunctionObject* decode_uri_component_function() const { return m_decode_uri_component_function; }
  37. FunctionObject* encode_uri_function() const { return m_encode_uri_function; }
  38. FunctionObject* encode_uri_component_function() const { return m_encode_uri_component_function; }
  39. FunctionObject* escape_function() const { return m_escape_function; }
  40. FunctionObject* unescape_function() const { return m_unescape_function; }
  41. // Namespace/constructor object functions
  42. FunctionObject* array_prototype_values_function() const { return m_array_prototype_values_function; }
  43. FunctionObject* date_constructor_now_function() const { return m_date_constructor_now_function; }
  44. FunctionObject* json_parse_function() const { return m_json_parse_function; }
  45. FunctionObject* json_stringify_function() const { return m_json_stringify_function; }
  46. FunctionObject* object_prototype_to_string_function() const { return m_object_prototype_to_string_function; }
  47. FunctionObject* throw_type_error_function() const { return m_throw_type_error_function; }
  48. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
  49. ConstructorName* snake_name##_constructor(); \
  50. Object* snake_name##_prototype();
  51. JS_ENUMERATE_BUILTIN_TYPES
  52. #undef __JS_ENUMERATE
  53. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
  54. Intl::ConstructorName* intl_##snake_name##_constructor(); \
  55. Object* intl_##snake_name##_prototype();
  56. JS_ENUMERATE_INTL_OBJECTS
  57. #undef __JS_ENUMERATE
  58. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
  59. Temporal::ConstructorName* temporal_##snake_name##_constructor(); \
  60. Object* temporal_##snake_name##_prototype();
  61. JS_ENUMERATE_TEMPORAL_OBJECTS
  62. #undef __JS_ENUMERATE
  63. #define __JS_ENUMERATE(ClassName, snake_name) \
  64. ClassName* snake_name##_object();
  65. JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS
  66. #undef __JS_ENUMERATE
  67. #define __JS_ENUMERATE(ClassName, snake_name) \
  68. Object* snake_name##_prototype() \
  69. { \
  70. return m_##snake_name##_prototype; \
  71. }
  72. JS_ENUMERATE_ITERATOR_PROTOTYPES
  73. #undef __JS_ENUMERATE
  74. private:
  75. Intrinsics(Realm& realm)
  76. : m_realm(realm)
  77. {
  78. }
  79. virtual void visit_edges(Visitor&) override;
  80. void initialize_intrinsics(Realm&);
  81. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
  82. void initialize_##snake_name();
  83. JS_ENUMERATE_BUILTIN_TYPES
  84. #undef __JS_ENUMERATE
  85. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
  86. void initialize_intl_##snake_name();
  87. JS_ENUMERATE_INTL_OBJECTS
  88. #undef __JS_ENUMERATE
  89. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
  90. void initialize_temporal_##snake_name();
  91. JS_ENUMERATE_TEMPORAL_OBJECTS
  92. #undef __JS_ENUMERATE
  93. Realm& m_realm;
  94. Shape* m_empty_object_shape { nullptr };
  95. Shape* m_new_object_shape { nullptr };
  96. Shape* m_new_ordinary_function_prototype_object_shape { nullptr };
  97. // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype
  98. ProxyConstructor* m_proxy_constructor { nullptr };
  99. // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct constructor
  100. Object* m_async_from_sync_iterator_prototype { nullptr };
  101. Object* m_async_generator_prototype { nullptr };
  102. Object* m_generator_prototype { nullptr };
  103. // Not included in JS_ENUMERATE_INTL_OBJECTS due to missing distinct constructor
  104. Object* m_intl_segments_prototype { nullptr };
  105. // Global object functions
  106. FunctionObject* m_eval_function { nullptr };
  107. FunctionObject* m_is_finite_function { nullptr };
  108. FunctionObject* m_is_nan_function { nullptr };
  109. FunctionObject* m_parse_float_function { nullptr };
  110. FunctionObject* m_parse_int_function { nullptr };
  111. FunctionObject* m_decode_uri_function { nullptr };
  112. FunctionObject* m_decode_uri_component_function { nullptr };
  113. FunctionObject* m_encode_uri_function { nullptr };
  114. FunctionObject* m_encode_uri_component_function { nullptr };
  115. FunctionObject* m_escape_function { nullptr };
  116. FunctionObject* m_unescape_function { nullptr };
  117. // Namespace/constructor object functions
  118. FunctionObject* m_array_prototype_values_function { nullptr };
  119. FunctionObject* m_date_constructor_now_function { nullptr };
  120. FunctionObject* m_json_parse_function { nullptr };
  121. FunctionObject* m_json_stringify_function { nullptr };
  122. FunctionObject* m_object_prototype_to_string_function { nullptr };
  123. FunctionObject* m_throw_type_error_function { nullptr };
  124. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
  125. ConstructorName* m_##snake_name##_constructor { nullptr }; \
  126. Object* m_##snake_name##_prototype { nullptr };
  127. JS_ENUMERATE_BUILTIN_TYPES
  128. #undef __JS_ENUMERATE
  129. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
  130. Intl::ConstructorName* m_intl_##snake_name##_constructor { nullptr }; \
  131. Object* m_intl_##snake_name##_prototype { nullptr };
  132. JS_ENUMERATE_INTL_OBJECTS
  133. #undef __JS_ENUMERATE
  134. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
  135. Temporal::ConstructorName* m_temporal_##snake_name##_constructor { nullptr }; \
  136. Object* m_temporal_##snake_name##_prototype { nullptr };
  137. JS_ENUMERATE_TEMPORAL_OBJECTS
  138. #undef __JS_ENUMERATE
  139. #define __JS_ENUMERATE(ClassName, snake_name) \
  140. ClassName* m_##snake_name##_object { nullptr };
  141. JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS
  142. #undef __JS_ENUMERATE
  143. #define __JS_ENUMERATE(ClassName, snake_name) \
  144. Object* m_##snake_name##_prototype { nullptr };
  145. JS_ENUMERATE_ITERATOR_PROTOTYPES
  146. #undef __JS_ENUMERATE
  147. };
  148. void add_restricted_function_properties(FunctionObject&, Realm&);
  149. }