Commit 41f51fe3 authored by verwaest's avatar verwaest Committed by Commit bot

Fix test-parsing/InnerAssignment to test what it intended

BUG=

Review-Url: https://codereview.chromium.org/2417833002
Cr-Commit-Position: refs/heads/master@{#40259}
parent a726e85f
...@@ -3281,7 +3281,7 @@ TEST(InnerAssignment) { ...@@ -3281,7 +3281,7 @@ TEST(InnerAssignment) {
const char* prefix = "function f() {"; const char* prefix = "function f() {";
const char* midfix = " function g() {"; const char* midfix = " function g() {";
const char* suffix = "}}"; const char* suffix = "}}; f";
struct { const char* source; bool assigned; bool strict; } outers[] = { struct { const char* source; bool assigned; bool strict; } outers[] = {
// Actual assignments. // Actual assignments.
{ "var x; var x = 5;", true, false }, { "var x; var x = 5;", true, false },
...@@ -3361,10 +3361,6 @@ TEST(InnerAssignment) { ...@@ -3361,10 +3361,6 @@ TEST(InnerAssignment) {
{ "(function(x) { eval(''); })", true, false }, { "(function(x) { eval(''); })", true, false },
}; };
// Used to trigger lazy parsing of the outer function.
int comment_len = 2048;
i::ScopedVector<char> comment(comment_len + 1);
i::SNPrintF(comment, "/*%0*d*/", comment_len - 4, 0);
int prefix_len = Utf8LengthHelper(prefix); int prefix_len = Utf8LengthHelper(prefix);
int midfix_len = Utf8LengthHelper(midfix); int midfix_len = Utf8LengthHelper(midfix);
int suffix_len = Utf8LengthHelper(suffix); int suffix_len = Utf8LengthHelper(suffix);
...@@ -3377,33 +3373,43 @@ TEST(InnerAssignment) { ...@@ -3377,33 +3373,43 @@ TEST(InnerAssignment) {
const char* inner = inners[j].source; const char* inner = inners[j].source;
int inner_len = Utf8LengthHelper(inner); int inner_len = Utf8LengthHelper(inner);
const char* comment_chars = lazy ? comment.start() : ""; int len = prefix_len + outer_len + midfix_len + inner_len + suffix_len;
int len = prefix_len + (lazy ? comment_len : 0) + outer_len +
midfix_len + inner_len + suffix_len;
i::ScopedVector<char> program(len + 1); i::ScopedVector<char> program(len + 1);
i::SNPrintF(program, "%s%s%s%s%s%s", comment_chars, prefix, outer, i::SNPrintF(program, "%s%s%s%s%s", prefix, outer, midfix, inner,
midfix, inner, suffix); suffix);
i::Zone zone(CcTest::i_isolate()->allocator());
std::unique_ptr<i::ParseInfo> info;
if (lazy) {
printf("%s\n", program.start());
v8::Local<v8::Value> v = CompileRun(program.start());
i::Handle<i::Object> o = v8::Utils::OpenHandle(*v);
i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o);
info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, f));
} else {
i::Handle<i::String> source = i::Handle<i::String> source =
factory->InternalizeUtf8String(program.start()); factory->InternalizeUtf8String(program.start());
source->PrintOn(stdout); source->PrintOn(stdout);
printf("\n"); printf("\n");
i::Handle<i::Script> script = factory->NewScript(source); i::Handle<i::Script> script = factory->NewScript(source);
i::Zone zone(CcTest::i_isolate()->allocator()); info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, script));
i::ParseInfo info(&zone, script); }
i::Parser parser(&info); i::Parser parser(info.get());
CHECK(parser.Parse(&info)); CHECK(parser.Parse(info.get()));
CHECK(i::Compiler::Analyze(&info)); CHECK(i::Compiler::Analyze(info.get()));
CHECK(info.literal() != NULL); CHECK(info->literal() != NULL);
i::Scope* scope = info.literal()->scope(); i::Scope* scope = info->literal()->scope();
i::Scope* inner_scope = scope->inner_scope(); if (!lazy) {
DCHECK_NOT_NULL(inner_scope); scope = scope->inner_scope();
DCHECK_NULL(inner_scope->sibling()); }
DCHECK_NOT_NULL(scope);
DCHECK_NULL(scope->sibling());
DCHECK(scope->is_function_scope());
const i::AstRawString* var_name = const i::AstRawString* var_name =
info.ast_value_factory()->GetOneByteString("x"); info->ast_value_factory()->GetOneByteString("x");
i::Variable* var = inner_scope->Lookup(var_name); i::Variable* var = scope->Lookup(var_name);
bool expected = outers[i].assigned || inners[j].assigned; bool expected = outers[i].assigned || inners[j].assigned;
CHECK(var != NULL); CHECK(var != NULL);
CHECK(var->is_used() || !expected); CHECK(var->is_used() || !expected);
......
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