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

Unified Diff: src/ast-value-factory.cc

Issue 699343004: Parser & internalization fix: ensure no heap allocs during GetString(Handle<String>). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month 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 | « src/ast-value-factory.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast-value-factory.cc
diff --git a/src/ast-value-factory.cc b/src/ast-value-factory.cc
index 895ce39f652845fa83674d61ec98b0c9b8f1b5e1..2a98d07105b1fd4d02d5bb5ed01eec18f6e0db75 100644
--- a/src/ast-value-factory.cc
+++ b/src/ast-value-factory.cc
@@ -229,13 +229,28 @@ const AstRawString* AstValueFactory::GetTwoByteString(
const AstRawString* AstValueFactory::GetString(Handle<String> literal) {
+ // 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()) {
- return GetOneByteString(content.ToOneByteVector());
rossberg 2014/11/05 12:39:51 I'm confused, what's the reason to inline these fu
marja 2014/11/05 12:41:41 constness. Another option would be to make these
rossberg 2014/11/05 12:46:21 Why not make the functions non-const but private,
+ Vector<const uint8_t> literal = content.ToOneByteVector();
+ uint32_t hash = StringHasher::HashSequentialString<uint8_t>(
+ literal.start(), literal.length(), hash_seed_);
+ result = GetString(hash, true, literal);
+ } else {
+ DCHECK(content.IsTwoByte());
+ Vector<const uint16_t> literal = content.ToUC16Vector();
+ uint32_t hash = StringHasher::HashSequentialString<uint16_t>(
+ literal.start(), literal.length(), hash_seed_);
+ result = GetString(hash, false, Vector<const byte>::cast(literal));
}
- DCHECK(content.IsTwoByte());
- return GetTwoByteString(content.ToUC16Vector());
+ isolate_ = saved_isolate;
+ result->string_ = literal;
+ return result;
}
@@ -348,8 +363,8 @@ const AstValue* AstValueFactory::NewTheHole() {
#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
« no previous file with comments | « src/ast-value-factory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698