Intrinsics.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * Copyright (c) 2022, 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 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. { \
  66. return m_##snake_name##_object; \
  67. }
  68. JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS
  69. #undef __JS_ENUMERATE
  70. #define __JS_ENUMERATE(ClassName, snake_name) \
  71. Object* snake_name##_prototype() \
  72. { \
  73. return m_##snake_name##_prototype; \
  74. }
  75. JS_ENUMERATE_ITERATOR_PROTOTYPES
  76. #undef __JS_ENUMERATE
  77. private:
  78. Intrinsics(Realm& realm)
  79. : m_realm(realm)
  80. {
  81. }
  82. virtual void visit_edges(Visitor&) override;
  83. void initialize_intrinsics(Realm&);
  84. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
  85. void initialize_##snake_name();
  86. JS_ENUMERATE_BUILTIN_TYPES
  87. #undef __JS_ENUMERATE
  88. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
  89. void initialize_intl_##snake_name();
  90. JS_ENUMERATE_INTL_OBJECTS
  91. #undef __JS_ENUMERATE
  92. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
  93. void initialize_temporal_##snake_name();
  94. JS_ENUMERATE_TEMPORAL_OBJECTS
  95. #undef __JS_ENUMERATE
  96. Realm& m_realm;
  97. Shape* m_empty_object_shape { nullptr };
  98. Shape* m_new_object_shape { nullptr };
  99. Shape* m_new_ordinary_function_prototype_object_shape { nullptr };
  100. // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype
  101. ProxyConstructor* m_proxy_constructor { nullptr };
  102. // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct constructor
  103. Object* m_async_from_sync_iterator_prototype { nullptr };
  104. Object* m_async_generator_prototype { nullptr };
  105. Object* m_generator_prototype { nullptr };
  106. // Not included in JS_ENUMERATE_INTL_OBJECTS due to missing distinct constructor
  107. Object* m_intl_segments_prototype { nullptr };
  108. // Global object functions
  109. FunctionObject* m_eval_function { nullptr };
  110. FunctionObject* m_is_finite_function { nullptr };
  111. FunctionObject* m_is_nan_function { nullptr };
  112. FunctionObject* m_parse_float_function { nullptr };
  113. FunctionObject* m_parse_int_function { nullptr };
  114. FunctionObject* m_decode_uri_function { nullptr };
  115. FunctionObject* m_decode_uri_component_function { nullptr };
  116. FunctionObject* m_encode_uri_function { nullptr };
  117. FunctionObject* m_encode_uri_component_function { nullptr };
  118. FunctionObject* m_escape_function { nullptr };
  119. FunctionObject* m_unescape_function { nullptr };
  120. // Namespace/constructor object functions
  121. FunctionObject* m_array_prototype_values_function { nullptr };
  122. FunctionObject* m_date_constructor_now_function { nullptr };
  123. FunctionObject* m_json_parse_function { nullptr };
  124. FunctionObject* m_json_stringify_function { nullptr };
  125. FunctionObject* m_object_prototype_to_string_function { nullptr };
  126. FunctionObject* m_throw_type_error_function { nullptr };
  127. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
  128. ConstructorName* m_##snake_name##_constructor { nullptr }; \
  129. Object* m_##snake_name##_prototype { nullptr };
  130. JS_ENUMERATE_BUILTIN_TYPES
  131. #undef __JS_ENUMERATE
  132. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
  133. Intl::ConstructorName* m_intl_##snake_name##_constructor { nullptr }; \
  134. Object* m_intl_##snake_name##_prototype { nullptr };
  135. JS_ENUMERATE_INTL_OBJECTS
  136. #undef __JS_ENUMERATE
  137. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
  138. Temporal::ConstructorName* m_temporal_##snake_name##_constructor { nullptr }; \
  139. Object* m_temporal_##snake_name##_prototype { nullptr };
  140. JS_ENUMERATE_TEMPORAL_OBJECTS
  141. #undef __JS_ENUMERATE
  142. #define __JS_ENUMERATE(ClassName, snake_name) \
  143. ClassName* m_##snake_name##_object { nullptr };
  144. JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS
  145. #undef __JS_ENUMERATE
  146. #define __JS_ENUMERATE(ClassName, snake_name) \
  147. Object* m_##snake_name##_prototype { nullptr };
  148. JS_ENUMERATE_ITERATOR_PROTOTYPES
  149. #undef __JS_ENUMERATE
  150. };
  151. void add_restricted_function_properties(FunctionObject&, Realm&);
  152. }