Commit fc3bdf4d authored by lrn@chromium.org's avatar lrn@chromium.org

Preparsing now considers catch-blocks as inside a with.

Fix issue 928.

Review URL: http://codereview.chromium.org/4639005

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5813 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 582a3bde
...@@ -132,7 +132,7 @@ class ScriptDataImpl : public ScriptData { ...@@ -132,7 +132,7 @@ class ScriptDataImpl : public ScriptData {
unsigned version() { return store_[kVersionOffset]; } unsigned version() { return store_[kVersionOffset]; }
static const unsigned kMagicNumber = 0xBadDead; static const unsigned kMagicNumber = 0xBadDead;
static const unsigned kCurrentVersion = 4; static const unsigned kCurrentVersion = 5;
static const int kMagicOffset = 0; static const int kMagicOffset = 0;
static const int kVersionOffset = 1; static const int kVersionOffset = 1;
......
...@@ -750,15 +750,18 @@ Statement PreParser<Scanner, Log>::ParseTryStatement(bool* ok) { ...@@ -750,15 +750,18 @@ Statement PreParser<Scanner, Log>::ParseTryStatement(bool* ok) {
bool catch_or_finally_seen = false; bool catch_or_finally_seen = false;
if (peek() == i::Token::CATCH) { if (peek() == i::Token::CATCH) {
Expect(i::Token::CATCH, CHECK_OK); Consume(i::Token::CATCH);
Expect(i::Token::LPAREN, CHECK_OK); Expect(i::Token::LPAREN, CHECK_OK);
ParseIdentifier(CHECK_OK); ParseIdentifier(CHECK_OK);
Expect(i::Token::RPAREN, CHECK_OK); Expect(i::Token::RPAREN, CHECK_OK);
ParseBlock(CHECK_OK); scope_->EnterWith();
ParseBlock(ok);
scope_->LeaveWith();
if (!*ok) return kUnknownStatement;
catch_or_finally_seen = true; catch_or_finally_seen = true;
} }
if (peek() == i::Token::FINALLY) { if (peek() == i::Token::FINALLY) {
Expect(i::Token::FINALLY, CHECK_OK); Consume(i::Token::FINALLY);
ParseBlock(CHECK_OK); ParseBlock(CHECK_OK);
catch_or_finally_seen = true; catch_or_finally_seen = true;
} }
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include "v8.h" #include "v8.h"
...@@ -277,7 +278,6 @@ TEST(RegressChromium62639) { ...@@ -277,7 +278,6 @@ TEST(RegressChromium62639) {
i::StackGuard::SetStackLimit( i::StackGuard::SetStackLimit(
reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
// Ensure that the source code is so big that it triggers preparsing.
char buffer[4096]; char buffer[4096];
const char* program_template = "var x = '%01024d'; // filler\n" const char* program_template = "var x = '%01024d'; // filler\n"
"escape: function() {}"; "escape: function() {}";
...@@ -293,3 +293,40 @@ TEST(RegressChromium62639) { ...@@ -293,3 +293,40 @@ TEST(RegressChromium62639) {
CHECK(data->HasError()); CHECK(data->HasError());
delete data; delete data;
} }
TEST(Regress928) {
// Preparsing didn't consider the catch clause of a try statement
// as with-content, which made it assume that a function inside
// the block could be lazily compiled, and an extra, unexpected,
// entry was added to the data.
int marker;
i::StackGuard::SetStackLimit(
reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
const char* program =
"try { } catch (e) { var foo = function () { /* first */ } }"
"var bar = function () { /* second */ }";
unibrow::Utf8InputBuffer<256> stream(program, strlen(program));
i::ScriptDataImpl* data =
i::ParserApi::PartialPreParse(i::Handle<i::String>::null(),
&stream, NULL);
CHECK(!data->HasError());
data->Initialize();
int first_function = strstr(program, "function") - program;
int first_lbrace = first_function + strlen("function () ");
CHECK_EQ('{', program[first_lbrace]);
i::FunctionEntry entry1 = data->GetFunctionEntry(first_lbrace);
CHECK(!entry1.is_valid());
int second_function = strstr(program + first_lbrace, "function") - program;
int second_lbrace = second_function + strlen("function () ");
CHECK_EQ('{', program[second_lbrace]);
i::FunctionEntry entry2 = data->GetFunctionEntry(second_lbrace);
CHECK(entry2.is_valid());
CHECK_EQ('}', program[entry2.end_pos() - 1]);
delete data;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment