1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 08:17:35 +00:00

LibJS: Move construction of GlobalObject native functions to Intrinsics

This will later allow global objects not inheriting from the regular
JS::GlobalObject to pull in these functions without having to implement
them from scratch. The primary use case here is, again, a wrapper-less
HTML::Window in LibWeb :^)

Allocating these upfront now allows us to get rid of two hacks:

- The GlobalObject assigning Intrinsics private members after finishing
  its initialization
- The GlobalObject defining the parseInt and parseFloat properties of
  the NumberConstructor object, as they are supposed to be identical
  with the global functions of the same name
This commit is contained in:
Linus Groh 2022-08-28 17:09:31 +01:00
parent 3d5300a25e
commit e3804e6426
5 changed files with 56 additions and 25 deletions

View file

@ -14,9 +14,6 @@ namespace JS {
class Intrinsics final : public Cell {
public:
// Allow the global object to set intrinsics, ugly but needed for now.
friend class GlobalObject;
static Intrinsics* create(Realm&);
Intrinsics() = default;
@ -42,9 +39,22 @@ public:
// Not included in JS_ENUMERATE_INTL_OBJECTS due to missing distinct constructor
Object* intl_segments_prototype() { return m_intl_segments_prototype; }
// Global object functions
FunctionObject* eval_function() const { return m_eval_function; }
FunctionObject* is_finite_function() const { return m_is_finite_function; }
FunctionObject* is_nan_function() const { return m_is_nan_function; }
FunctionObject* parse_float_function() const { return m_parse_float_function; }
FunctionObject* parse_int_function() const { return m_parse_int_function; }
FunctionObject* decode_uri_function() const { return m_decode_uri_function; }
FunctionObject* decode_uri_component_function() const { return m_decode_uri_component_function; }
FunctionObject* encode_uri_function() const { return m_encode_uri_function; }
FunctionObject* encode_uri_component_function() const { return m_encode_uri_component_function; }
FunctionObject* escape_function() const { return m_escape_function; }
FunctionObject* unescape_function() const { return m_unescape_function; }
// Namespace/constructor object functions
FunctionObject* array_prototype_values_function() const { return m_array_prototype_values_function; }
FunctionObject* date_constructor_now_function() const { return m_date_constructor_now_function; }
FunctionObject* eval_function() const { return m_eval_function; }
FunctionObject* json_parse_function() const { return m_json_parse_function; }
FunctionObject* object_prototype_to_string_function() const { return m_object_prototype_to_string_function; }
FunctionObject* throw_type_error_function() const { return m_throw_type_error_function; }
@ -122,9 +132,22 @@ private:
// Not included in JS_ENUMERATE_INTL_OBJECTS due to missing distinct constructor
Object* m_intl_segments_prototype { nullptr };
// Global object functions
FunctionObject* m_eval_function { nullptr };
FunctionObject* m_is_finite_function { nullptr };
FunctionObject* m_is_nan_function { nullptr };
FunctionObject* m_parse_float_function { nullptr };
FunctionObject* m_parse_int_function { nullptr };
FunctionObject* m_decode_uri_function { nullptr };
FunctionObject* m_decode_uri_component_function { nullptr };
FunctionObject* m_encode_uri_function { nullptr };
FunctionObject* m_encode_uri_component_function { nullptr };
FunctionObject* m_escape_function { nullptr };
FunctionObject* m_unescape_function { nullptr };
// Namespace/constructor object functions
FunctionObject* m_array_prototype_values_function { nullptr };
FunctionObject* m_date_constructor_now_function { nullptr };
FunctionObject* m_eval_function { nullptr };
FunctionObject* m_json_parse_function { nullptr };
FunctionObject* m_object_prototype_to_string_function { nullptr };
FunctionObject* m_throw_type_error_function { nullptr };