From 2bbf3bbee7483b31762ed717fb387fcefa07d29a Mon Sep 17 00:00:00 2001 From: "lrn@chromium.org" Date: Mon, 17 Oct 2011 12:45:52 +0000 Subject: [PATCH] Make native syntax an early error in the preparser. Previously the preparser always accepted natives syntax and let the real parser throw the syntax error. In ES5, it should be an early error, so the preparser must catch the error. The perparser library does not expose parsing for natives syntax, it's only used internally. Review URL: http://codereview.chromium.org/8306024 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9660 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/compiler.cc | 16 ++++++++------- src/parser.cc | 22 ++++++++++---------- src/parser.h | 5 +++-- src/preparser-api.cc | 2 +- src/preparser.cc | 5 ++++- src/preparser.h | 14 +++++++++---- src/scanner.h | 11 ++++++++++ test/cctest/test-parsing.cc | 40 ++++++++++++++++++++++++++++++++++++- 8 files changed, 89 insertions(+), 26 deletions(-) diff --git a/src/compiler.cc b/src/compiler.cc index 544d1904f..3f5f009e9 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -480,20 +480,22 @@ Handle Compiler::Compile(Handle source, // that would be compiled lazily anyway, so we skip the preparse step // in that case too. ScriptDataImpl* pre_data = input_pre_data; - bool harmony_scoping = natives != NATIVES_CODE && FLAG_harmony_scoping; + int flags = kNoParsingFlags; + if ((natives == NATIVES_CODE) || FLAG_allow_natives_syntax) { + flags |= kAllowNativesSyntax; + } + if (natives != NATIVES_CODE && FLAG_harmony_scoping) { + flags |= kHarmonyScoping; + } if (pre_data == NULL && source_length >= FLAG_min_preparse_length) { if (source->IsExternalTwoByteString()) { ExternalTwoByteStringUC16CharacterStream stream( Handle::cast(source), 0, source->length()); - pre_data = ParserApi::PartialPreParse(&stream, - extension, - harmony_scoping); + pre_data = ParserApi::PartialPreParse(&stream, extension, flags); } else { GenericStringUC16CharacterStream stream(source, 0, source->length()); - pre_data = ParserApi::PartialPreParse(&stream, - extension, - harmony_scoping); + pre_data = ParserApi::PartialPreParse(&stream, extension, flags); } } diff --git a/src/parser.cc b/src/parser.cc index 0960c832c..edd2e531d 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -5217,17 +5217,16 @@ int ScriptDataImpl::ReadNumber(byte** source) { // Create a Scanner for the preparser to use as input, and preparse the source. static ScriptDataImpl* DoPreParse(UC16CharacterStream* source, - bool allow_lazy, - ParserRecorder* recorder, - bool harmony_scoping) { + int flags, + ParserRecorder* recorder) { Isolate* isolate = Isolate::Current(); JavaScriptScanner scanner(isolate->unicode_cache()); - scanner.SetHarmonyScoping(harmony_scoping); + scanner.SetHarmonyScoping((flags & kHarmonyScoping) != 0); scanner.Initialize(source); intptr_t stack_limit = isolate->stack_guard()->real_climit(); if (!preparser::PreParser::PreParseProgram(&scanner, recorder, - allow_lazy, + flags, stack_limit)) { isolate->StackOverflow(); return NULL; @@ -5244,25 +5243,28 @@ static ScriptDataImpl* DoPreParse(UC16CharacterStream* source, // even if the preparser data is only used once. ScriptDataImpl* ParserApi::PartialPreParse(UC16CharacterStream* source, v8::Extension* extension, - bool harmony_scoping) { + int flags) { bool allow_lazy = FLAG_lazy && (extension == NULL); if (!allow_lazy) { // Partial preparsing is only about lazily compiled functions. // If we don't allow lazy compilation, the log data will be empty. return NULL; } + flags |= kAllowLazy; PartialParserRecorder recorder; - return DoPreParse(source, allow_lazy, &recorder, harmony_scoping); + return DoPreParse(source, flags, &recorder); } ScriptDataImpl* ParserApi::PreParse(UC16CharacterStream* source, v8::Extension* extension, - bool harmony_scoping) { + int flags) { Handle