}
-const AstRawString* AstValueFactory::GetOneByteString(
+AstRawString* AstValueFactory::GetOneByteStringInternal(
Vector<const uint8_t> literal) {
uint32_t hash = StringHasher::HashSequentialString<uint8_t>(
literal.start(), literal.length(), hash_seed_);
}
-const AstRawString* AstValueFactory::GetTwoByteString(
+AstRawString* AstValueFactory::GetTwoByteStringInternal(
Vector<const uint16_t> literal) {
uint32_t hash = StringHasher::HashSequentialString<uint16_t>(
literal.start(), literal.length(), hash_seed_);
const AstRawString* AstValueFactory::GetString(Handle<String> literal) {
- DisallowHeapAllocation no_gc;
- String::FlatContent content = literal->GetFlatContent();
- if (content.IsOneByte()) {
- return GetOneByteString(content.ToOneByteVector());
+ // For the FlatContent to stay valid, we shouldn't do any heap
+ // allocation. Make sure we won't try to internalize the string in GetString.
+ AstRawString* result = NULL;
+ Isolate* saved_isolate = isolate_;
+ isolate_ = NULL;
+ {
+ DisallowHeapAllocation no_gc;
+ String::FlatContent content = literal->GetFlatContent();
+ if (content.IsOneByte()) {
+ result = GetOneByteStringInternal(content.ToOneByteVector());
+ } else {
+ DCHECK(content.IsTwoByte());
+ result = GetTwoByteStringInternal(content.ToUC16Vector());
+ }
}
- DCHECK(content.IsTwoByte());
- return GetTwoByteString(content.ToUC16Vector());
+ isolate_ = saved_isolate;
+ if (isolate_) result->Internalize(isolate_);
+ return result;
}
#undef GENERATE_VALUE_GETTER
-const AstRawString* AstValueFactory::GetString(
- uint32_t hash, bool is_one_byte, Vector<const byte> literal_bytes) {
+AstRawString* AstValueFactory::GetString(uint32_t hash, bool is_one_byte,
+ Vector<const byte> literal_bytes) {
// literal_bytes here points to whatever the user passed, and this is OK
// because we use vector_compare (which checks the contents) to compare
// against the AstRawStrings which are in the string_table_. We should not
Zone* zone() const { return zone_; }
- const AstRawString* GetOneByteString(Vector<const uint8_t> literal);
+ const AstRawString* GetOneByteString(Vector<const uint8_t> literal) {
+ return GetOneByteStringInternal(literal);
+ }
const AstRawString* GetOneByteString(const char* string) {
return GetOneByteString(Vector<const uint8_t>(
reinterpret_cast<const uint8_t*>(string), StrLength(string)));
}
- const AstRawString* GetTwoByteString(Vector<const uint16_t> literal);
+ const AstRawString* GetTwoByteString(Vector<const uint16_t> literal) {
+ return GetTwoByteStringInternal(literal);
+ }
const AstRawString* GetString(Handle<String> literal);
const AstConsString* NewConsString(const AstString* left,
const AstString* right);
const AstValue* NewTheHole();
private:
- const AstRawString* GetString(uint32_t hash, bool is_one_byte,
- Vector<const byte> literal_bytes);
+ AstRawString* GetOneByteStringInternal(Vector<const uint8_t> literal);
+ AstRawString* GetTwoByteStringInternal(Vector<const uint16_t> literal);
+ AstRawString* GetString(uint32_t hash, bool is_one_byte,
+ Vector<const byte> literal_bytes);
// All strings are copied here, one after another (no NULLs inbetween).
HashMap string_table_;