diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-01-10 06:28:20 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-01-10 16:08:14 +0100 |
commit | 834202aeb9a47c544ab4e61deb813de50bc03946 (patch) | |
tree | c120e9231fa5451b527131f6e423fac2645253bb /Userland/Libraries/LibWeb/Encoding | |
parent | 7bd8fd000f3f8e92ff632be2370a279ac2309250 (diff) | |
download | serenity-834202aeb9a47c544ab4e61deb813de50bc03946.zip |
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.
Diffstat (limited to 'Userland/Libraries/LibWeb/Encoding')
4 files changed, 16 insertions, 2 deletions
diff --git a/Userland/Libraries/LibWeb/Encoding/TextDecoder.cpp b/Userland/Libraries/LibWeb/Encoding/TextDecoder.cpp index 1979ef261c..0a300d6f42 100644 --- a/Userland/Libraries/LibWeb/Encoding/TextDecoder.cpp +++ b/Userland/Libraries/LibWeb/Encoding/TextDecoder.cpp @@ -29,11 +29,16 @@ TextDecoder::TextDecoder(JS::Realm& realm, TextCodec::Decoder& decoder, Deprecat , m_fatal(fatal) , m_ignore_bom(ignore_bom) { - set_prototype(&Bindings::cached_web_prototype(realm, "TextDecoder")); } TextDecoder::~TextDecoder() = default; +void TextDecoder::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype<Bindings::TextDecoderPrototype>(realm, "TextDecoder")); +} + // https://encoding.spec.whatwg.org/#dom-textdecoder-decode WebIDL::ExceptionOr<DeprecatedString> TextDecoder::decode(JS::Handle<JS::Object> const& input) const { diff --git a/Userland/Libraries/LibWeb/Encoding/TextDecoder.h b/Userland/Libraries/LibWeb/Encoding/TextDecoder.h index 450ca2dbb5..c68447d078 100644 --- a/Userland/Libraries/LibWeb/Encoding/TextDecoder.h +++ b/Userland/Libraries/LibWeb/Encoding/TextDecoder.h @@ -35,6 +35,8 @@ private: // https://encoding.spec.whatwg.org/#dom-textdecoder TextDecoder(JS::Realm&, TextCodec::Decoder&, DeprecatedFlyString encoding, bool fatal, bool ignore_bom); + virtual void initialize(JS::Realm&) override; + TextCodec::Decoder& m_decoder; DeprecatedFlyString m_encoding; bool m_fatal { false }; diff --git a/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp b/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp index c1a44767dc..78fbd0b131 100644 --- a/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp +++ b/Userland/Libraries/LibWeb/Encoding/TextEncoder.cpp @@ -19,11 +19,16 @@ JS::NonnullGCPtr<TextEncoder> TextEncoder::construct_impl(JS::Realm& realm) TextEncoder::TextEncoder(JS::Realm& realm) : PlatformObject(realm) { - set_prototype(&Bindings::cached_web_prototype(realm, "TextEncoder")); } TextEncoder::~TextEncoder() = default; +void TextEncoder::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype<Bindings::TextEncoderPrototype>(realm, "TextEncoder")); +} + // https://encoding.spec.whatwg.org/#dom-textencoder-encode JS::Uint8Array* TextEncoder::encode(DeprecatedString const& input) const { diff --git a/Userland/Libraries/LibWeb/Encoding/TextEncoder.h b/Userland/Libraries/LibWeb/Encoding/TextEncoder.h index 02eb55d736..2da540f5d5 100644 --- a/Userland/Libraries/LibWeb/Encoding/TextEncoder.h +++ b/Userland/Libraries/LibWeb/Encoding/TextEncoder.h @@ -31,6 +31,8 @@ public: protected: // https://encoding.spec.whatwg.org/#dom-textencoder explicit TextEncoder(JS::Realm&); + + virtual void initialize(JS::Realm&) override; }; } |