mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:37:36 +00:00
LibJS+LibWeb: Replace GlobalObject with Realm in initialize() functions
This is a continuation of the previous commit. Calling initialize() is the first thing that's done after allocating a cell on the JS heap - and in the common case of allocating an object, that's where properties are assigned and intrinsics occasionally accessed. Since those are supposed to live on the realm eventually, this is another step into that direction.
This commit is contained in:
parent
ecd163bdf1
commit
5dd5896588
304 changed files with 608 additions and 603 deletions
|
@ -19,11 +19,11 @@ AudioConstructor::AudioConstructor(JS::Realm& realm)
|
|||
{
|
||||
}
|
||||
|
||||
void AudioConstructor::initialize(JS::GlobalObject& global_object)
|
||||
void AudioConstructor::initialize(JS::Realm& realm)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& window = static_cast<WindowObject&>(global_object);
|
||||
NativeFunction::initialize(global_object);
|
||||
auto& window = static_cast<WindowObject&>(realm.global_object());
|
||||
NativeFunction::initialize(realm);
|
||||
|
||||
define_direct_property(vm.names.prototype, &window.ensure_web_prototype<HTMLAudioElementPrototype>("HTMLAudioElement"), 0);
|
||||
define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Web::Bindings {
|
|||
class AudioConstructor final : public JS::NativeFunction {
|
||||
public:
|
||||
explicit AudioConstructor(JS::Realm&);
|
||||
virtual void initialize(JS::GlobalObject&) override;
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual ~AudioConstructor() override = default;
|
||||
|
||||
virtual JS::ThrowCompletionOr<JS::Value> call() override;
|
||||
|
|
|
@ -18,9 +18,9 @@ CSSNamespace::CSSNamespace(JS::Realm& realm)
|
|||
{
|
||||
}
|
||||
|
||||
void CSSNamespace::initialize(JS::GlobalObject& global_object)
|
||||
void CSSNamespace::initialize(JS::Realm& realm)
|
||||
{
|
||||
Object::initialize(global_object);
|
||||
Object::initialize(realm);
|
||||
u8 attr = JS::Attribute::Enumerable;
|
||||
define_native_function("escape", escape, 1, attr);
|
||||
define_native_function("supports", supports, 2, attr);
|
||||
|
|
|
@ -17,7 +17,7 @@ class CSSNamespace final : public JS::Object {
|
|||
|
||||
public:
|
||||
explicit CSSNamespace(JS::Realm&);
|
||||
virtual void initialize(JS::GlobalObject&) override;
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual ~CSSNamespace() override = default;
|
||||
|
||||
private:
|
||||
|
|
|
@ -19,11 +19,11 @@ ImageConstructor::ImageConstructor(JS::Realm& realm)
|
|||
{
|
||||
}
|
||||
|
||||
void ImageConstructor::initialize(JS::GlobalObject& global_object)
|
||||
void ImageConstructor::initialize(JS::Realm& realm)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& window = static_cast<WindowObject&>(global_object);
|
||||
NativeFunction::initialize(global_object);
|
||||
auto& window = static_cast<WindowObject&>(realm.global_object());
|
||||
NativeFunction::initialize(realm);
|
||||
|
||||
define_direct_property(vm.names.prototype, &window.ensure_web_prototype<HTMLImageElementPrototype>("HTMLImageElement"), 0);
|
||||
define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Web::Bindings {
|
|||
class ImageConstructor final : public JS::NativeFunction {
|
||||
public:
|
||||
explicit ImageConstructor(JS::Realm&);
|
||||
virtual void initialize(JS::GlobalObject&) override;
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual ~ImageConstructor() override = default;
|
||||
|
||||
virtual JS::ThrowCompletionOr<JS::Value> call() override;
|
||||
|
|
|
@ -28,12 +28,12 @@ JS::ThrowCompletionOr<JS::Object*> LocationConstructor::construct(FunctionObject
|
|||
return vm().throw_completion<JS::TypeError>(global_object(), JS::ErrorType::NotAConstructor, "Location");
|
||||
}
|
||||
|
||||
void LocationConstructor::initialize(JS::GlobalObject& global_object)
|
||||
void LocationConstructor::initialize(JS::Realm& realm)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& window = static_cast<WindowObject&>(global_object);
|
||||
auto& window = static_cast<WindowObject&>(realm.global_object());
|
||||
|
||||
NativeFunction::initialize(global_object);
|
||||
NativeFunction::initialize(realm);
|
||||
define_direct_property(vm.names.prototype, &window.ensure_web_prototype<LocationPrototype>("Location"), 0);
|
||||
define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ class LocationConstructor : public JS::NativeFunction {
|
|||
|
||||
public:
|
||||
explicit LocationConstructor(JS::Realm&);
|
||||
virtual void initialize(JS::GlobalObject&) override;
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual ~LocationConstructor() override;
|
||||
|
||||
virtual JS::ThrowCompletionOr<JS::Value> call() override;
|
||||
|
|
|
@ -29,11 +29,11 @@ LocationObject::LocationObject(JS::Realm& realm)
|
|||
{
|
||||
}
|
||||
|
||||
void LocationObject::initialize(JS::GlobalObject& global_object)
|
||||
void LocationObject::initialize(JS::Realm& realm)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
auto& vm = this->vm();
|
||||
|
||||
Object::initialize(global_object);
|
||||
Object::initialize(realm);
|
||||
u8 attr = JS::Attribute::Writable | JS::Attribute::Enumerable;
|
||||
define_native_accessor("href", href_getter, href_setter, attr);
|
||||
define_native_accessor("host", host_getter, {}, attr);
|
||||
|
|
|
@ -22,7 +22,7 @@ class LocationObject final : public JS::Object {
|
|||
|
||||
public:
|
||||
explicit LocationObject(JS::Realm&);
|
||||
virtual void initialize(JS::GlobalObject&) override;
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual ~LocationObject() override = default;
|
||||
|
||||
virtual JS::ThrowCompletionOr<JS::Object*> internal_get_prototype_of() const override;
|
||||
|
|
|
@ -28,12 +28,12 @@ JS::ThrowCompletionOr<JS::Object*> NavigatorConstructor::construct(FunctionObjec
|
|||
return vm().throw_completion<JS::TypeError>(global_object(), JS::ErrorType::NotAConstructor, "Navigator");
|
||||
}
|
||||
|
||||
void NavigatorConstructor::initialize(JS::GlobalObject& global_object)
|
||||
void NavigatorConstructor::initialize(JS::Realm& realm)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& window = static_cast<WindowObject&>(global_object);
|
||||
auto& window = static_cast<WindowObject&>(realm.global_object());
|
||||
|
||||
NativeFunction::initialize(global_object);
|
||||
NativeFunction::initialize(realm);
|
||||
define_direct_property(vm.names.prototype, &window.ensure_web_prototype<NavigatorPrototype>("Navigator"), 0);
|
||||
define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ class NavigatorConstructor : public JS::NativeFunction {
|
|||
|
||||
public:
|
||||
explicit NavigatorConstructor(JS::Realm&);
|
||||
virtual void initialize(JS::GlobalObject&) override;
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual ~NavigatorConstructor() override;
|
||||
|
||||
virtual JS::ThrowCompletionOr<JS::Value> call() override;
|
||||
|
|
|
@ -18,10 +18,10 @@ NavigatorObject::NavigatorObject(JS::Realm& realm)
|
|||
{
|
||||
}
|
||||
|
||||
void NavigatorObject::initialize(JS::GlobalObject& global_object)
|
||||
void NavigatorObject::initialize(JS::Realm& realm)
|
||||
{
|
||||
auto& heap = this->heap();
|
||||
auto* languages = MUST(JS::Array::create(global_object, 0));
|
||||
auto* languages = MUST(JS::Array::create(realm.global_object(), 0));
|
||||
languages->indexed_properties().append(js_string(heap, "en-US"));
|
||||
|
||||
// FIXME: All of these should be in Navigator's prototype and be native accessors
|
||||
|
|
|
@ -17,7 +17,7 @@ class NavigatorObject final : public JS::Object {
|
|||
|
||||
public:
|
||||
NavigatorObject(JS::Realm&);
|
||||
virtual void initialize(JS::GlobalObject&) override;
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual ~NavigatorObject() override = default;
|
||||
|
||||
private:
|
||||
|
|
|
@ -20,11 +20,11 @@ OptionConstructor::OptionConstructor(JS::Realm& realm)
|
|||
{
|
||||
}
|
||||
|
||||
void OptionConstructor::initialize(JS::GlobalObject& global_object)
|
||||
void OptionConstructor::initialize(JS::Realm& realm)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& window = static_cast<WindowObject&>(global_object);
|
||||
NativeFunction::initialize(global_object);
|
||||
auto& window = static_cast<WindowObject&>(realm.global_object());
|
||||
NativeFunction::initialize(realm);
|
||||
|
||||
define_direct_property(vm.names.prototype, &window.ensure_web_prototype<HTMLOptionElementPrototype>("HTMLOptionElement"), 0);
|
||||
define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Web::Bindings {
|
|||
class OptionConstructor final : public JS::NativeFunction {
|
||||
public:
|
||||
explicit OptionConstructor(JS::Realm&);
|
||||
virtual void initialize(JS::GlobalObject&) override;
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual ~OptionConstructor() override = default;
|
||||
|
||||
virtual JS::ThrowCompletionOr<JS::Value> call() override;
|
||||
|
|
|
@ -28,12 +28,12 @@ JS::ThrowCompletionOr<JS::Object*> WindowConstructor::construct(FunctionObject&)
|
|||
return vm().throw_completion<JS::TypeError>(global_object(), JS::ErrorType::NotAConstructor, "Window");
|
||||
}
|
||||
|
||||
void WindowConstructor::initialize(JS::GlobalObject& global_object)
|
||||
void WindowConstructor::initialize(JS::Realm& realm)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& window = static_cast<WindowObject&>(global_object);
|
||||
auto& window = static_cast<WindowObject&>(realm.global_object());
|
||||
|
||||
NativeFunction::initialize(global_object);
|
||||
NativeFunction::initialize(realm);
|
||||
define_direct_property(vm.names.prototype, &window.ensure_web_prototype<WindowPrototype>("Window"), 0);
|
||||
define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ class WindowConstructor : public JS::NativeFunction {
|
|||
|
||||
public:
|
||||
explicit WindowConstructor(JS::Realm&);
|
||||
virtual void initialize(JS::GlobalObject&) override;
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual ~WindowConstructor() override;
|
||||
|
||||
virtual JS::ThrowCompletionOr<JS::Value> call() override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue