mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
LibJS: Turn initialize_global_object() into a regular initialize()
There's nothing special about global object initialization anymore, this can just work the same way as for any other object now.
This commit is contained in:
parent
867ad03995
commit
cfa5885855
Notes:
sideshowbarker
2024-07-17 07:39:44 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/cfa5885855 Pull-request: https://github.com/SerenityOS/serenity/pull/15057
17 changed files with 36 additions and 36 deletions
|
@ -120,10 +120,9 @@ class TestRunnerGlobalObject final : public JS::GlobalObject {
|
|||
|
||||
public:
|
||||
TestRunnerGlobalObject(JS::Realm&);
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual ~TestRunnerGlobalObject() override;
|
||||
|
||||
virtual void initialize_global_object(JS::Realm&) override;
|
||||
|
||||
private:
|
||||
JS_DECLARE_NATIVE_FUNCTION(fuzzilli);
|
||||
};
|
||||
|
@ -168,9 +167,9 @@ JS_DEFINE_NATIVE_FUNCTION(TestRunnerGlobalObject::fuzzilli)
|
|||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
void TestRunnerGlobalObject::initialize_global_object(JS::Realm& realm)
|
||||
void TestRunnerGlobalObject::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize_global_object(realm);
|
||||
Base::initialize(realm);
|
||||
define_direct_property("global", this, JS::Attribute::Enumerable);
|
||||
define_native_function(realm, "fuzzilli", fuzzilli, 2, JS::default_attributes);
|
||||
}
|
||||
|
|
|
@ -144,9 +144,10 @@ JS::ThrowCompletionOr<bool> SheetGlobalObject::internal_set(const JS::PropertyKe
|
|||
return Base::internal_set(property_name, value, receiver);
|
||||
}
|
||||
|
||||
void SheetGlobalObject::initialize_global_object(JS::Realm& realm)
|
||||
void SheetGlobalObject::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize_global_object(realm);
|
||||
Base::initialize(realm);
|
||||
|
||||
u8 attr = JS::Attribute::Configurable | JS::Attribute::Writable | JS::Attribute::Enumerable;
|
||||
define_native_function(realm, "get_real_cell_contents", get_real_cell_contents, 1, attr);
|
||||
define_native_function(realm, "set_real_cell_contents", set_real_cell_contents, 2, attr);
|
||||
|
|
|
@ -24,13 +24,12 @@ class SheetGlobalObject final : public JS::GlobalObject {
|
|||
|
||||
public:
|
||||
SheetGlobalObject(JS::Realm&, Sheet&);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual ~SheetGlobalObject() override = default;
|
||||
|
||||
virtual JS::ThrowCompletionOr<bool> internal_has_property(JS::PropertyKey const& name) const override;
|
||||
virtual JS::ThrowCompletionOr<JS::Value> internal_get(JS::PropertyKey const&, JS::Value receiver) const override;
|
||||
virtual JS::ThrowCompletionOr<bool> internal_set(JS::PropertyKey const&, JS::Value value, JS::Value receiver) override;
|
||||
virtual void initialize_global_object(JS::Realm&) override;
|
||||
|
||||
JS_DECLARE_NATIVE_FUNCTION(get_real_cell_contents);
|
||||
JS_DECLARE_NATIVE_FUNCTION(set_real_cell_contents);
|
||||
|
|
|
@ -62,7 +62,7 @@ JS_DEFINE_NATIVE_FUNCTION($262Object::create_realm)
|
|||
auto* realm_global_object = vm.heap().allocate_without_realm<GlobalObject>(*realm);
|
||||
VERIFY(realm_global_object);
|
||||
realm->set_global_object(realm_global_object, nullptr);
|
||||
realm_global_object->initialize_global_object(*realm);
|
||||
realm_global_object->initialize(*realm);
|
||||
return Value(realm_global_object->$262());
|
||||
}
|
||||
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
|
||||
namespace JS::Test262 {
|
||||
|
||||
void GlobalObject::initialize_global_object(Realm& realm)
|
||||
void GlobalObject::initialize(Realm& realm)
|
||||
{
|
||||
Base::initialize_global_object(realm);
|
||||
Base::initialize(realm);
|
||||
|
||||
m_$262 = vm().heap().allocate<$262Object>(realm, realm);
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ public:
|
|||
: JS::GlobalObject(realm)
|
||||
{
|
||||
}
|
||||
virtual void initialize_global_object(Realm&) override;
|
||||
virtual void initialize(Realm&) override;
|
||||
virtual ~GlobalObject() override = default;
|
||||
|
||||
$262Object* $262() const { return m_$262; }
|
||||
|
|
|
@ -88,8 +88,10 @@ GlobalObject::GlobalObject(Realm& realm)
|
|||
}
|
||||
|
||||
// 9.3.4 SetDefaultGlobalBindings ( realmRec ), https://tc39.es/ecma262/#sec-setdefaultglobalbindings
|
||||
void GlobalObject::initialize_global_object(Realm& realm)
|
||||
void GlobalObject::initialize(Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
|
||||
auto& vm = this->vm();
|
||||
|
||||
ensure_shape_is_unique();
|
||||
|
|
|
@ -18,8 +18,7 @@ class GlobalObject : public Object {
|
|||
|
||||
public:
|
||||
explicit GlobalObject(Realm&);
|
||||
virtual void initialize_global_object(Realm&);
|
||||
|
||||
virtual void initialize(Realm&) override;
|
||||
virtual ~GlobalObject() override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -75,7 +75,7 @@ ThrowCompletionOr<NonnullOwnPtr<ExecutionContext>> Realm::initialize_host_define
|
|||
|
||||
// 10. Let globalObj be ? SetDefaultGlobalBindings(realm).
|
||||
// 11. Create any host-defined global object properties on globalObj.
|
||||
realm->global_object().initialize_global_object(*realm);
|
||||
realm->global_object().initialize(*realm);
|
||||
|
||||
// 12. Return unused.
|
||||
return new_context;
|
||||
|
|
|
@ -64,7 +64,7 @@ ThrowCompletionOr<Object*> ShadowRealmConstructor::construct(FunctionObject& new
|
|||
// 10. Perform ? SetRealmGlobalObject(realmRec, undefined, undefined).
|
||||
auto* new_global_object = vm.heap().allocate_without_realm<GlobalObject>(*realm);
|
||||
realm->set_global_object(new_global_object, nullptr);
|
||||
new_global_object->initialize_global_object(*realm);
|
||||
new_global_object->initialize(*realm);
|
||||
|
||||
// TODO: I don't think we should have these exactly like this, that doesn't work well with how
|
||||
// we create global objects. Still, it should be possible to make a ShadowRealm with a
|
||||
|
|
|
@ -194,15 +194,14 @@ public:
|
|||
: JS::GlobalObject(realm)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual ~TestRunnerGlobalObject() override = default;
|
||||
|
||||
virtual void initialize_global_object(JS::Realm&) override;
|
||||
};
|
||||
|
||||
inline void TestRunnerGlobalObject::initialize_global_object(JS::Realm& realm)
|
||||
inline void TestRunnerGlobalObject::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize_global_object(realm);
|
||||
Base::initialize(realm);
|
||||
|
||||
define_direct_property("global", this, JS::Attribute::Enumerable);
|
||||
for (auto& entry : s_exposed_global_functions) {
|
||||
define_native_function(
|
||||
|
|
|
@ -57,9 +57,9 @@ WindowObject::WindowObject(JS::Realm& realm, HTML::Window& impl)
|
|||
impl.set_wrapper({}, *this);
|
||||
}
|
||||
|
||||
void WindowObject::initialize_global_object(JS::Realm& realm)
|
||||
void WindowObject::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize_global_object(realm);
|
||||
Base::initialize(realm);
|
||||
|
||||
Object::set_prototype(&ensure_web_prototype<WindowPrototype>("Window"));
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ class WindowObject
|
|||
|
||||
public:
|
||||
explicit WindowObject(JS::Realm&, HTML::Window&);
|
||||
virtual void initialize_global_object(JS::Realm&) override;
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual ~WindowObject() override = default;
|
||||
|
||||
HTML::Window& impl() { return *m_impl; }
|
||||
|
|
|
@ -20,9 +20,9 @@ ConsoleGlobalObject::ConsoleGlobalObject(JS::Realm& realm, Web::Bindings::Window
|
|||
{
|
||||
}
|
||||
|
||||
void ConsoleGlobalObject::initialize_global_object(JS::Realm& realm)
|
||||
void ConsoleGlobalObject::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize_global_object(realm);
|
||||
Base::initialize(realm);
|
||||
|
||||
// $0 magic variable
|
||||
define_native_accessor(realm, "$0", inspected_node_getter, nullptr, 0);
|
||||
|
|
|
@ -21,6 +21,7 @@ class ConsoleGlobalObject final : public JS::GlobalObject {
|
|||
|
||||
public:
|
||||
ConsoleGlobalObject(JS::Realm&, Web::Bindings::WindowObject&);
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual ~ConsoleGlobalObject() override = default;
|
||||
|
||||
virtual JS::ThrowCompletionOr<Object*> internal_get_prototype_of() const override;
|
||||
|
@ -35,8 +36,6 @@ public:
|
|||
virtual JS::ThrowCompletionOr<bool> internal_delete(JS::PropertyKey const& name) override;
|
||||
virtual JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> internal_own_property_keys() const override;
|
||||
|
||||
virtual void initialize_global_object(JS::Realm&) override;
|
||||
|
||||
private:
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ WebContentConsoleClient::WebContentConsoleClient(JS::Console& console, WeakPtr<J
|
|||
// It gets removed immediately after creating the interpreter in Document::interpreter().
|
||||
auto& eso = verify_cast<Web::HTML::EnvironmentSettingsObject>(*realm.host_defined());
|
||||
vm.push_execution_context(eso.realm_execution_context());
|
||||
console_global_object->initialize_global_object(realm);
|
||||
console_global_object->initialize(realm);
|
||||
vm.pop_execution_context();
|
||||
|
||||
m_console_global_object = JS::make_handle(console_global_object);
|
||||
|
|
|
@ -97,7 +97,7 @@ public:
|
|||
: GlobalObject(realm)
|
||||
{
|
||||
}
|
||||
virtual void initialize_global_object(JS::Realm&) override;
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual ~ReplObject() override = default;
|
||||
|
||||
private:
|
||||
|
@ -118,7 +118,7 @@ public:
|
|||
: JS::GlobalObject(realm)
|
||||
{
|
||||
}
|
||||
virtual void initialize_global_object(JS::Realm&) override;
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual ~ScriptObject() override = default;
|
||||
|
||||
private:
|
||||
|
@ -1301,9 +1301,10 @@ static JS::ThrowCompletionOr<JS::Value> load_json_impl(JS::VM& vm)
|
|||
return JS::JSONObject::parse_json_value(vm, json.value());
|
||||
}
|
||||
|
||||
void ReplObject::initialize_global_object(JS::Realm& realm)
|
||||
void ReplObject::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize_global_object(realm);
|
||||
Base::initialize(realm);
|
||||
|
||||
define_direct_property("global", this, JS::Attribute::Enumerable);
|
||||
u8 attr = JS::Attribute::Configurable | JS::Attribute::Writable | JS::Attribute::Enumerable;
|
||||
define_native_function(realm, "exit", exit_interpreter, 0, attr);
|
||||
|
@ -1380,9 +1381,10 @@ JS_DEFINE_NATIVE_FUNCTION(ReplObject::print)
|
|||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
void ScriptObject::initialize_global_object(JS::Realm& realm)
|
||||
void ScriptObject::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize_global_object(realm);
|
||||
Base::initialize(realm);
|
||||
|
||||
define_direct_property("global", this, JS::Attribute::Enumerable);
|
||||
u8 attr = JS::Attribute::Configurable | JS::Attribute::Writable | JS::Attribute::Enumerable;
|
||||
define_native_function(realm, "loadINI", load_ini, 1, attr);
|
||||
|
|
Loading…
Reference in a new issue