mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:17:34 +00:00
WebContent: Rename $0 getter and use global object instead of this
Using the global object works consistently in native accessors and native functions, so changing this for consistency.
This commit is contained in:
parent
f9c9506997
commit
3ec13fdb86
2 changed files with 13 additions and 11 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -21,8 +21,7 @@ void ConsoleGlobalObject::initialize(JS::Realm& realm)
|
||||||
{
|
{
|
||||||
Base::initialize(realm);
|
Base::initialize(realm);
|
||||||
|
|
||||||
// $0 magic variable
|
define_native_accessor(realm, "$0", $0_getter, nullptr, 0);
|
||||||
define_native_accessor(realm, "$0", inspected_node_getter, nullptr, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConsoleGlobalObject::visit_edges(Visitor& visitor)
|
void ConsoleGlobalObject::visit_edges(Visitor& visitor)
|
||||||
|
@ -92,14 +91,17 @@ JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> ConsoleGlobalObject::internal
|
||||||
return m_window_object->internal_own_property_keys();
|
return m_window_object->internal_own_property_keys();
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ConsoleGlobalObject::inspected_node_getter)
|
static JS::ThrowCompletionOr<ConsoleGlobalObject*> get_console(JS::VM& vm)
|
||||||
{
|
{
|
||||||
auto* this_object = TRY(vm.this_value().to_object(vm));
|
if (!is<ConsoleGlobalObject>(vm.get_global_object()))
|
||||||
|
|
||||||
if (!is<ConsoleGlobalObject>(this_object))
|
|
||||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "ConsoleGlobalObject");
|
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "ConsoleGlobalObject");
|
||||||
|
|
||||||
auto console_global_object = static_cast<ConsoleGlobalObject*>(this_object);
|
return static_cast<ConsoleGlobalObject*>(&vm.get_global_object());
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_DEFINE_NATIVE_FUNCTION(ConsoleGlobalObject::$0_getter)
|
||||||
|
{
|
||||||
|
auto* console_global_object = TRY(get_console(vm));
|
||||||
auto& window = *console_global_object->m_window_object;
|
auto& window = *console_global_object->m_window_object;
|
||||||
auto* inspected_node = window.associated_document().inspected_node();
|
auto* inspected_node = window.associated_document().inspected_node();
|
||||||
if (!inspected_node)
|
if (!inspected_node)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -36,8 +36,8 @@ public:
|
||||||
private:
|
private:
|
||||||
virtual void visit_edges(Visitor&) override;
|
virtual void visit_edges(Visitor&) override;
|
||||||
|
|
||||||
// Because $0 is not a nice C++ function name
|
// $0, the DOM node currently selected in the inspector
|
||||||
JS_DECLARE_NATIVE_FUNCTION(inspected_node_getter);
|
JS_DECLARE_NATIVE_FUNCTION($0_getter);
|
||||||
|
|
||||||
Web::HTML::Window* m_window_object;
|
Web::HTML::Window* m_window_object;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue