OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 namespace v8 { | 45 namespace v8 { |
46 | 46 |
47 #ifdef _MSC_VER | 47 #ifdef _MSC_VER |
48 // Usually defined in math.h, but not in MSVC. | 48 // Usually defined in math.h, but not in MSVC. |
49 // Abstracted to work | 49 // Abstracted to work |
50 int isfinite(double value); | 50 int isfinite(double value); |
51 #endif | 51 #endif |
52 | 52 |
53 namespace preparser { | 53 namespace preparser { |
54 | 54 |
| 55 PreParser::PreParseResult PreParser::PreParseLazyFunction( |
| 56 bool strict_mode, i::ParserRecorder* log) { |
| 57 log_ = log; |
| 58 // Lazy functions always have trivial outer scopes (no with/catch scopes). |
| 59 Scope top_scope(&scope_, kTopLevelScope); |
| 60 if (strict_mode) set_strict_mode(); |
| 61 Scope function_scope(&scope_, kFunctionScope); |
| 62 ASSERT_EQ(i::Token::LBRACE, scanner_->current_token()); |
| 63 bool ok = true; |
| 64 int start_position = scanner_->peek_location().beg_pos; |
| 65 ParseLazyFunctionLiteralBody(&ok); |
| 66 if (stack_overflow_) return kPreParseStackOverflow; |
| 67 if (!ok) { |
| 68 ReportUnexpectedToken(scanner_->current_token()); |
| 69 } else { |
| 70 ASSERT_EQ(i::Token::RBRACE, scanner_->peek()); |
| 71 if (scope_->is_strict_mode()) { |
| 72 int end_pos = scanner_->location().end_pos; |
| 73 CheckOctalLiteral(start_position, end_pos, &ok); |
| 74 if (ok) { |
| 75 CheckDelayedStrictModeViolation(start_position, end_pos, &ok); |
| 76 } |
| 77 } |
| 78 } |
| 79 return kPreParseSuccess; |
| 80 } |
| 81 |
| 82 |
55 // Preparsing checks a JavaScript program and emits preparse-data that helps | 83 // Preparsing checks a JavaScript program and emits preparse-data that helps |
56 // a later parsing to be faster. | 84 // a later parsing to be faster. |
57 // See preparser-data.h for the data. | 85 // See preparser-data.h for the data. |
58 | 86 |
59 // The PreParser checks that the syntax follows the grammar for JavaScript, | 87 // The PreParser checks that the syntax follows the grammar for JavaScript, |
60 // and collects some information about the program along the way. | 88 // and collects some information about the program along the way. |
61 // The grammar check is only performed in order to understand the program | 89 // The grammar check is only performed in order to understand the program |
62 // sufficiently to deduce some information about it, that can be used | 90 // sufficiently to deduce some information about it, that can be used |
63 // to speed up later parsing. Finding errors is not the goal of pre-parsing, | 91 // to speed up later parsing. Finding errors is not the goal of pre-parsing, |
64 // rather it is to speed up properly written and correct programs. | 92 // rather it is to speed up properly written and correct programs. |
(...skipping 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1333 "strict_param_dupe", | 1361 "strict_param_dupe", |
1334 CHECK_OK); | 1362 CHECK_OK); |
1335 } | 1363 } |
1336 done = (peek() == i::Token::RPAREN); | 1364 done = (peek() == i::Token::RPAREN); |
1337 if (!done) { | 1365 if (!done) { |
1338 Expect(i::Token::COMMA, CHECK_OK); | 1366 Expect(i::Token::COMMA, CHECK_OK); |
1339 } | 1367 } |
1340 } | 1368 } |
1341 Expect(i::Token::RPAREN, CHECK_OK); | 1369 Expect(i::Token::RPAREN, CHECK_OK); |
1342 | 1370 |
1343 Expect(i::Token::LBRACE, CHECK_OK); | |
1344 int function_block_pos = scanner_->location().beg_pos; | |
1345 | |
1346 // Determine if the function will be lazily compiled. | 1371 // Determine if the function will be lazily compiled. |
1347 // Currently only happens to top-level functions. | 1372 // Currently only happens to top-level functions. |
1348 // Optimistically assume that all top-level functions are lazily compiled. | 1373 // Optimistically assume that all top-level functions are lazily compiled. |
1349 bool is_lazily_compiled = (outer_scope_type == kTopLevelScope && | 1374 bool is_lazily_compiled = (outer_scope_type == kTopLevelScope && |
1350 !inside_with && allow_lazy_ && | 1375 !inside_with && allow_lazy_ && |
1351 !parenthesized_function_); | 1376 !parenthesized_function_); |
1352 parenthesized_function_ = false; | 1377 parenthesized_function_ = false; |
1353 | 1378 |
| 1379 Expect(i::Token::LBRACE, CHECK_OK); |
1354 if (is_lazily_compiled) { | 1380 if (is_lazily_compiled) { |
1355 log_->PauseRecording(); | 1381 ParseLazyFunctionLiteralBody(CHECK_OK); |
| 1382 } else { |
1356 ParseSourceElements(i::Token::RBRACE, ok); | 1383 ParseSourceElements(i::Token::RBRACE, ok); |
1357 log_->ResumeRecording(); | |
1358 if (!*ok) Expression::Default(); | |
1359 | |
1360 Expect(i::Token::RBRACE, CHECK_OK); | |
1361 | |
1362 // Position right after terminal '}'. | |
1363 int end_pos = scanner_->location().end_pos; | |
1364 log_->LogFunction(function_block_pos, end_pos, | |
1365 function_scope.materialized_literal_count(), | |
1366 function_scope.expected_properties(), | |
1367 strict_mode_flag()); | |
1368 } else { | |
1369 ParseSourceElements(i::Token::RBRACE, CHECK_OK); | |
1370 Expect(i::Token::RBRACE, CHECK_OK); | |
1371 } | 1384 } |
| 1385 Expect(i::Token::RBRACE, CHECK_OK); |
1372 | 1386 |
1373 if (strict_mode()) { | 1387 if (strict_mode()) { |
1374 int end_position = scanner_->location().end_pos; | 1388 int end_position = scanner_->location().end_pos; |
1375 CheckOctalLiteral(start_position, end_position, CHECK_OK); | 1389 CheckOctalLiteral(start_position, end_position, CHECK_OK); |
1376 CheckDelayedStrictModeViolation(start_position, end_position, CHECK_OK); | 1390 CheckDelayedStrictModeViolation(start_position, end_position, CHECK_OK); |
1377 return Expression::StrictFunction(); | 1391 return Expression::StrictFunction(); |
1378 } | 1392 } |
1379 | 1393 |
1380 return Expression::Default(); | 1394 return Expression::Default(); |
1381 } | 1395 } |
1382 | 1396 |
1383 | 1397 |
| 1398 void PreParser::ParseLazyFunctionLiteralBody(bool* ok) { |
| 1399 int body_start = scanner_->location().beg_pos; |
| 1400 log_->PauseRecording(); |
| 1401 ParseSourceElements(i::Token::RBRACE, ok); |
| 1402 log_->ResumeRecording(); |
| 1403 if (!*ok) return; |
| 1404 |
| 1405 // Position right after terminal '}'. |
| 1406 ASSERT_EQ(i::Token::RBRACE, scanner_->peek()); |
| 1407 int body_end = scanner_->peek_location().end_pos; |
| 1408 log_->LogFunction(body_start, body_end, |
| 1409 scope_->materialized_literal_count(), |
| 1410 scope_->expected_properties(), |
| 1411 scope_->strict_mode_flag()); |
| 1412 } |
| 1413 |
| 1414 |
1384 PreParser::Expression PreParser::ParseV8Intrinsic(bool* ok) { | 1415 PreParser::Expression PreParser::ParseV8Intrinsic(bool* ok) { |
1385 // CallRuntime :: | 1416 // CallRuntime :: |
1386 // '%' Identifier Arguments | 1417 // '%' Identifier Arguments |
1387 Expect(i::Token::MOD, CHECK_OK); | 1418 Expect(i::Token::MOD, CHECK_OK); |
1388 if (!allow_natives_syntax_) { | 1419 if (!allow_natives_syntax_) { |
1389 *ok = false; | 1420 *ok = false; |
1390 return Expression::Default(); | 1421 return Expression::Default(); |
1391 } | 1422 } |
1392 ParseIdentifier(CHECK_OK); | 1423 ParseIdentifier(CHECK_OK); |
1393 ParseArguments(ok); | 1424 ParseArguments(ok); |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1714 backing_store_.Add(static_cast<byte>((ascii_length >> 14) | 0x80u)); | 1745 backing_store_.Add(static_cast<byte>((ascii_length >> 14) | 0x80u)); |
1715 } | 1746 } |
1716 backing_store_.Add(static_cast<byte>((ascii_length >> 7) | 0x80u)); | 1747 backing_store_.Add(static_cast<byte>((ascii_length >> 7) | 0x80u)); |
1717 } | 1748 } |
1718 backing_store_.Add(static_cast<byte>(ascii_length & 0x7f)); | 1749 backing_store_.Add(static_cast<byte>(ascii_length & 0x7f)); |
1719 | 1750 |
1720 backing_store_.AddBlock(bytes); | 1751 backing_store_.AddBlock(bytes); |
1721 return backing_store_.EndSequence().start(); | 1752 return backing_store_.EndSequence().start(); |
1722 } | 1753 } |
1723 } } // v8::preparser | 1754 } } // v8::preparser |
OLD | NEW |