mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 06:05:07 +00:00

This Intrinsics object hangs off of a new HostDefined struct that takes the place of EnvironmentSettingsObject as the true [[HostDefined]] slot on JS::Realm objects created by LibWeb. This gets the intrinsics off of the GlobalObject, Window, similar to the previous refactor of LibJS to move the intrinsics into the Realm's [[Intrinics]] internal slot. A side effect of this change is that we cannot fully initialize a Window object until the [[HostDefined]] slot has been installed into the realm, which happens with the creation of the WindowEnvironmentSettingsObject. As such, any Window usage that has not been funned through a WindowESO will not have any cached Web prototyped or constructors, and will not have Window APIs available to javascript code. Currently this seems limited to usage of Window in the CSS parser, but a subsequent commit will clean those up to take Realm as well. However, this commit compiles so let's cut it off here :^).
35 lines
1 KiB
C++
35 lines
1 KiB
C++
/*
|
|
* Copyright (c) 2022, Andrew Kaster <akaster@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/TypeCasts.h>
|
|
#include <LibJS/Heap/GCPtr.h>
|
|
#include <LibJS/Runtime/Realm.h>
|
|
#include <LibWeb/Forward.h>
|
|
|
|
namespace Web::Bindings {
|
|
|
|
struct HostDefined : public JS::Realm::HostDefined {
|
|
HostDefined(JS::GCPtr<HTML::EnvironmentSettingsObject> eso, JS::NonnullGCPtr<Intrinsics> intrinsics)
|
|
: environment_settings_object(eso)
|
|
, intrinsics(intrinsics)
|
|
{
|
|
}
|
|
virtual ~HostDefined() override = default;
|
|
virtual void visit_edges(JS::Cell::Visitor& visitor) override;
|
|
|
|
// NOTE: Only the root execution environment in the main thread VM ever sets this to nullptr
|
|
JS::GCPtr<HTML::EnvironmentSettingsObject> environment_settings_object;
|
|
JS::NonnullGCPtr<Intrinsics> intrinsics;
|
|
};
|
|
|
|
inline HTML::EnvironmentSettingsObject& host_defined_environment_settings_object(JS::Realm& realm)
|
|
{
|
|
return *verify_cast<HostDefined>(realm.host_defined())->environment_settings_object;
|
|
}
|
|
|
|
}
|