Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Unified Diff: test/cctest/test-inobject-slack-tracking.cc

Issue 2650593002: [test] Check object literal backing store size. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-inobject-slack-tracking.cc
diff --git a/test/cctest/test-inobject-slack-tracking.cc b/test/cctest/test-inobject-slack-tracking.cc
index 3c46fbee065cd08f1431aff7a9867c9aef9cc4a0..23e12e7249e513456827b516670fd4e44c8fbc75 100644
--- a/test/cctest/test-inobject-slack-tracking.cc
+++ b/test/cctest/test-inobject-slack-tracking.cc
@@ -724,6 +724,112 @@ TEST(InobjectPropetiesCountOverflowInSubclass) {
TestClassHierarchy(hierarchy_desc, kNoOverflowCount);
}
+static void CheckExpectedProperties(int expected, std::ostringstream& os) {
+ Handle<HeapObject> obj = Handle<HeapObject>::cast(
+ v8::Utils::OpenHandle(*CompileRun(os.str().c_str())));
+ CHECK_EQ(expected, obj->map()->GetInObjectProperties());
+}
+
+TEST(ObjectLiteralPropertyBackingStoreSize) {
+ v8::HandleScope scope(CcTest::isolate());
+ LocalContext env;
+
+ std::ostringstream os;
+
+ // An index key does not require space in the property backing store.
+ os << "(function() {\n"
+ " function f() {\n"
+ " var o = {\n"
+ " '-1': 42,\n" // Allocate for non-index key.
+ " 1: 42,\n" // Do not allocate for index key.
+ " '2': 42\n" // Do not allocate for index key.
+ " };\n"
+ " return o;\n"
+ " }\n"
+ "\n"
+ " return f();\n"
+ "} )();";
+ CheckExpectedProperties(1, os);
+
+ // Avoid over-/under-allocation for computed property names.
+ os << "(function() {\n"
+ " function f(x) {\n"
+ " var o = {\n"
+ " 1: 42,\n" // Do not allocate for index key.
+ " '2': 42,\n" // Do not allocate for index key.
+ " [x]: 42,\n" // Allocate for property with computed name.
+ " 3: 42\n" // Allocate for index key because we have seen a
+ // computed property.
+ " };\n"
+ " return o;\n"
+ " }\n"
+ "\n"
+ " var x = 'hello'\n"
+ "\n"
+ " return f(x);\n"
+ "} )();";
+ CheckExpectedProperties(2, os);
+
+ os << "(function() {\n"
+ " function f() {\n"
+ " var o = {};\n"
+ " return o;\n"
+ " }\n"
+ "\n"
+ " return f();\n"
+ "} )();";
+ // Empty objects have slack for 4 properties.
+ CheckExpectedProperties(4, os);
+
+ os << "(function() {\n"
+ " function f(x) {\n"
+ " var o = {\n"
+ " a: 42,\n" // Allocate for constant property.
+ " [x]: 42,\n" // Allocate for property with computed name.
+ " b: 42\n" // Allocate for constant property.
+ " };\n"
+ " return o;\n"
+ " }\n"
+ "\n"
+ " var x = 'hello'\n"
+ "\n"
+ " return f(x);\n"
+ "} )();";
+ CheckExpectedProperties(3, os);
+
+ os << "(function() {\n"
+ " function f(x) {\n"
+ " var o = {\n"
+ " a: 42,\n" // Allocate for constant property.
+ " __proto__: 42,\n" // Do not allocate for __proto__.
+ " [x]: 42\n" // Allocate for property with computed name.
+ " };\n"
+ " return o;\n"
+ " }\n"
+ "\n"
+ " var x = 'hello'\n"
+ "\n"
+ " return f(x);\n"
+ "} )();";
+ // __proto__ is not allocated in the backing store.
+ CheckExpectedProperties(2, os);
+
+ os << "(function() {\n"
+ " function f(x) {\n"
+ " var o = {\n"
+ " a: 42,\n" // Allocate for constant property.
+ " [x]: 42,\n" // Allocate for property with computed name.
+ " __proto__: 42\n" // Do not allocate for __proto__.
+ " };\n"
+ " return o;\n"
+ " }\n"
+ "\n"
+ " var x = 'hello'\n"
+ "\n"
+ " return f(x);\n"
+ "} )();";
+ CheckExpectedProperties(2, os);
+}
TEST(SlowModeSubclass) {
// Avoid eventual completion of in-object slack tracking.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698