| 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 // labels can be simply ignored in all other cases; except for | 192 // labels can be simply ignored in all other cases; except for |
| 193 // trivial labeled break statements 'label: break label' which is | 193 // trivial labeled break statements 'label: break label' which is |
| 194 // parsed into an empty statement. | 194 // parsed into an empty statement. |
| 195 | 195 |
| 196 // Keep the source position of the statement | 196 // Keep the source position of the statement |
| 197 switch (peek()) { | 197 switch (peek()) { |
| 198 case i::Token::LBRACE: | 198 case i::Token::LBRACE: |
| 199 return ParseBlock(ok); | 199 return ParseBlock(ok); |
| 200 | 200 |
| 201 case i::Token::CONST: | 201 case i::Token::CONST: |
| 202 case i::Token::LET: |
| 202 case i::Token::VAR: | 203 case i::Token::VAR: |
| 203 return ParseVariableStatement(kStatement, ok); | 204 return ParseVariableStatement(kStatement, ok); |
| 204 | 205 |
| 205 case i::Token::SEMICOLON: | 206 case i::Token::SEMICOLON: |
| 206 Next(); | 207 Next(); |
| 207 return Statement::Default(); | 208 return Statement::Default(); |
| 208 | 209 |
| 209 case i::Token::IF: | 210 case i::Token::IF: |
| 210 return ParseIfStatement(ok); | 211 return ParseIfStatement(ok); |
| 211 | 212 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 // ConstBinding :: | 343 // ConstBinding :: |
| 343 // Identifier '=' AssignmentExpression | 344 // Identifier '=' AssignmentExpression |
| 344 // | 345 // |
| 345 // TODO(ES6): | 346 // TODO(ES6): |
| 346 // ConstBinding :: | 347 // ConstBinding :: |
| 347 // BindingPattern '=' AssignmentExpression | 348 // BindingPattern '=' AssignmentExpression |
| 348 bool require_initializer = false; | 349 bool require_initializer = false; |
| 349 if (peek() == i::Token::VAR) { | 350 if (peek() == i::Token::VAR) { |
| 350 Consume(i::Token::VAR); | 351 Consume(i::Token::VAR); |
| 351 } else if (peek() == i::Token::CONST) { | 352 } else if (peek() == i::Token::CONST) { |
| 353 // TODO(ES6): The ES6 Draft Rev4 section 12.2.2 reads: |
| 354 // |
| 355 // ConstDeclaration : const ConstBinding (',' ConstBinding)* ';' |
| 356 // |
| 357 // * It is a Syntax Error if the code that matches this production is not |
| 358 // contained in extended code. |
| 359 // |
| 360 // However disallowing const in classic mode will break compatibility with |
| 361 // existing pages. Therefore we keep allowing const with the old |
| 362 // non-harmony semantics in classic mode. |
| 363 Consume(i::Token::CONST); |
| 352 switch (language_mode()) { | 364 switch (language_mode()) { |
| 353 case i::CLASSIC_MODE: | 365 case i::CLASSIC_MODE: |
| 354 break; | 366 break; |
| 355 case i::STRICT_MODE: { | 367 case i::STRICT_MODE: { |
| 356 i::Scanner::Location location = scanner_->peek_location(); | 368 i::Scanner::Location location = scanner_->peek_location(); |
| 357 ReportMessageAt(location, "strict_const", NULL); | 369 ReportMessageAt(location, "strict_const", NULL); |
| 358 *ok = false; | 370 *ok = false; |
| 359 return Statement::Default(); | 371 return Statement::Default(); |
| 360 } | 372 } |
| 361 case i::EXTENDED_MODE: | 373 case i::EXTENDED_MODE: |
| 362 if (var_context != kSourceElement && | 374 if (var_context != kSourceElement && |
| 363 var_context != kForStatement) { | 375 var_context != kForStatement) { |
| 364 i::Scanner::Location location = scanner_->peek_location(); | 376 i::Scanner::Location location = scanner_->peek_location(); |
| 365 ReportMessageAt(location.beg_pos, location.end_pos, | 377 ReportMessageAt(location.beg_pos, location.end_pos, |
| 366 "unprotected_const", NULL); | 378 "unprotected_const", NULL); |
| 367 *ok = false; | 379 *ok = false; |
| 368 return Statement::Default(); | 380 return Statement::Default(); |
| 369 } | 381 } |
| 370 require_initializer = true; | 382 require_initializer = true; |
| 371 break; | 383 break; |
| 372 } | 384 } |
| 373 Consume(i::Token::CONST); | |
| 374 } else if (peek() == i::Token::LET) { | 385 } else if (peek() == i::Token::LET) { |
| 375 ASSERT(is_extended_mode()); | 386 // ES6 Draft Rev4 section 12.2.1: |
| 387 // |
| 388 // LetDeclaration : let LetBindingList ; |
| 389 // |
| 390 // * It is a Syntax Error if the code that matches this production is not |
| 391 // contained in extended code. |
| 392 if (!is_extended_mode()) { |
| 393 i::Scanner::Location location = scanner_->peek_location(); |
| 394 ReportMessageAt(location.beg_pos, location.end_pos, |
| 395 "illegal_let", NULL); |
| 396 *ok = false; |
| 397 return Statement::Default(); |
| 398 } |
| 399 Consume(i::Token::LET); |
| 376 if (var_context != kSourceElement && | 400 if (var_context != kSourceElement && |
| 377 var_context != kForStatement) { | 401 var_context != kForStatement) { |
| 378 i::Scanner::Location location = scanner_->peek_location(); | 402 i::Scanner::Location location = scanner_->peek_location(); |
| 379 ReportMessageAt(location.beg_pos, location.end_pos, | 403 ReportMessageAt(location.beg_pos, location.end_pos, |
| 380 "unprotected_let", NULL); | 404 "unprotected_let", NULL); |
| 381 *ok = false; | 405 *ok = false; |
| 382 return Statement::Default(); | 406 return Statement::Default(); |
| 383 } | 407 } |
| 384 Consume(i::Token::LET); | |
| 385 } else { | 408 } else { |
| 386 *ok = false; | 409 *ok = false; |
| 387 return Statement::Default(); | 410 return Statement::Default(); |
| 388 } | 411 } |
| 389 | 412 |
| 390 // The scope of a var/const declared variable anywhere inside a function | 413 // The scope of a var/const declared variable anywhere inside a function |
| 391 // is the entire function (ECMA-262, 3rd, 10.1.3, and 12.2). The scope | 414 // is the entire function (ECMA-262, 3rd, 10.1.3, and 12.2). The scope |
| 392 // of a let declared variable is the scope of the immediately enclosing | 415 // of a let declared variable is the scope of the immediately enclosing |
| 393 // block. | 416 // block. |
| 394 int nvars = 0; // the number of variables declared | 417 int nvars = 0; // the number of variables declared |
| (...skipping 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1724 backing_store_.Add(static_cast<byte>((ascii_length >> 14) | 0x80u)); | 1747 backing_store_.Add(static_cast<byte>((ascii_length >> 14) | 0x80u)); |
| 1725 } | 1748 } |
| 1726 backing_store_.Add(static_cast<byte>((ascii_length >> 7) | 0x80u)); | 1749 backing_store_.Add(static_cast<byte>((ascii_length >> 7) | 0x80u)); |
| 1727 } | 1750 } |
| 1728 backing_store_.Add(static_cast<byte>(ascii_length & 0x7f)); | 1751 backing_store_.Add(static_cast<byte>(ascii_length & 0x7f)); |
| 1729 | 1752 |
| 1730 backing_store_.AddBlock(bytes); | 1753 backing_store_.AddBlock(bytes); |
| 1731 return backing_store_.EndSequence().start(); | 1754 return backing_store_.EndSequence().start(); |
| 1732 } | 1755 } |
| 1733 } } // v8::preparser | 1756 } } // v8::preparser |
| OLD | NEW |