Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Side by Side Diff: src/preparser.cc

Issue 8662037: Don't preparse large files to find boundaries of lazy functions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Updated to match tip of bleeding edge Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/preparser.h ('k') | src/scanner.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 i::LanguageMode 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 set_language_mode(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 (!is_classic_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 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1343 "strict_param_dupe", 1371 "strict_param_dupe",
1344 CHECK_OK); 1372 CHECK_OK);
1345 } 1373 }
1346 done = (peek() == i::Token::RPAREN); 1374 done = (peek() == i::Token::RPAREN);
1347 if (!done) { 1375 if (!done) {
1348 Expect(i::Token::COMMA, CHECK_OK); 1376 Expect(i::Token::COMMA, CHECK_OK);
1349 } 1377 }
1350 } 1378 }
1351 Expect(i::Token::RPAREN, CHECK_OK); 1379 Expect(i::Token::RPAREN, CHECK_OK);
1352 1380
1353 Expect(i::Token::LBRACE, CHECK_OK);
1354 int function_block_pos = scanner_->location().beg_pos;
1355
1356 // Determine if the function will be lazily compiled. 1381 // Determine if the function will be lazily compiled.
1357 // Currently only happens to top-level functions. 1382 // Currently only happens to top-level functions.
1358 // Optimistically assume that all top-level functions are lazily compiled. 1383 // Optimistically assume that all top-level functions are lazily compiled.
1359 bool is_lazily_compiled = (outer_scope_type == kTopLevelScope && 1384 bool is_lazily_compiled = (outer_scope_type == kTopLevelScope &&
1360 !inside_with && allow_lazy_ && 1385 !inside_with && allow_lazy_ &&
1361 !parenthesized_function_); 1386 !parenthesized_function_);
1362 parenthesized_function_ = false; 1387 parenthesized_function_ = false;
1363 1388
1389 Expect(i::Token::LBRACE, CHECK_OK);
1364 if (is_lazily_compiled) { 1390 if (is_lazily_compiled) {
1365 log_->PauseRecording(); 1391 ParseLazyFunctionLiteralBody(CHECK_OK);
1392 } else {
1366 ParseSourceElements(i::Token::RBRACE, ok); 1393 ParseSourceElements(i::Token::RBRACE, ok);
1367 log_->ResumeRecording();
1368 if (!*ok) Expression::Default();
1369
1370 Expect(i::Token::RBRACE, CHECK_OK);
1371
1372 // Position right after terminal '}'.
1373 int end_pos = scanner_->location().end_pos;
1374 log_->LogFunction(function_block_pos, end_pos,
1375 function_scope.materialized_literal_count(),
1376 function_scope.expected_properties(),
1377 language_mode());
1378 } else {
1379 ParseSourceElements(i::Token::RBRACE, CHECK_OK);
1380 Expect(i::Token::RBRACE, CHECK_OK);
1381 } 1394 }
1395 Expect(i::Token::RBRACE, CHECK_OK);
1382 1396
1383 if (!is_classic_mode()) { 1397 if (!is_classic_mode()) {
1384 int end_position = scanner_->location().end_pos; 1398 int end_position = scanner_->location().end_pos;
1385 CheckOctalLiteral(start_position, end_position, CHECK_OK); 1399 CheckOctalLiteral(start_position, end_position, CHECK_OK);
1386 CheckDelayedStrictModeViolation(start_position, end_position, CHECK_OK); 1400 CheckDelayedStrictModeViolation(start_position, end_position, CHECK_OK);
1387 return Expression::StrictFunction(); 1401 return Expression::StrictFunction();
1388 } 1402 }
1389 1403
1390 return Expression::Default(); 1404 return Expression::Default();
1391 } 1405 }
1392 1406
1393 1407
1408 void PreParser::ParseLazyFunctionLiteralBody(bool* ok) {
1409 int body_start = scanner_->location().beg_pos;
1410 log_->PauseRecording();
1411 ParseSourceElements(i::Token::RBRACE, ok);
1412 log_->ResumeRecording();
1413 if (!*ok) return;
1414
1415 // Position right after terminal '}'.
1416 ASSERT_EQ(i::Token::RBRACE, scanner_->peek());
1417 int body_end = scanner_->peek_location().end_pos;
1418 log_->LogFunction(body_start, body_end,
1419 scope_->materialized_literal_count(),
1420 scope_->expected_properties(),
1421 language_mode());
1422 }
1423
1424
1394 PreParser::Expression PreParser::ParseV8Intrinsic(bool* ok) { 1425 PreParser::Expression PreParser::ParseV8Intrinsic(bool* ok) {
1395 // CallRuntime :: 1426 // CallRuntime ::
1396 // '%' Identifier Arguments 1427 // '%' Identifier Arguments
1397 Expect(i::Token::MOD, CHECK_OK); 1428 Expect(i::Token::MOD, CHECK_OK);
1398 if (!allow_natives_syntax_) { 1429 if (!allow_natives_syntax_) {
1399 *ok = false; 1430 *ok = false;
1400 return Expression::Default(); 1431 return Expression::Default();
1401 } 1432 }
1402 ParseIdentifier(CHECK_OK); 1433 ParseIdentifier(CHECK_OK);
1403 ParseArguments(ok); 1434 ParseArguments(ok);
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1724 backing_store_.Add(static_cast<byte>((ascii_length >> 14) | 0x80u)); 1755 backing_store_.Add(static_cast<byte>((ascii_length >> 14) | 0x80u));
1725 } 1756 }
1726 backing_store_.Add(static_cast<byte>((ascii_length >> 7) | 0x80u)); 1757 backing_store_.Add(static_cast<byte>((ascii_length >> 7) | 0x80u));
1727 } 1758 }
1728 backing_store_.Add(static_cast<byte>(ascii_length & 0x7f)); 1759 backing_store_.Add(static_cast<byte>(ascii_length & 0x7f));
1729 1760
1730 backing_store_.AddBlock(bytes); 1761 backing_store_.AddBlock(bytes);
1731 return backing_store_.EndSequence().start(); 1762 return backing_store_.EndSequence().start();
1732 } 1763 }
1733 } } // v8::preparser 1764 } } // v8::preparser
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | src/scanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698