Skip to content

Commit da591c3

Browse files
authored
Merge pull request #1253 from emutavchi/wpe-2.38-blob-mem-cost
Blob should report memory cost
2 parents 0ac2e6f + 55890f9 commit da591c3

3 files changed

Lines changed: 11 additions & 0 deletions

File tree

Source/WebCore/fileapi/Blob.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ Blob::Blob(ScriptExecutionContext* context, Vector<uint8_t>&& data, const String
155155
, m_type(contentType)
156156
, m_size(data.size())
157157
, m_internalURL(BlobURL::createInternalURL())
158+
, m_memoryCost(data.size())
158159
{
159160
ThreadableBlobRegistry::registerBlobURL(m_internalURL, { BlobPart(WTFMove(data)) }, contentType);
160161
}
@@ -383,4 +384,9 @@ WebCoreOpaqueRoot root(Blob* blob)
383384
return WebCoreOpaqueRoot { blob };
384385
}
385386

387+
size_t Blob::memoryCost() const
388+
{
389+
return m_memoryCost;
390+
}
391+
386392
} // namespace WebCore

Source/WebCore/fileapi/Blob.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ class Blob : public ScriptWrappable, public URLRegistrable, public RefCounted<Bl
121121
// Keeping the handle alive will keep the Blob data alive (but not the Blob object).
122122
BlobURLHandle handle() const;
123123

124+
size_t memoryCost() const;
125+
124126
protected:
125127
WEBCORE_EXPORT explicit Blob(ScriptExecutionContext*);
126128
Blob(ScriptExecutionContext&, Vector<BlobPartVariant>&&, const BlobPropertyBag&);
@@ -153,6 +155,8 @@ class Blob : public ScriptWrappable, public URLRegistrable, public RefCounted<Bl
153155
URL m_internalURL;
154156

155157
HashSet<std::unique_ptr<BlobLoader>> m_blobLoaders;
158+
159+
std::atomic<size_t> m_memoryCost { 0 };
156160
};
157161

158162
WebCoreOpaqueRoot root(Blob*);

Source/WebCore/fileapi/Blob.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ typedef (BufferSource or Blob or USVString) BlobPart;
3636
Exposed=(Window,Worker),
3737
GenerateIsReachable=Impl,
3838
CustomToJSObject,
39+
ReportExtraMemoryCost,
3940
] interface Blob {
4041
[CallWith=CurrentScriptExecutionContext] constructor(optional sequence<BlobPart> blobParts, optional BlobPropertyBag options);
4142

0 commit comments

Comments
 (0)