| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 3352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3363 { "function h() { eval(''); }", true, false }, | 3363 { "function h() { eval(''); }", true, false }, |
| 3364 { "(function() { eval(''); })", true, false }, | 3364 { "(function() { eval(''); })", true, false }, |
| 3365 // Shadowing not recognized because of eval approximation. | 3365 // Shadowing not recognized because of eval approximation. |
| 3366 { "var x; eval('');", true, false }, | 3366 { "var x; eval('');", true, false }, |
| 3367 { "'use strict'; let x; eval('');", true, false }, | 3367 { "'use strict'; let x; eval('');", true, false }, |
| 3368 { "try {} catch(x) { eval(''); }", true, false }, | 3368 { "try {} catch(x) { eval(''); }", true, false }, |
| 3369 { "function x() { eval(''); }", true, false }, | 3369 { "function x() { eval(''); }", true, false }, |
| 3370 { "(function(x) { eval(''); })", true, false }, | 3370 { "(function(x) { eval(''); })", true, false }, |
| 3371 }; | 3371 }; |
| 3372 | 3372 |
| 3373 // Used to trigger lazy compilation of function | 3373 // Used to trigger lazy parsing of the outer function. |
| 3374 int comment_len = 2048; | 3374 int comment_len = 2048; |
| 3375 i::ScopedVector<char> comment(comment_len + 1); | 3375 i::ScopedVector<char> comment(comment_len + 1); |
| 3376 i::SNPrintF(comment, "/*%0*d*/", comment_len - 4, 0); | 3376 i::SNPrintF(comment, "/*%0*d*/", comment_len - 4, 0); |
| 3377 int prefix_len = Utf8LengthHelper(prefix); | 3377 int prefix_len = Utf8LengthHelper(prefix); |
| 3378 int midfix_len = Utf8LengthHelper(midfix); | 3378 int midfix_len = Utf8LengthHelper(midfix); |
| 3379 int suffix_len = Utf8LengthHelper(suffix); | 3379 int suffix_len = Utf8LengthHelper(suffix); |
| 3380 for (unsigned i = 0; i < arraysize(outers); ++i) { | 3380 for (unsigned i = 0; i < arraysize(outers); ++i) { |
| 3381 const char* outer = outers[i].source; | 3381 const char* outer = outers[i].source; |
| 3382 int outer_len = Utf8LengthHelper(outer); | 3382 int outer_len = Utf8LengthHelper(outer); |
| 3383 for (unsigned j = 0; j < arraysize(inners); ++j) { | 3383 for (unsigned j = 0; j < arraysize(inners); ++j) { |
| 3384 for (unsigned outer_lazy = 0; outer_lazy < 2; ++outer_lazy) { | 3384 for (unsigned lazy = 0; lazy < 2; ++lazy) { |
| 3385 for (unsigned inner_lazy = 0; inner_lazy < 2; ++inner_lazy) { | 3385 if (outers[i].strict && inners[j].with) continue; |
| 3386 if (outers[i].strict && inners[j].with) continue; | 3386 const char* inner = inners[j].source; |
| 3387 const char* inner = inners[j].source; | 3387 int inner_len = Utf8LengthHelper(inner); |
| 3388 int inner_len = Utf8LengthHelper(inner); | |
| 3389 | 3388 |
| 3390 int outer_comment_len = outer_lazy ? comment_len : 0; | 3389 const char* comment_chars = lazy ? comment.start() : ""; |
| 3391 int inner_comment_len = inner_lazy ? comment_len : 0; | 3390 int len = prefix_len + (lazy ? comment_len : 0) + outer_len + |
| 3392 const char* outer_comment = outer_lazy ? comment.start() : ""; | 3391 midfix_len + inner_len + suffix_len; |
| 3393 const char* inner_comment = inner_lazy ? comment.start() : ""; | 3392 i::ScopedVector<char> program(len + 1); |
| 3394 int len = prefix_len + outer_comment_len + outer_len + midfix_len + | |
| 3395 inner_comment_len + inner_len + suffix_len; | |
| 3396 i::ScopedVector<char> program(len + 1); | |
| 3397 | 3393 |
| 3398 i::SNPrintF(program, "%s%s%s%s%s%s%s", prefix, outer_comment, outer, | 3394 i::SNPrintF(program, "%s%s%s%s%s%s", comment_chars, prefix, outer, |
| 3399 midfix, inner_comment, inner, suffix); | 3395 midfix, inner, suffix); |
| 3400 i::Handle<i::String> source = | 3396 i::Handle<i::String> source = |
| 3401 factory->InternalizeUtf8String(program.start()); | 3397 factory->InternalizeUtf8String(program.start()); |
| 3402 source->PrintOn(stdout); | 3398 source->PrintOn(stdout); |
| 3403 printf("\n"); | 3399 printf("\n"); |
| 3404 | 3400 |
| 3405 i::Handle<i::Script> script = factory->NewScript(source); | 3401 i::Handle<i::Script> script = factory->NewScript(source); |
| 3406 i::Zone zone(CcTest::i_isolate()->allocator()); | 3402 i::Zone zone(CcTest::i_isolate()->allocator()); |
| 3407 i::ParseInfo info(&zone, script); | 3403 i::ParseInfo info(&zone, script); |
| 3408 i::Parser parser(&info); | 3404 i::Parser parser(&info); |
| 3409 CHECK(parser.Parse(&info)); | 3405 CHECK(parser.Parse(&info)); |
| 3410 CHECK(i::Compiler::Analyze(&info)); | 3406 CHECK(i::Compiler::Analyze(&info)); |
| 3411 CHECK(info.literal() != NULL); | 3407 CHECK(info.literal() != NULL); |
| 3412 | 3408 |
| 3413 i::Scope* scope = info.literal()->scope(); | 3409 i::Scope* scope = info.literal()->scope(); |
| 3414 i::Scope* inner_scope = scope->inner_scope(); | 3410 i::Scope* inner_scope = scope->inner_scope(); |
| 3415 DCHECK_NOT_NULL(inner_scope); | 3411 DCHECK_NOT_NULL(inner_scope); |
| 3416 DCHECK_NULL(inner_scope->sibling()); | 3412 DCHECK_NULL(inner_scope->sibling()); |
| 3417 const i::AstRawString* var_name = | 3413 const i::AstRawString* var_name = |
| 3418 info.ast_value_factory()->GetOneByteString("x"); | 3414 info.ast_value_factory()->GetOneByteString("x"); |
| 3419 i::Variable* var = inner_scope->Lookup(var_name); | 3415 i::Variable* var = inner_scope->Lookup(var_name); |
| 3420 bool expected = outers[i].assigned || inners[j].assigned; | 3416 bool expected = outers[i].assigned || inners[j].assigned; |
| 3421 CHECK(var != NULL); | 3417 CHECK(var != NULL); |
| 3422 CHECK(var->is_used() || !expected); | 3418 CHECK(var->is_used() || !expected); |
| 3423 CHECK((var->maybe_assigned() == i::kMaybeAssigned) == expected); | 3419 CHECK((var->maybe_assigned() == i::kMaybeAssigned) == expected); |
| 3424 } | |
| 3425 } | 3420 } |
| 3426 } | 3421 } |
| 3427 } | 3422 } |
| 3428 } | 3423 } |
| 3429 | 3424 |
| 3430 namespace { | 3425 namespace { |
| 3431 | 3426 |
| 3432 int* global_use_counts = NULL; | 3427 int* global_use_counts = NULL; |
| 3433 | 3428 |
| 3434 void MockUseCounterCallback(v8::Isolate* isolate, | 3429 void MockUseCounterCallback(v8::Isolate* isolate, |
| (...skipping 4893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8328 const char* data[] = { | 8323 const char* data[] = { |
| 8329 "const arguments = 1", | 8324 "const arguments = 1", |
| 8330 "let arguments", | 8325 "let arguments", |
| 8331 "var arguments", | 8326 "var arguments", |
| 8332 NULL | 8327 NULL |
| 8333 }; | 8328 }; |
| 8334 // clang-format on | 8329 // clang-format on |
| 8335 RunParserSyncTest(context_data, data, kSuccess); | 8330 RunParserSyncTest(context_data, data, kSuccess); |
| 8336 } | 8331 } |
| 8337 } | 8332 } |
| OLD | NEW |