1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 14:17:36 +00:00

WebContent: Implement ConsoleGlobalObject which proxies to WindowObject

ConsoleGlobalObject is used as the global object when running javascript
from the Browser console. This lets us implement console-only functions
and variables (like `$0`) without exposing them to webpage content. It
passes other calls over to the usual WindowObject so any code that would
have worked in the webpage will still work in the console. :^)
This commit is contained in:
Sam Atkins 2021-09-03 10:16:36 +01:00 committed by Andreas Kling
parent ca2c129923
commit 7838eab341
8 changed files with 156 additions and 10 deletions

View file

@ -0,0 +1,43 @@
/*
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibJS/Forward.h>
#include <LibJS/Runtime/GlobalObject.h>
namespace Web::Bindings {
class WindowObject;
}
namespace WebContent {
class ConsoleGlobalObject final : public JS::GlobalObject {
JS_OBJECT(ConsoleGlobalObject, JS::GlobalObject);
public:
ConsoleGlobalObject(Web::Bindings::WindowObject&);
virtual ~ConsoleGlobalObject() override;
virtual Object* internal_get_prototype_of() const override;
virtual bool internal_set_prototype_of(Object* prototype) override;
virtual bool internal_is_extensible() const override;
virtual bool internal_prevent_extensions() override;
virtual Optional<JS::PropertyDescriptor> internal_get_own_property(JS::PropertyName const& name) const override;
virtual bool internal_define_own_property(JS::PropertyName const& name, JS::PropertyDescriptor const& descriptor) override;
virtual bool internal_has_property(JS::PropertyName const& name) const override;
virtual JS::Value internal_get(JS::PropertyName const&, JS::Value) const override;
virtual bool internal_set(JS::PropertyName const&, JS::Value value, JS::Value receiver) override;
virtual bool internal_delete(JS::PropertyName const& name) override;
virtual JS::MarkedValueList internal_own_property_keys() const override;
private:
virtual void visit_edges(Visitor&) override;
Web::Bindings::WindowObject* m_window_object;
};
}