Object.prototype.toString() should use cached strings for null/undefined.
[WebKit-https.git] / Source / JavaScriptCore / runtime / SmallStrings.cpp
index 54cef97..a4bdb0c 100644 (file)
@@ -67,6 +67,8 @@ SmallStrings::SmallStrings()
 #define JSC_COMMON_STRINGS_ATTRIBUTE_INITIALIZE(name) , m_##name(0)
     JSC_COMMON_STRINGS_EACH_NAME(JSC_COMMON_STRINGS_ATTRIBUTE_INITIALIZE)
 #undef JSC_COMMON_STRINGS_ATTRIBUTE_INITIALIZE
+    , m_nullObjectString(nullptr)
+    , m_undefinedObjectString(nullptr)
 {
     COMPILE_ASSERT(singleCharacterStringCount == sizeof(m_singleCharacterStrings) / sizeof(m_singleCharacterStrings[0]), IsNumCharactersConstInSyncWithClassUsage);
 
@@ -82,6 +84,8 @@ void SmallStrings::initializeCommonStrings(VM& vm)
 #define JSC_COMMON_STRINGS_ATTRIBUTE_INITIALIZE(name) initialize(&vm, m_##name, #name);
     JSC_COMMON_STRINGS_EACH_NAME(JSC_COMMON_STRINGS_ATTRIBUTE_INITIALIZE)
 #undef JSC_COMMON_STRINGS_ATTRIBUTE_INITIALIZE
+    initialize(&vm, m_nullObjectString, "[object Null]");
+    initialize(&vm, m_undefinedObjectString, "[object Undefined]");
 }
 
 void SmallStrings::visitStrongReferences(SlotVisitor& visitor)
@@ -92,6 +96,8 @@ void SmallStrings::visitStrongReferences(SlotVisitor& visitor)
 #define JSC_COMMON_STRINGS_ATTRIBUTE_VISIT(name) visitor.appendUnbarrieredPointer(&m_##name);
     JSC_COMMON_STRINGS_EACH_NAME(JSC_COMMON_STRINGS_ATTRIBUTE_VISIT)
 #undef JSC_COMMON_STRINGS_ATTRIBUTE_VISIT
+    visitor.appendUnbarrieredPointer(&m_nullObjectString);
+    visitor.appendUnbarrieredPointer(&m_undefinedObjectString);
 }
 
 SmallStrings::~SmallStrings()