Web Inspector: Add memoryCost to Inspector Protocol objects
https://bugs.webkit.org/show_bug.cgi?id=174478
Reviewed by Joseph Pecoraro.
Source/JavaScriptCore:
For non-array and non-object InspectorValue, calculate memoryCost as the sizeof the object,
plus the memoryCost of the data if it is a string.
For array InspectorValue, calculate memoryCost as the sum of the memoryCost of all items.
For object InspectorValue, calculate memoryCost as the sum of the memoryCost of the string
key plus the memoryCost of the InspectorValue for each entry.
Test: TestWebKitAPI/Tests/JavaScriptCore/InspectorValue.cpp
* inspector/InspectorValues.h:
* inspector/InspectorValues.cpp:
(Inspector::InspectorValue::memoryCost):
(Inspector::InspectorObjectBase::memoryCost):
(Inspector::InspectorArrayBase::memoryCost):
Tools:
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/JavaScriptCore/InspectorValue.cpp: Added.
(TestWebKitAPI::TEST(InspectorValue, MemoryCostNull)):
(TestWebKitAPI::TEST(InspectorValue, MemoryCostBoolean)):
(TestWebKitAPI::TEST(InspectorValue, MemoryCostDouble)):
(TestWebKitAPI::TEST(InspectorValue, MemoryCostInteger)):
(TestWebKitAPI::TEST(InspectorValue, MemoryCostString)):
(TestWebKitAPI::TEST(InspectorValue, MemoryCostStringEmpty)):
(TestWebKitAPI::TEST(InspectorValue, MemoryCostStringNull)):
(TestWebKitAPI::TEST(InspectorValue, MemoryCostStringGrowing)):
(TestWebKitAPI::TEST(InspectorValue, MemoryCostStringUnicode)):
(TestWebKitAPI::TEST(InspectorValue, MemoryCostObject)):
(TestWebKitAPI::TEST(InspectorValue, MemoryCostObjectEmpty)):
(TestWebKitAPI::TEST(InspectorValue, MemoryCostObjectGrowing)):
(TestWebKitAPI::TEST(InspectorValue, MemoryCostArray)):
(TestWebKitAPI::TEST(InspectorValue, MemoryCostArrayEmpty)):
(TestWebKitAPI::TEST(InspectorValue, MemoryCostArrayGrowing)):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@219624 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/inspector/InspectorValues.h b/Source/JavaScriptCore/inspector/InspectorValues.h
index 6687bba..a1fc743 100644
--- a/Source/JavaScriptCore/inspector/InspectorValues.h
+++ b/Source/JavaScriptCore/inspector/InspectorValues.h
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2009 Google Inc. All rights reserved.
* Copyright (C) 2014 University of Washington. All rights reserved.
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -108,6 +109,8 @@
String toJSONString() const;
virtual void writeJSON(StringBuilder& output) const;
+ virtual size_t memoryCost() const;
+
protected:
InspectorValue()
: m_type(Type::Null) { }
@@ -169,6 +172,8 @@
InspectorObject* openAccessors();
+ size_t memoryCost() const final;
+
protected:
virtual ~InspectorObjectBase();
@@ -235,6 +240,7 @@
using InspectorObjectBase::asObject;
+ // This class expected non-cyclic values, as we cannot serialize cycles in JSON.
using InspectorObjectBase::setBoolean;
using InspectorObjectBase::setInteger;
using InspectorObjectBase::setDouble;
@@ -268,6 +274,8 @@
unsigned length() const { return static_cast<unsigned>(m_map.size()); }
+ size_t memoryCost() const final;
+
protected:
virtual ~InspectorArrayBase();
@@ -303,6 +311,7 @@
using InspectorArrayBase::asArray;
+ // This class expected non-cyclic values, as we cannot serialize cycles in JSON.
using InspectorArrayBase::pushBoolean;
using InspectorArrayBase::pushInteger;
using InspectorArrayBase::pushDouble;