Fix preparsing from a source string that is not external.
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
This commit is contained in:
parent
b569e6f562
commit
ad5e73fb85
@ -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<SharedFunctionInfo> Compiler::Compile(Handle<String> source,
|
||||||
Handle<Object> script_name,
|
Handle<Object> script_name,
|
||||||
int line_offset,
|
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.
|
// No cache entry found. Do pre-parsing and compile the script.
|
||||||
ScriptDataImpl* pre_data = input_pre_data;
|
ScriptDataImpl* pre_data = input_pre_data;
|
||||||
if (pre_data == NULL && source_length >= FLAG_min_preparse_length) {
|
if (pre_data == NULL && source_length >= FLAG_min_preparse_length) {
|
||||||
Access<SafeStringInputBuffer> buf(&safe_string_input_buffer);
|
pre_data = PreParse(source, NULL, extension);
|
||||||
buf->Reset(source.location());
|
|
||||||
pre_data = PreParse(source, buf.value(), extension);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a script object describing the script to be compiled.
|
// Create a script object describing the script to be compiled.
|
||||||
|
@ -341,8 +341,7 @@ Scanner::Scanner(ParserMode pre)
|
|||||||
|
|
||||||
void Scanner::Initialize(Handle<String> source,
|
void Scanner::Initialize(Handle<String> source,
|
||||||
ParserLanguage language) {
|
ParserLanguage language) {
|
||||||
safe_string_input_buffer_.Reset(source.location());
|
Init(source, NULL, 0, source->length(), language);
|
||||||
Init(source, &safe_string_input_buffer_, 0, source->length(), language);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -357,9 +356,7 @@ void Scanner::Initialize(Handle<String> source,
|
|||||||
int start_position,
|
int start_position,
|
||||||
int end_position,
|
int end_position,
|
||||||
ParserLanguage language) {
|
ParserLanguage language) {
|
||||||
safe_string_input_buffer_.Reset(source.location());
|
Init(source, NULL, start_position, end_position, language);
|
||||||
Init(source, &safe_string_input_buffer_,
|
|
||||||
start_position, end_position, language);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -368,6 +365,10 @@ void Scanner::Init(Handle<String> source,
|
|||||||
int start_position,
|
int start_position,
|
||||||
int end_position,
|
int end_position,
|
||||||
ParserLanguage language) {
|
ParserLanguage language) {
|
||||||
|
// Either initialize the scanner from a character stream or from a
|
||||||
|
// string.
|
||||||
|
ASSERT(source.is_null() || stream == NULL);
|
||||||
|
|
||||||
// Initialize the source buffer.
|
// Initialize the source buffer.
|
||||||
if (!source.is_null() && StringShape(*source).IsExternalTwoByte()) {
|
if (!source.is_null() && StringShape(*source).IsExternalTwoByte()) {
|
||||||
two_byte_string_buffer_.Initialize(
|
two_byte_string_buffer_.Initialize(
|
||||||
@ -382,6 +383,10 @@ void Scanner::Init(Handle<String> source,
|
|||||||
end_position);
|
end_position);
|
||||||
source_ = &ascii_string_buffer_;
|
source_ = &ascii_string_buffer_;
|
||||||
} else {
|
} else {
|
||||||
|
if (!source.is_null()) {
|
||||||
|
safe_string_input_buffer_.Reset(source.location());
|
||||||
|
stream = &safe_string_input_buffer_;
|
||||||
|
}
|
||||||
char_stream_buffer_.Initialize(source,
|
char_stream_buffer_.Initialize(source,
|
||||||
stream,
|
stream,
|
||||||
start_position,
|
start_position,
|
||||||
|
@ -8612,20 +8612,31 @@ TEST(PreCompileAPIVariationsAreSame) {
|
|||||||
v8::HandleScope scope;
|
v8::HandleScope scope;
|
||||||
|
|
||||||
const char* cstring = "function foo(a) { return a+1; }";
|
const char* cstring = "function foo(a) { return a+1; }";
|
||||||
|
|
||||||
v8::ScriptData* sd_from_cstring =
|
v8::ScriptData* sd_from_cstring =
|
||||||
v8::ScriptData::PreCompile(cstring, i::StrLength(cstring));
|
v8::ScriptData::PreCompile(cstring, i::StrLength(cstring));
|
||||||
|
|
||||||
TestAsciiResource* resource = new TestAsciiResource(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));
|
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(),
|
CHECK_EQ(0, memcmp(sd_from_cstring->Data(),
|
||||||
sd_from_istring->Data(),
|
sd_from_external_string->Data(),
|
||||||
sd_from_cstring->Length()));
|
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_cstring;
|
||||||
delete sd_from_istring;
|
delete sd_from_external_string;
|
||||||
|
delete sd_from_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user