diff options
author | davidot <davidot@serenityos.org> | 2022-01-27 14:49:55 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-01-30 17:40:20 +0000 |
commit | 202de6ed2587d9c7d5f5288c3df88eee3067d3fb (patch) | |
tree | 6eeee32d9b26966a9e1f148705f9c05660e3bbba | |
parent | f568939568b69231d5bebae8a9199ee3359e36e3 (diff) | |
download | serenity-202de6ed2587d9c7d5f5288c3df88eee3067d3fb.zip |
LibJS: Expose JSON.parse as an intrinsic value of the global object
This will allow us to safely call it if we need to parse JSON within
LibJS.
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/GlobalObject.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/GlobalObject.h | 2 |
2 files changed, 4 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp index bed7389cbe..2c50e6dafe 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp @@ -304,6 +304,7 @@ void GlobalObject::initialize_global_object() 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_eval_function = &get_without_side_effects(vm.names.eval).as_function(); + m_json_parse_function = &get_without_side_effects(vm.names.JSON).as_object().get_without_side_effects(vm.names.parse).as_function(); } GlobalObject::~GlobalObject() @@ -324,6 +325,7 @@ void GlobalObject::visit_edges(Visitor& visitor) visitor.visit(m_date_constructor_now_function); visitor.visit(m_eval_function); visitor.visit(m_throw_type_error_function); + visitor.visit(m_json_parse_function); #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ visitor.visit(m_##snake_name##_constructor); \ diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.h b/Userland/Libraries/LibJS/Runtime/GlobalObject.h index 2329ff514a..a1fa0f2a54 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalObject.h +++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.h @@ -42,6 +42,7 @@ public: FunctionObject* date_constructor_now_function() const { return m_date_constructor_now_function; } FunctionObject* eval_function() const { return m_eval_function; } FunctionObject* throw_type_error_function() const { return m_throw_type_error_function; } + FunctionObject* json_parse_function() const { return m_json_parse_function; } #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ ConstructorName* snake_name##_constructor() { return m_##snake_name##_constructor; } \ @@ -109,6 +110,7 @@ private: FunctionObject* m_date_constructor_now_function { nullptr }; FunctionObject* m_eval_function { nullptr }; FunctionObject* m_throw_type_error_function { nullptr }; + FunctionObject* m_json_parse_function { nullptr }; #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ ConstructorName* m_##snake_name##_constructor { nullptr }; \ |