Browse Source

LibJS: Add JSON.stringify function to the intrinsics

This is needed for some Web APIs.
Linus Groh 2 years ago
parent
commit
4e536eaf98

+ 2 - 0
Userland/Libraries/LibJS/Runtime/Intrinsics.cpp

@@ -310,6 +310,7 @@ void Intrinsics::initialize_intrinsics(Realm& realm)
     m_array_prototype_values_function = &m_array_prototype->get_without_side_effects(vm.names.values).as_function();
     m_array_prototype_values_function = &m_array_prototype->get_without_side_effects(vm.names.values).as_function();
     m_date_constructor_now_function = &m_date_constructor->get_without_side_effects(vm.names.now).as_function();
     m_date_constructor_now_function = &m_date_constructor->get_without_side_effects(vm.names.now).as_function();
     m_json_parse_function = &m_json_object->get_without_side_effects(vm.names.parse).as_function();
     m_json_parse_function = &m_json_object->get_without_side_effects(vm.names.parse).as_function();
+    m_json_stringify_function = &m_json_object->get_without_side_effects(vm.names.stringify).as_function();
     m_object_prototype_to_string_function = &m_object_prototype->get_without_side_effects(vm.names.toString).as_function();
     m_object_prototype_to_string_function = &m_object_prototype->get_without_side_effects(vm.names.toString).as_function();
 }
 }
 
 
@@ -327,6 +328,7 @@ void Intrinsics::visit_edges(Visitor& visitor)
     visitor.visit(m_date_constructor_now_function);
     visitor.visit(m_date_constructor_now_function);
     visitor.visit(m_eval_function);
     visitor.visit(m_eval_function);
     visitor.visit(m_json_parse_function);
     visitor.visit(m_json_parse_function);
+    visitor.visit(m_json_stringify_function);
     visitor.visit(m_object_prototype_to_string_function);
     visitor.visit(m_object_prototype_to_string_function);
     visitor.visit(m_throw_type_error_function);
     visitor.visit(m_throw_type_error_function);
 
 

+ 2 - 0
Userland/Libraries/LibJS/Runtime/Intrinsics.h

@@ -55,6 +55,7 @@ public:
     FunctionObject* array_prototype_values_function() const { return m_array_prototype_values_function; }
     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* date_constructor_now_function() const { return m_date_constructor_now_function; }
     FunctionObject* json_parse_function() const { return m_json_parse_function; }
     FunctionObject* json_parse_function() const { return m_json_parse_function; }
+    FunctionObject* json_stringify_function() const { return m_json_stringify_function; }
     FunctionObject* object_prototype_to_string_function() const { return m_object_prototype_to_string_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; }
     FunctionObject* throw_type_error_function() const { return m_throw_type_error_function; }
 
 
@@ -149,6 +150,7 @@ private:
     FunctionObject* m_array_prototype_values_function { nullptr };
     FunctionObject* m_array_prototype_values_function { nullptr };
     FunctionObject* m_date_constructor_now_function { nullptr };
     FunctionObject* m_date_constructor_now_function { nullptr };
     FunctionObject* m_json_parse_function { nullptr };
     FunctionObject* m_json_parse_function { nullptr };
+    FunctionObject* m_json_stringify_function { nullptr };
     FunctionObject* m_object_prototype_to_string_function { nullptr };
     FunctionObject* m_object_prototype_to_string_function { nullptr };
     FunctionObject* m_throw_type_error_function { nullptr };
     FunctionObject* m_throw_type_error_function { nullptr };