1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-20 20:42:06 +00:00

LibWeb: Replace usage of native properties with accessors in Navigator

This is required by the WebIDL specification.
This commit is contained in:
Idan Horowitz 2021-07-05 15:03:31 +03:00 committed by Linus Groh
parent 6468a2bf21
commit 4fdf4bfbd0
2 changed files with 4 additions and 4 deletions

View file

@ -4,7 +4,6 @@
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <AK/FlyString.h>
#include <LibJS/Runtime/Array.h> #include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
#include <LibWeb/Bindings/NavigatorObject.h> #include <LibWeb/Bindings/NavigatorObject.h>
@ -24,6 +23,7 @@ void NavigatorObject::initialize(JS::GlobalObject& global_object)
auto* languages = JS::Array::create(global_object, 0); auto* languages = JS::Array::create(global_object, 0);
languages->indexed_properties().append(js_string(heap, "en-US")); languages->indexed_properties().append(js_string(heap, "en-US"));
// FIXME: All of these should be in Navigator's prototype and be native accessors
define_property("appCodeName", js_string(heap, "Mozilla")); define_property("appCodeName", js_string(heap, "Mozilla"));
define_property("appName", js_string(heap, "Netscape")); define_property("appName", js_string(heap, "Netscape"));
define_property("appVersion", js_string(heap, "4.0")); define_property("appVersion", js_string(heap, "4.0"));
@ -32,14 +32,14 @@ void NavigatorObject::initialize(JS::GlobalObject& global_object)
define_property("platform", js_string(heap, "SerenityOS")); define_property("platform", js_string(heap, "SerenityOS"));
define_property("product", js_string(heap, "Gecko")); define_property("product", js_string(heap, "Gecko"));
define_native_property("userAgent", user_agent_getter, nullptr); define_native_accessor("userAgent", user_agent_getter, {});
} }
NavigatorObject::~NavigatorObject() NavigatorObject::~NavigatorObject()
{ {
} }
JS_DEFINE_NATIVE_GETTER(NavigatorObject::user_agent_getter) JS_DEFINE_NATIVE_FUNCTION(NavigatorObject::user_agent_getter)
{ {
return JS::js_string(vm, ResourceLoader::the().user_agent()); return JS::js_string(vm, ResourceLoader::the().user_agent());
} }

View file

@ -21,7 +21,7 @@ public:
virtual ~NavigatorObject() override; virtual ~NavigatorObject() override;
private: private:
JS_DECLARE_NATIVE_GETTER(user_agent_getter); JS_DECLARE_NATIVE_FUNCTION(user_agent_getter);
}; };
} }