Intrinsics.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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* object_prototype_to_string_function() const { return m_object_prototype_to_string_function; }
  46. FunctionObject* throw_type_error_function() const { return m_throw_type_error_function; }
  47. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
  48. ConstructorName* snake_name##_constructor() \
  49. { \
  50. return m_##snake_name##_constructor; \
  51. } \
  52. Object* snake_name##_prototype() \
  53. { \
  54. return m_##snake_name##_prototype; \
  55. }
  56. JS_ENUMERATE_BUILTIN_TYPES
  57. #undef __JS_ENUMERATE
  58. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
  59. Intl::ConstructorName* intl_##snake_name##_constructor() \
  60. { \
  61. return m_intl_##snake_name##_constructor; \
  62. } \
  63. Object* intl_##snake_name##_prototype() \
  64. { \
  65. return m_intl_##snake_name##_prototype; \
  66. }
  67. JS_ENUMERATE_INTL_OBJECTS
  68. #undef __JS_ENUMERATE
  69. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
  70. Temporal::ConstructorName* temporal_##snake_name##_constructor() \
  71. { \
  72. return m_temporal_##snake_name##_constructor; \
  73. } \
  74. Object* temporal_##snake_name##_prototype() \
  75. { \
  76. return m_temporal_##snake_name##_prototype; \
  77. }
  78. JS_ENUMERATE_TEMPORAL_OBJECTS
  79. #undef __JS_ENUMERATE
  80. #define __JS_ENUMERATE(ClassName, snake_name) \
  81. ClassName* snake_name##_object() \
  82. { \
  83. return m_##snake_name##_object; \
  84. }
  85. JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS
  86. #undef __JS_ENUMERATE
  87. #define __JS_ENUMERATE(ClassName, snake_name) \
  88. Object* snake_name##_prototype() \
  89. { \
  90. return m_##snake_name##_prototype; \
  91. }
  92. JS_ENUMERATE_ITERATOR_PROTOTYPES
  93. #undef __JS_ENUMERATE
  94. private:
  95. Intrinsics() = default;
  96. virtual void visit_edges(Visitor&) override;
  97. void initialize_intrinsics(Realm&);
  98. Shape* m_empty_object_shape { nullptr };
  99. Shape* m_new_object_shape { nullptr };
  100. Shape* m_new_ordinary_function_prototype_object_shape { nullptr };
  101. // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype
  102. ProxyConstructor* m_proxy_constructor { nullptr };
  103. // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct constructor
  104. Object* m_async_from_sync_iterator_prototype { nullptr };
  105. Object* m_async_generator_prototype { nullptr };
  106. Object* m_generator_prototype { nullptr };
  107. // Not included in JS_ENUMERATE_INTL_OBJECTS due to missing distinct constructor
  108. Object* m_intl_segments_prototype { nullptr };
  109. // Global object functions
  110. FunctionObject* m_eval_function { nullptr };
  111. FunctionObject* m_is_finite_function { nullptr };
  112. FunctionObject* m_is_nan_function { nullptr };
  113. FunctionObject* m_parse_float_function { nullptr };
  114. FunctionObject* m_parse_int_function { nullptr };
  115. FunctionObject* m_decode_uri_function { nullptr };
  116. FunctionObject* m_decode_uri_component_function { nullptr };
  117. FunctionObject* m_encode_uri_function { nullptr };
  118. FunctionObject* m_encode_uri_component_function { nullptr };
  119. FunctionObject* m_escape_function { nullptr };
  120. FunctionObject* m_unescape_function { nullptr };
  121. // Namespace/constructor object functions
  122. FunctionObject* m_array_prototype_values_function { nullptr };
  123. FunctionObject* m_date_constructor_now_function { nullptr };
  124. FunctionObject* m_json_parse_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. }