| 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 1392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1403 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen); | 1403 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen); |
| 1404 } | 1404 } |
| 1405 } | 1405 } |
| 1406 | 1406 |
| 1407 | 1407 |
| 1408 TEST(DiscardFunctionBody) { | 1408 TEST(DiscardFunctionBody) { |
| 1409 // Test that inner function bodies are discarded if possible. | 1409 // Test that inner function bodies are discarded if possible. |
| 1410 // See comments in ParseFunctionLiteral in parser.cc. | 1410 // See comments in ParseFunctionLiteral in parser.cc. |
| 1411 const char* discard_sources[] = { | 1411 const char* discard_sources[] = { |
| 1412 "(function f() { function g() { var a; } })();", | 1412 "(function f() { function g() { var a; } })();", |
| 1413 "(function f() { function g() { { function h() { } } } })();", |
| 1413 /* TODO(conradw): In future it may be possible to apply this optimisation | 1414 /* TODO(conradw): In future it may be possible to apply this optimisation |
| 1414 * to these productions. | 1415 * to these productions. |
| 1415 "(function f() { 0, function g() { var a; } })();", | 1416 "(function f() { 0, function g() { var a; } })();", |
| 1416 "(function f() { 0, { g() { var a; } } })();", | 1417 "(function f() { 0, { g() { var a; } } })();", |
| 1417 "(function f() { 0, class c { g() { var a; } } })();", */ | 1418 "(function f() { 0, class c { g() { var a; } } })();", */ |
| 1418 NULL | 1419 NULL}; |
| 1419 }; | |
| 1420 | 1420 |
| 1421 i::Isolate* isolate = CcTest::i_isolate(); | 1421 i::Isolate* isolate = CcTest::i_isolate(); |
| 1422 i::Factory* factory = isolate->factory(); | 1422 i::Factory* factory = isolate->factory(); |
| 1423 v8::HandleScope handles(CcTest::isolate()); | 1423 v8::HandleScope handles(CcTest::isolate()); |
| 1424 i::FunctionLiteral* function; | 1424 i::FunctionLiteral* function; |
| 1425 | 1425 |
| 1426 for (int i = 0; discard_sources[i]; i++) { | 1426 for (int i = 0; discard_sources[i]; i++) { |
| 1427 const char* source = discard_sources[i]; | 1427 const char* source = discard_sources[i]; |
| 1428 i::Handle<i::String> source_code = | 1428 i::Handle<i::String> source_code = |
| 1429 factory->NewStringFromUtf8(i::CStrVector(source)).ToHandleChecked(); | 1429 factory->NewStringFromUtf8(i::CStrVector(source)).ToHandleChecked(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1441 i::FunctionLiteral* inner = | 1441 i::FunctionLiteral* inner = |
| 1442 function->body()->first()->AsExpressionStatement()->expression()-> | 1442 function->body()->first()->AsExpressionStatement()->expression()-> |
| 1443 AsCall()->expression()->AsFunctionLiteral(); | 1443 AsCall()->expression()->AsFunctionLiteral(); |
| 1444 i::Scope* inner_scope = inner->scope(); | 1444 i::Scope* inner_scope = inner->scope(); |
| 1445 i::FunctionLiteral* fun = nullptr; | 1445 i::FunctionLiteral* fun = nullptr; |
| 1446 if (inner_scope->declarations()->length() > 1) { | 1446 if (inner_scope->declarations()->length() > 1) { |
| 1447 fun = inner_scope->declarations()->at(1)->AsFunctionDeclaration()->fun(); | 1447 fun = inner_scope->declarations()->at(1)->AsFunctionDeclaration()->fun(); |
| 1448 } else { | 1448 } else { |
| 1449 // TODO(conradw): This path won't be hit until the other test cases can be | 1449 // TODO(conradw): This path won't be hit until the other test cases can be |
| 1450 // uncommented. | 1450 // uncommented. |
| 1451 UNREACHABLE(); |
| 1451 CHECK_NOT_NULL(inner->body()); | 1452 CHECK_NOT_NULL(inner->body()); |
| 1452 CHECK_GE(2, inner->body()->length()); | 1453 CHECK_GE(2, inner->body()->length()); |
| 1453 i::Expression* exp = inner->body()->at(1)->AsExpressionStatement()-> | 1454 i::Expression* exp = inner->body()->at(1)->AsExpressionStatement()-> |
| 1454 expression()->AsBinaryOperation()->right(); | 1455 expression()->AsBinaryOperation()->right(); |
| 1455 if (exp->IsFunctionLiteral()) { | 1456 if (exp->IsFunctionLiteral()) { |
| 1456 fun = exp->AsFunctionLiteral(); | 1457 fun = exp->AsFunctionLiteral(); |
| 1457 } else if (exp->IsObjectLiteral()) { | 1458 } else if (exp->IsObjectLiteral()) { |
| 1458 fun = exp->AsObjectLiteral()->properties()->at(0)->value()-> | 1459 fun = exp->AsObjectLiteral()->properties()->at(0)->value()-> |
| 1459 AsFunctionLiteral(); | 1460 AsFunctionLiteral(); |
| 1460 } else { | 1461 } else { |
| (...skipping 6311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7772 } | 7773 } |
| 7773 | 7774 |
| 7774 | 7775 |
| 7775 TEST(MiscSyntaxErrors) { | 7776 TEST(MiscSyntaxErrors) { |
| 7776 const char* context_data[][2] = { | 7777 const char* context_data[][2] = { |
| 7777 {"'use strict'", ""}, {"", ""}, {NULL, NULL}}; | 7778 {"'use strict'", ""}, {"", ""}, {NULL, NULL}}; |
| 7778 const char* error_data[] = {"for (();;) {}", NULL}; | 7779 const char* error_data[] = {"for (();;) {}", NULL}; |
| 7779 | 7780 |
| 7780 RunParserSyncTest(context_data, error_data, kError, NULL, 0, NULL, 0); | 7781 RunParserSyncTest(context_data, error_data, kError, NULL, 0, NULL, 0); |
| 7781 } | 7782 } |
| OLD | NEW |