1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 22:28:11 +00:00

WebContent: Add $_ variable to browser console

This holds the return value of the expression that was last entered into
the browser console. If that last expression returned an error of some
kind, `$_` will be `undefined`. This matches the behaviour in Firefox.
This commit is contained in:
Sam Atkins 2022-10-03 14:41:41 +01:00 committed by Linus Groh
parent 3ec13fdb86
commit c793beb0cc
3 changed files with 15 additions and 1 deletions

View file

@ -22,6 +22,7 @@ void ConsoleGlobalObject::initialize(JS::Realm& realm)
Base::initialize(realm);
define_native_accessor(realm, "$0", $0_getter, nullptr, 0);
define_native_accessor(realm, "$_", $__getter, nullptr, 0);
}
void ConsoleGlobalObject::visit_edges(Visitor& visitor)
@ -110,4 +111,10 @@ JS_DEFINE_NATIVE_FUNCTION(ConsoleGlobalObject::$0_getter)
return inspected_node;
}
JS_DEFINE_NATIVE_FUNCTION(ConsoleGlobalObject::$__getter)
{
auto* console_global_object = TRY(get_console(vm));
return console_global_object->m_most_recent_result;
}
}