Fix preparsing from a source string that is not external.
authorager@chromium.org <ager@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 13 Jul 2010 10:29:31 +0000 (10:29 +0000)
committerager@chromium.org <ager@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 13 Jul 2010 10:29:31 +0000 (10:29 +0000)
This fixes issue 775.
Review URL: http://codereview.chromium.org/2959007

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5050 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/compiler.cc
src/scanner.cc
test/cctest/test-api.cc

index ebb9743..8218921 100755 (executable)
@@ -275,9 +275,6 @@ static Handle<SharedFunctionInfo> MakeFunctionInfo(bool is_global,
 }
 
 
-static StaticResource<SafeStringInputBuffer> safe_string_input_buffer;
-
-
 Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source,
                                              Handle<Object> script_name,
                                              int line_offset,
@@ -306,9 +303,7 @@ Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source,
     // No cache entry found. Do pre-parsing and compile the script.
     ScriptDataImpl* pre_data = input_pre_data;
     if (pre_data == NULL && source_length >= FLAG_min_preparse_length) {
-      Access<SafeStringInputBuffer> buf(&safe_string_input_buffer);
-      buf->Reset(source.location());
-      pre_data = PreParse(source, buf.value(), extension);
+      pre_data = PreParse(source, NULL, extension);
     }
 
     // Create a script object describing the script to be compiled.
index 286f515..ca0e2d8 100755 (executable)
@@ -341,8 +341,7 @@ Scanner::Scanner(ParserMode pre)
 
 void Scanner::Initialize(Handle<String> source,
                          ParserLanguage language) {
-  safe_string_input_buffer_.Reset(source.location());
-  Init(source, &safe_string_input_buffer_, 0, source->length(), language);
+  Init(source, NULL, 0, source->length(), language);
 }
 
 
@@ -357,9 +356,7 @@ void Scanner::Initialize(Handle<String> source,
                          int start_position,
                          int end_position,
                          ParserLanguage language) {
-  safe_string_input_buffer_.Reset(source.location());
-  Init(source, &safe_string_input_buffer_,
-       start_position, end_position, language);
+  Init(source, NULL, start_position, end_position, language);
 }
 
 
@@ -368,6 +365,10 @@ void Scanner::Init(Handle<String> source,
                    int start_position,
                    int end_position,
                    ParserLanguage language) {
+  // Either initialize the scanner from a character stream or from a
+  // string.
+  ASSERT(source.is_null() || stream == NULL);
+
   // Initialize the source buffer.
   if (!source.is_null() && StringShape(*source).IsExternalTwoByte()) {
     two_byte_string_buffer_.Initialize(
@@ -382,6 +383,10 @@ void Scanner::Init(Handle<String> source,
         end_position);
     source_ = &ascii_string_buffer_;
   } else {
+    if (!source.is_null()) {
+      safe_string_input_buffer_.Reset(source.location());
+      stream = &safe_string_input_buffer_;
+    }
     char_stream_buffer_.Initialize(source,
                                    stream,
                                    start_position,
index 20f8eae..7005873 100644 (file)
@@ -8612,20 +8612,31 @@ TEST(PreCompileAPIVariationsAreSame) {
   v8::HandleScope scope;
 
   const char* cstring = "function foo(a) { return a+1; }";
+
   v8::ScriptData* sd_from_cstring =
       v8::ScriptData::PreCompile(cstring, i::StrLength(cstring));
 
   TestAsciiResource* resource = new TestAsciiResource(cstring);
-  v8::ScriptData* sd_from_istring = v8::ScriptData::PreCompile(
+  v8::ScriptData* sd_from_external_string = v8::ScriptData::PreCompile(
       v8::String::NewExternal(resource));
 
-  CHECK_EQ(sd_from_cstring->Length(), sd_from_istring->Length());
+  v8::ScriptData* sd_from_string = v8::ScriptData::PreCompile(
+      v8::String::New(cstring));
+
+  CHECK_EQ(sd_from_cstring->Length(), sd_from_external_string->Length());
+  CHECK_EQ(0, memcmp(sd_from_cstring->Data(),
+                     sd_from_external_string->Data(),
+                     sd_from_cstring->Length()));
+
+  CHECK_EQ(sd_from_cstring->Length(), sd_from_string->Length());
   CHECK_EQ(0, memcmp(sd_from_cstring->Data(),
-                     sd_from_istring->Data(),
+                     sd_from_string->Data(),
                      sd_from_cstring->Length()));
 
+
   delete sd_from_cstring;
-  delete sd_from_istring;
+  delete sd_from_external_string;
+  delete sd_from_string;
 }