summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/FileAPI
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-01-10 06:28:20 -0500
committerAndreas Kling <kling@serenityos.org>2023-01-10 16:08:14 +0100
commit834202aeb9a47c544ab4e61deb813de50bc03946 (patch)
treec120e9231fa5451b527131f6e423fac2645253bb /Userland/Libraries/LibWeb/FileAPI
parent7bd8fd000f3f8e92ff632be2370a279ac2309250 (diff)
downloadserenity-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/FileAPI')
-rw-r--r--Userland/Libraries/LibWeb/FileAPI/Blob.cpp9
-rw-r--r--Userland/Libraries/LibWeb/FileAPI/Blob.h2
-rw-r--r--Userland/Libraries/LibWeb/FileAPI/File.cpp7
-rw-r--r--Userland/Libraries/LibWeb/FileAPI/File.h2
4 files changed, 16 insertions, 4 deletions
diff --git a/Userland/Libraries/LibWeb/FileAPI/Blob.cpp b/Userland/Libraries/LibWeb/FileAPI/Blob.cpp
index d2d19a093d..6a76a7cbd4 100644
--- a/Userland/Libraries/LibWeb/FileAPI/Blob.cpp
+++ b/Userland/Libraries/LibWeb/FileAPI/Blob.cpp
@@ -115,7 +115,6 @@ bool is_basic_latin(StringView view)
Blob::Blob(JS::Realm& realm)
: PlatformObject(realm)
{
- set_prototype(&Bindings::cached_web_prototype(realm, "Blob"));
}
Blob::Blob(JS::Realm& realm, ByteBuffer byte_buffer, DeprecatedString type)
@@ -123,18 +122,22 @@ Blob::Blob(JS::Realm& realm, ByteBuffer byte_buffer, DeprecatedString type)
, m_byte_buffer(move(byte_buffer))
, m_type(move(type))
{
- set_prototype(&Bindings::cached_web_prototype(realm, "Blob"));
}
Blob::Blob(JS::Realm& realm, ByteBuffer byte_buffer)
: PlatformObject(realm)
, m_byte_buffer(move(byte_buffer))
{
- set_prototype(&Bindings::cached_web_prototype(realm, "Blob"));
}
Blob::~Blob() = default;
+void Blob::initialize(JS::Realm& realm)
+{
+ Base::initialize(realm);
+ set_prototype(&Bindings::ensure_web_prototype<Bindings::BlobPrototype>(realm, "Blob"));
+}
+
// https://w3c.github.io/FileAPI/#ref-for-dom-blob-blob
WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> Blob::create(JS::Realm& realm, Optional<Vector<BlobPart>> const& blob_parts, Optional<BlobPropertyBag> const& options)
{
diff --git a/Userland/Libraries/LibWeb/FileAPI/Blob.h b/Userland/Libraries/LibWeb/FileAPI/Blob.h
index 7a7150994b..f3d482eb0a 100644
--- a/Userland/Libraries/LibWeb/FileAPI/Blob.h
+++ b/Userland/Libraries/LibWeb/FileAPI/Blob.h
@@ -53,6 +53,8 @@ protected:
Blob(JS::Realm&, ByteBuffer, DeprecatedString type);
Blob(JS::Realm&, ByteBuffer);
+ virtual void initialize(JS::Realm&) override;
+
private:
explicit Blob(JS::Realm&);
diff --git a/Userland/Libraries/LibWeb/FileAPI/File.cpp b/Userland/Libraries/LibWeb/FileAPI/File.cpp
index 5435b82abe..bd1c68ba9b 100644
--- a/Userland/Libraries/LibWeb/FileAPI/File.cpp
+++ b/Userland/Libraries/LibWeb/FileAPI/File.cpp
@@ -16,7 +16,12 @@ File::File(JS::Realm& realm, ByteBuffer byte_buffer, DeprecatedString file_name,
, m_name(move(file_name))
, m_last_modified(last_modified)
{
- set_prototype(&Bindings::cached_web_prototype(realm, "File"));
+}
+
+void File::initialize(JS::Realm& realm)
+{
+ Base::initialize(realm);
+ set_prototype(&Bindings::ensure_web_prototype<Bindings::FilePrototype>(realm, "File"));
}
File::~File() = default;
diff --git a/Userland/Libraries/LibWeb/FileAPI/File.h b/Userland/Libraries/LibWeb/FileAPI/File.h
index da43c79a7d..143f61ac3d 100644
--- a/Userland/Libraries/LibWeb/FileAPI/File.h
+++ b/Userland/Libraries/LibWeb/FileAPI/File.h
@@ -31,6 +31,8 @@ public:
private:
File(JS::Realm&, ByteBuffer, DeprecatedString file_name, DeprecatedString type, i64 last_modified);
+ virtual void initialize(JS::Realm&) override;
+
DeprecatedString m_name;
i64 m_last_modified { 0 };
};