1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 10:17:34 +00:00

LibWeb: Move setting of Web object prototypes to initialize()

This needs to happen before prototype/constructor intitialization can be
made lazy. Otherwise, GC could run during the C++ constructor and try to
collect the object currently being created.
This commit is contained in:
Timothy Flynn 2023-01-10 06:28:20 -05:00 committed by Andreas Kling
parent 7bd8fd000f
commit 834202aeb9
339 changed files with 1294 additions and 187 deletions

View file

@ -22,7 +22,6 @@ JS::NonnullGCPtr<Crypto> Crypto::create(JS::Realm& realm)
Crypto::Crypto(JS::Realm& realm)
: PlatformObject(realm)
{
set_prototype(&Bindings::cached_web_prototype(realm, "Crypto"));
}
Crypto::~Crypto() = default;
@ -30,6 +29,7 @@ Crypto::~Crypto() = default;
void Crypto::initialize(JS::Realm& realm)
{
Base::initialize(realm);
set_prototype(&Bindings::ensure_web_prototype<Bindings::CryptoPrototype>(realm, "Crypto"));
m_subtle = SubtleCrypto::create(realm);
}

View file

@ -26,11 +26,11 @@ public:
DeprecatedString random_uuid() const;
protected:
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
private:
explicit Crypto(JS::Realm&);
virtual void initialize(JS::Realm&) override;
JS::GCPtr<SubtleCrypto> m_subtle;
};

View file

@ -22,11 +22,16 @@ JS::NonnullGCPtr<SubtleCrypto> SubtleCrypto::create(JS::Realm& realm)
SubtleCrypto::SubtleCrypto(JS::Realm& realm)
: PlatformObject(realm)
{
set_prototype(&Bindings::cached_web_prototype(realm, "SubtleCrypto"));
}
SubtleCrypto::~SubtleCrypto() = default;
void SubtleCrypto::initialize(JS::Realm& realm)
{
Base::initialize(realm);
set_prototype(&Bindings::ensure_web_prototype<Bindings::SubtleCryptoPrototype>(realm, "SubtleCrypto"));
}
// https://w3c.github.io/webcrypto/#dfn-SubtleCrypto-method-digest
JS::Promise* SubtleCrypto::digest(DeprecatedString const& algorithm, JS::Handle<JS::Object> const& data)
{

View file

@ -23,6 +23,7 @@ public:
private:
explicit SubtleCrypto(JS::Realm&);
virtual void initialize(JS::Realm&) override;
};
}