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::Handle<i::String> source =
factory->InternalizeUtf8String(program.start());
source->PrintOn(stdout);
printf("\n");
i::Handle<i::Script> script = factory->NewScript(source);
i::Zone zone(CcTest::i_isolate()->allocator()); i::Zone zone(CcTest::i_isolate()->allocator());
i::ParseInfo info(&zone, script); std::unique_ptr<i::ParseInfo> info;
i::Parser parser(&info); if (lazy) {
CHECK(parser.Parse(&info)); printf("%s\n", program.start());
CHECK(i::Compiler::Analyze(&info)); v8::Local<v8::Value> v = CompileRun(program.start());
CHECK(info.literal() != NULL); i::Handle<i::Object> o = v8::Utils::OpenHandle(*v);
i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o);
i::Scope* scope = info.literal()->scope(); info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, f));
i::Scope* inner_scope = scope->inner_scope(); } else {
DCHECK_NOT_NULL(inner_scope); i::Handle<i::String> source =
DCHECK_NULL(inner_scope->sibling()); factory->InternalizeUtf8String(program.start());
source->PrintOn(stdout);
printf("\n");
i::Handle<i::Script> script = factory->NewScript(source);
info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, script));
}
i::Parser parser(info.get());
CHECK(parser.Parse(info.get()));
CHECK(i::Compiler::Analyze(info.get()));
CHECK(info->literal() != NULL);
i::Scope* scope = info->literal()->scope();
if (!lazy) {
scope = scope->inner_scope();
}
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