Intrinsics.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. #include <LibJS/Runtime/Realm.h>
  10. namespace JS {
  11. class Intrinsics final : public Cell {
  12. JS_CELL(Intrinsics, Cell);
  13. public:
  14. static Intrinsics* create(Realm&);
  15. Intrinsics() = default;
  16. Shape* empty_object_shape() { return m_empty_object_shape; }
  17. Shape* new_object_shape() { return m_new_object_shape; }
  18. Shape* new_ordinary_function_prototype_object_shape() { return m_new_ordinary_function_prototype_object_shape; }
  19. // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype
  20. ProxyConstructor* proxy_constructor() { return m_proxy_constructor; }
  21. // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct constructor
  22. Object* async_from_sync_iterator_prototype() { return m_async_from_sync_iterator_prototype; }
  23. Object* async_generator_prototype() { return m_async_generator_prototype; }
  24. Object* generator_prototype() { return m_generator_prototype; }
  25. // Alias for the AsyncGenerator Prototype Object used by the spec (%AsyncGeneratorFunction.prototype.prototype%)
  26. Object* async_generator_function_prototype_prototype() { return m_async_generator_prototype; }
  27. // Alias for the Generator Prototype Object used by the spec (%GeneratorFunction.prototype.prototype%)
  28. Object* generator_function_prototype_prototype() { return m_generator_prototype; }
  29. // Not included in JS_ENUMERATE_INTL_OBJECTS due to missing distinct constructor
  30. Object* intl_segments_prototype() { return m_intl_segments_prototype; }
  31. // Global object functions
  32. FunctionObject* eval_function() const { return m_eval_function; }
  33. FunctionObject* is_finite_function() const { return m_is_finite_function; }
  34. FunctionObject* is_nan_function() const { return m_is_nan_function; }
  35. FunctionObject* parse_float_function() const { return m_parse_float_function; }
  36. FunctionObject* parse_int_function() const { return m_parse_int_function; }
  37. FunctionObject* decode_uri_function() const { return m_decode_uri_function; }
  38. FunctionObject* decode_uri_component_function() const { return m_decode_uri_component_function; }
  39. FunctionObject* encode_uri_function() const { return m_encode_uri_function; }
  40. FunctionObject* encode_uri_component_function() const { return m_encode_uri_component_function; }
  41. FunctionObject* escape_function() const { return m_escape_function; }
  42. FunctionObject* unescape_function() const { return m_unescape_function; }
  43. // Namespace/constructor object functions
  44. FunctionObject* array_prototype_values_function() const { return m_array_prototype_values_function; }
  45. FunctionObject* date_constructor_now_function() const { return m_date_constructor_now_function; }
  46. FunctionObject* json_parse_function() const { return m_json_parse_function; }
  47. FunctionObject* object_prototype_to_string_function() const { return m_object_prototype_to_string_function; }
  48. FunctionObject* throw_type_error_function() const { return m_throw_type_error_function; }
  49. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
  50. ConstructorName* snake_name##_constructor() \
  51. { \
  52. return m_##snake_name##_constructor; \
  53. } \
  54. Object* snake_name##_prototype() \
  55. { \
  56. return m_##snake_name##_prototype; \
  57. }
  58. JS_ENUMERATE_BUILTIN_TYPES
  59. #undef __JS_ENUMERATE
  60. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
  61. Intl::ConstructorName* intl_##snake_name##_constructor() \
  62. { \
  63. return m_intl_##snake_name##_constructor; \
  64. } \
  65. Object* intl_##snake_name##_prototype() \
  66. { \
  67. return m_intl_##snake_name##_prototype; \
  68. }
  69. JS_ENUMERATE_INTL_OBJECTS
  70. #undef __JS_ENUMERATE
  71. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
  72. Temporal::ConstructorName* temporal_##snake_name##_constructor() \
  73. { \
  74. return m_temporal_##snake_name##_constructor; \
  75. } \
  76. Object* temporal_##snake_name##_prototype() \
  77. { \
  78. return m_temporal_##snake_name##_prototype; \
  79. }
  80. JS_ENUMERATE_TEMPORAL_OBJECTS
  81. #undef __JS_ENUMERATE
  82. #define __JS_ENUMERATE(ClassName, snake_name) \
  83. ClassName* snake_name##_object() \
  84. { \
  85. return m_##snake_name##_object; \
  86. }
  87. JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS
  88. #undef __JS_ENUMERATE
  89. #define __JS_ENUMERATE(ClassName, snake_name) \
  90. Object* snake_name##_prototype() \
  91. { \
  92. return m_##snake_name##_prototype; \
  93. }
  94. JS_ENUMERATE_ITERATOR_PROTOTYPES
  95. #undef __JS_ENUMERATE
  96. private:
  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_object_prototype_to_string_function { nullptr };
  127. FunctionObject* m_throw_type_error_function { nullptr };
  128. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \
  129. ConstructorName* m_##snake_name##_constructor { nullptr }; \
  130. Object* m_##snake_name##_prototype { nullptr };
  131. JS_ENUMERATE_BUILTIN_TYPES
  132. #undef __JS_ENUMERATE
  133. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
  134. Intl::ConstructorName* m_intl_##snake_name##_constructor { nullptr }; \
  135. Object* m_intl_##snake_name##_prototype { nullptr };
  136. JS_ENUMERATE_INTL_OBJECTS
  137. #undef __JS_ENUMERATE
  138. #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
  139. Temporal::ConstructorName* m_temporal_##snake_name##_constructor { nullptr }; \
  140. Object* m_temporal_##snake_name##_prototype { nullptr };
  141. JS_ENUMERATE_TEMPORAL_OBJECTS
  142. #undef __JS_ENUMERATE
  143. #define __JS_ENUMERATE(ClassName, snake_name) \
  144. ClassName* m_##snake_name##_object { nullptr };
  145. JS_ENUMERATE_BUILTIN_NAMESPACE_OBJECTS
  146. #undef __JS_ENUMERATE
  147. #define __JS_ENUMERATE(ClassName, snake_name) \
  148. Object* m_##snake_name##_prototype { nullptr };
  149. JS_ENUMERATE_ITERATOR_PROTOTYPES
  150. #undef __JS_ENUMERATE
  151. };
  152. void add_restricted_function_properties(FunctionObject&, Realm&);
  153. }