Revision: 5050 Author: [email protected] Date: Tue Jul 13 03:29:31 2010 Log: Fix preparsing from a source string that is not external.
This fixes issue 775. Review URL: http://codereview.chromium.org/2959007 http://code.google.com/p/v8/source/detail?r=5050 Modified: /branches/bleeding_edge/src/compiler.cc /branches/bleeding_edge/src/scanner.cc /branches/bleeding_edge/test/cctest/test-api.cc ======================================= --- /branches/bleeding_edge/src/compiler.cc Mon Jun 7 08:39:10 2010 +++ /branches/bleeding_edge/src/compiler.cc Tue Jul 13 03:29:31 2010 @@ -273,9 +273,6 @@ return result; } - - -static StaticResource<SafeStringInputBuffer> safe_string_input_buffer; Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source, @@ -306,9 +303,7 @@ // 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. ======================================= --- /branches/bleeding_edge/src/scanner.cc Tue Jun 22 05:31:24 2010 +++ /branches/bleeding_edge/src/scanner.cc Tue Jul 13 03:29:31 2010 @@ -341,8 +341,7 @@ 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 @@ 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 @@ 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 @@ 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, ======================================= --- /branches/bleeding_edge/test/cctest/test-api.cc Mon Jul 12 06:17:27 2010 +++ /branches/bleeding_edge/test/cctest/test-api.cc Tue Jul 13 03:29:31 2010 @@ -8612,20 +8612,31 @@ 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_istring->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_string->Data(), + sd_from_cstring->Length())); + + delete sd_from_cstring; - delete sd_from_istring; + delete sd_from_external_string; + delete sd_from_string; } -- v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev
