Intrinsics.h 8.8 KB

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