| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 118 |
| 119 PreParser::Statement PreParser::ParseSourceElement(bool* ok) { | 119 PreParser::Statement PreParser::ParseSourceElement(bool* ok) { |
| 120 // (Ecma 262 5th Edition, clause 14): | 120 // (Ecma 262 5th Edition, clause 14): |
| 121 // SourceElement: | 121 // SourceElement: |
| 122 // Statement | 122 // Statement |
| 123 // FunctionDeclaration | 123 // FunctionDeclaration |
| 124 // | 124 // |
| 125 // In harmony mode we allow additionally the following productions | 125 // In harmony mode we allow additionally the following productions |
| 126 // SourceElement: | 126 // SourceElement: |
| 127 // LetDeclaration | 127 // LetDeclaration |
| 128 // ConstDeclaration |
| 128 | 129 |
| 129 switch (peek()) { | 130 switch (peek()) { |
| 130 case i::Token::FUNCTION: | 131 case i::Token::FUNCTION: |
| 131 return ParseFunctionDeclaration(ok); | 132 return ParseFunctionDeclaration(ok); |
| 132 case i::Token::LET: | 133 case i::Token::LET: |
| 134 case i::Token::CONST: |
| 133 return ParseVariableStatement(kSourceElement, ok); | 135 return ParseVariableStatement(kSourceElement, ok); |
| 134 default: | 136 default: |
| 135 return ParseStatement(ok); | 137 return ParseStatement(ok); |
| 136 } | 138 } |
| 137 } | 139 } |
| 138 | 140 |
| 139 | 141 |
| 140 PreParser::SourceElements PreParser::ParseSourceElements(int end_token, | 142 PreParser::SourceElements PreParser::ParseSourceElements(int end_token, |
| 141 bool* ok) { | 143 bool* ok) { |
| 142 // SourceElements :: | 144 // SourceElements :: |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 // *var is untouched; in particular, it is the caller's responsibility | 326 // *var is untouched; in particular, it is the caller's responsibility |
| 325 // to initialize it properly. This mechanism is also used for the parsing | 327 // to initialize it properly. This mechanism is also used for the parsing |
| 326 // of 'for-in' loops. | 328 // of 'for-in' loops. |
| 327 PreParser::Statement PreParser::ParseVariableDeclarations( | 329 PreParser::Statement PreParser::ParseVariableDeclarations( |
| 328 VariableDeclarationContext var_context, | 330 VariableDeclarationContext var_context, |
| 329 VariableDeclarationProperties* decl_props, | 331 VariableDeclarationProperties* decl_props, |
| 330 int* num_decl, | 332 int* num_decl, |
| 331 bool* ok) { | 333 bool* ok) { |
| 332 // VariableDeclarations :: | 334 // VariableDeclarations :: |
| 333 // ('var' | 'const') (Identifier ('=' AssignmentExpression)?)+[','] | 335 // ('var' | 'const') (Identifier ('=' AssignmentExpression)?)+[','] |
| 334 | 336 // |
| 337 // The ES6 Draft Rev3 specifies the following grammar for const declarations |
| 338 // |
| 339 // ConstDeclaration :: |
| 340 // const ConstBinding (',' ConstBinding)* ';' |
| 341 // ConstBinding :: |
| 342 // Identifier '=' AssignmentExpression |
| 343 // |
| 344 // TODO(ES6): |
| 345 // ConstBinding :: |
| 346 // BindingPattern '=' AssignmentExpression |
| 347 bool require_initializer = false; |
| 335 if (peek() == i::Token::VAR) { | 348 if (peek() == i::Token::VAR) { |
| 336 Consume(i::Token::VAR); | 349 Consume(i::Token::VAR); |
| 337 } else if (peek() == i::Token::CONST) { | 350 } else if (peek() == i::Token::CONST) { |
| 338 if (strict_mode()) { | 351 if (harmony_scoping_) { |
| 352 if (var_context != kSourceElement && |
| 353 var_context != kForStatement) { |
| 354 i::Scanner::Location location = scanner_->peek_location(); |
| 355 ReportMessageAt(location.beg_pos, location.end_pos, |
| 356 "unprotected_const", NULL); |
| 357 *ok = false; |
| 358 return Statement::Default(); |
| 359 } |
| 360 require_initializer = true; |
| 361 } else if (strict_mode()) { |
| 339 i::Scanner::Location location = scanner_->peek_location(); | 362 i::Scanner::Location location = scanner_->peek_location(); |
| 340 ReportMessageAt(location, "strict_const", NULL); | 363 ReportMessageAt(location, "strict_const", NULL); |
| 341 *ok = false; | 364 *ok = false; |
| 342 return Statement::Default(); | 365 return Statement::Default(); |
| 343 } | 366 } |
| 344 Consume(i::Token::CONST); | 367 Consume(i::Token::CONST); |
| 345 } else if (peek() == i::Token::LET) { | 368 } else if (peek() == i::Token::LET) { |
| 346 if (var_context != kSourceElement && | 369 if (var_context != kSourceElement && |
| 347 var_context != kForStatement) { | 370 var_context != kForStatement) { |
| 348 i::Scanner::Location location = scanner_->peek_location(); | 371 i::Scanner::Location location = scanner_->peek_location(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 367 if (nvars > 0) Consume(i::Token::COMMA); | 390 if (nvars > 0) Consume(i::Token::COMMA); |
| 368 Identifier identifier = ParseIdentifier(CHECK_OK); | 391 Identifier identifier = ParseIdentifier(CHECK_OK); |
| 369 if (strict_mode() && !identifier.IsValidStrictVariable()) { | 392 if (strict_mode() && !identifier.IsValidStrictVariable()) { |
| 370 StrictModeIdentifierViolation(scanner_->location(), | 393 StrictModeIdentifierViolation(scanner_->location(), |
| 371 "strict_var_name", | 394 "strict_var_name", |
| 372 identifier, | 395 identifier, |
| 373 ok); | 396 ok); |
| 374 return Statement::Default(); | 397 return Statement::Default(); |
| 375 } | 398 } |
| 376 nvars++; | 399 nvars++; |
| 377 if (peek() == i::Token::ASSIGN) { | 400 if (peek() == i::Token::ASSIGN || require_initializer) { |
| 378 Expect(i::Token::ASSIGN, CHECK_OK); | 401 Expect(i::Token::ASSIGN, CHECK_OK); |
| 379 ParseAssignmentExpression(var_context != kForStatement, CHECK_OK); | 402 ParseAssignmentExpression(var_context != kForStatement, CHECK_OK); |
| 380 if (decl_props != NULL) *decl_props = kHasInitializers; | 403 if (decl_props != NULL) *decl_props = kHasInitializers; |
| 381 } | 404 } |
| 382 } while (peek() == i::Token::COMMA); | 405 } while (peek() == i::Token::COMMA); |
| 383 | 406 |
| 384 if (num_decl != NULL) *num_decl = nvars; | 407 if (num_decl != NULL) *num_decl = nvars; |
| 385 return Statement::Default(); | 408 return Statement::Default(); |
| 386 } | 409 } |
| 387 | 410 |
| (...skipping 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1691 backing_store_.Add(static_cast<byte>((ascii_length >> 14) | 0x80u)); | 1714 backing_store_.Add(static_cast<byte>((ascii_length >> 14) | 0x80u)); |
| 1692 } | 1715 } |
| 1693 backing_store_.Add(static_cast<byte>((ascii_length >> 7) | 0x80u)); | 1716 backing_store_.Add(static_cast<byte>((ascii_length >> 7) | 0x80u)); |
| 1694 } | 1717 } |
| 1695 backing_store_.Add(static_cast<byte>(ascii_length & 0x7f)); | 1718 backing_store_.Add(static_cast<byte>(ascii_length & 0x7f)); |
| 1696 | 1719 |
| 1697 backing_store_.AddBlock(bytes); | 1720 backing_store_.AddBlock(bytes); |
| 1698 return backing_store_.EndSequence().start(); | 1721 return backing_store_.EndSequence().start(); |
| 1699 } | 1722 } |
| 1700 } } // v8::preparser | 1723 } } // v8::preparser |
| OLD | NEW |