#ifndef SmallStrings_h
#define SmallStrings_h
-#include "UString.h"
-#include <wtf/FixedArray.h>
+#include "WriteBarrier.h"
+#include <wtf/Noncopyable.h>
#include <wtf/OwnPtr.h>
+#define JSC_COMMON_STRINGS_EACH_NAME(macro) \
+ macro(boolean) \
+ macro(false) \
+ macro(function) \
+ macro(number) \
+ macro(null) \
+ macro(object) \
+ macro(undefined) \
+ macro(string) \
+ macro(true)
+
+namespace WTF {
+class StringImpl;
+}
+
namespace JSC {
class HeapRootVisitor;
- class JSGlobalData;
+ class VM;
class JSString;
- class MarkStack;
class SmallStringsStorage;
- typedef MarkStack SlotVisitor;
+ class SlotVisitor;
static const unsigned maxSingleCharacterString = 0xFF;
SmallStrings();
~SmallStrings();
- JSString* emptyString(JSGlobalData* globalData)
+ JSString* emptyString()
{
- if (!m_emptyString)
- createEmptyString(globalData);
return m_emptyString;
}
- JSString* singleCharacterString(JSGlobalData* globalData, unsigned char character)
+ JSString* singleCharacterString(unsigned char character)
{
- if (!m_singleCharacterStrings[character])
- createSingleCharacterString(globalData, character);
return m_singleCharacterStrings[character];
}
- StringImpl* singleCharacterStringRep(unsigned char character);
+ JS_EXPORT_PRIVATE WTF::StringImpl* singleCharacterStringRep(unsigned char character);
- void visitChildren(HeapRootVisitor&);
- void clear();
+ JSString** singleCharacterStrings() { return &m_singleCharacterStrings[0]; }
- unsigned count() const;
+ void initializeCommonStrings(VM&);
+ void visitStrongReferences(SlotVisitor&);
- JSString** singleCharacterStrings() { return &m_singleCharacterStrings[0]; }
+#define JSC_COMMON_STRINGS_ACCESSOR_DEFINITION(name) \
+ JSString* name##String() const \
+ { \
+ return m_##name; \
+ }
+ JSC_COMMON_STRINGS_EACH_NAME(JSC_COMMON_STRINGS_ACCESSOR_DEFINITION)
+#undef JSC_COMMON_STRINGS_ACCESSOR_DEFINITION
+
+ JSString* nullObjectString() const { return m_nullObjectString; }
+ JSString* undefinedObjectString() const { return m_undefinedObjectString; }
private:
static const unsigned singleCharacterStringCount = maxSingleCharacterString + 1;
- void createEmptyString(JSGlobalData*);
- void createSingleCharacterString(JSGlobalData*, unsigned char);
+ JS_EXPORT_PRIVATE void createEmptyString(VM*);
+ JS_EXPORT_PRIVATE void createSingleCharacterString(VM*, unsigned char);
+
+ void initialize(VM* vm, JSString*& string, const char* value) const;
JSString* m_emptyString;
+#define JSC_COMMON_STRINGS_ATTRIBUTE_DECLARATION(name) JSString* m_##name;
+ JSC_COMMON_STRINGS_EACH_NAME(JSC_COMMON_STRINGS_ATTRIBUTE_DECLARATION)
+#undef JSC_COMMON_STRINGS_ATTRIBUTE_DECLARATION
+ JSString* m_nullObjectString;
+ JSString* m_undefinedObjectString;
JSString* m_singleCharacterStrings[singleCharacterStringCount];
OwnPtr<SmallStringsStorage> m_storage;
};