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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 | 110 |
111 | 111 |
112 #define CHECK_OK ok); \ | 112 #define CHECK_OK ok); \ |
113 if (!*ok) return kUnknownSourceElements; \ | 113 if (!*ok) return kUnknownSourceElements; \ |
114 ((void)0 | 114 ((void)0 |
115 #define DUMMY ) // to make indentation work | 115 #define DUMMY ) // to make indentation work |
116 #undef DUMMY | 116 #undef DUMMY |
117 | 117 |
118 | 118 |
119 PreParser::Statement PreParser::ParseSourceElement(bool* ok) { | 119 PreParser::Statement PreParser::ParseSourceElement(bool* ok) { |
120 // (Ecma 262 5th Edition, clause 14): | |
121 // SourceElement: | |
122 // Statement | |
123 // FunctionDeclaration | |
124 // | |
125 // In harmony mode we allow additionally the following productions | |
126 // SourceElement: | |
127 // LetDeclaration | |
128 | |
120 switch (peek()) { | 129 switch (peek()) { |
130 case i::Token::FUNCTION: | |
131 return ParseFunctionDeclaration(ok); | |
121 case i::Token::LET: | 132 case i::Token::LET: |
122 return ParseVariableStatement(kSourceElement, ok); | 133 return ParseVariableStatement(kSourceElement, ok); |
123 default: | 134 default: |
124 return ParseStatement(ok); | 135 return ParseStatement(ok); |
125 } | 136 } |
126 } | 137 } |
127 | 138 |
128 | 139 |
129 PreParser::SourceElements PreParser::ParseSourceElements(int end_token, | 140 PreParser::SourceElements PreParser::ParseSourceElements(int end_token, |
130 bool* ok) { | 141 bool* ok) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 | 229 |
219 case i::Token::SWITCH: | 230 case i::Token::SWITCH: |
220 return ParseSwitchStatement(ok); | 231 return ParseSwitchStatement(ok); |
221 | 232 |
222 case i::Token::THROW: | 233 case i::Token::THROW: |
223 return ParseThrowStatement(ok); | 234 return ParseThrowStatement(ok); |
224 | 235 |
225 case i::Token::TRY: | 236 case i::Token::TRY: |
226 return ParseTryStatement(ok); | 237 return ParseTryStatement(ok); |
227 | 238 |
228 case i::Token::FUNCTION: | 239 case i::Token::FUNCTION: { |
229 return ParseFunctionDeclaration(ok); | 240 i::Scanner::Location start_location = scanner_->peek_location(); |
241 Statement statement = ParseFunctionDeclaration(CHECK_OK); | |
242 i::Scanner::Location end_location = scanner_->location(); | |
243 if (strict_mode()) { | |
244 ReportMessageAt(start_location.beg_pos, end_location.end_pos, | |
245 "strict_function", NULL); | |
246 *ok = false; | |
247 return Statement::Default(); | |
248 } else { | |
249 return statement; | |
250 } | |
251 } | |
230 | 252 |
231 case i::Token::DEBUGGER: | 253 case i::Token::DEBUGGER: |
232 return ParseDebuggerStatement(ok); | 254 return ParseDebuggerStatement(ok); |
233 | 255 |
234 default: | 256 default: |
235 return ParseExpressionOrLabelledStatement(ok); | 257 return ParseExpressionOrLabelledStatement(ok); |
236 } | 258 } |
237 } | 259 } |
238 | 260 |
239 | 261 |
(...skipping 24 matching lines...) Expand all Loading... | |
264 | 286 |
265 PreParser::Statement PreParser::ParseBlock(bool* ok) { | 287 PreParser::Statement PreParser::ParseBlock(bool* ok) { |
266 // Block :: | 288 // Block :: |
267 // '{' Statement* '}' | 289 // '{' Statement* '}' |
268 | 290 |
269 // Note that a Block does not introduce a new execution scope! | 291 // Note that a Block does not introduce a new execution scope! |
270 // (ECMA-262, 3rd, 12.2) | 292 // (ECMA-262, 3rd, 12.2) |
271 // | 293 // |
272 Expect(i::Token::LBRACE, CHECK_OK); | 294 Expect(i::Token::LBRACE, CHECK_OK); |
273 while (peek() != i::Token::RBRACE) { | 295 while (peek() != i::Token::RBRACE) { |
274 i::Scanner::Location start_location = scanner_->peek_location(); | 296 if (harmony_block_scoping_) { |
275 Statement statement = ParseSourceElement(CHECK_OK); | 297 ParseSourceElement(CHECK_OK); |
276 i::Scanner::Location end_location = scanner_->location(); | 298 } else { |
277 if (strict_mode() && statement.IsFunctionDeclaration()) { | 299 ParseStatement(CHECK_OK); |
278 ReportMessageAt(start_location.beg_pos, end_location.end_pos, | |
279 "strict_function", NULL); | |
280 *ok = false; | |
281 return Statement::Default(); | |
282 } | 300 } |
283 } | 301 } |
284 Expect(i::Token::RBRACE, ok); | 302 Expect(i::Token::RBRACE, ok); |
285 return Statement::Default(); | 303 return Statement::Default(); |
286 } | 304 } |
287 | 305 |
288 | 306 |
289 PreParser::Statement PreParser::ParseVariableStatement( | 307 PreParser::Statement PreParser::ParseVariableStatement( |
290 VariableDeclarationContext var_context, | 308 VariableDeclarationContext var_context, |
291 bool* ok) { | 309 bool* ok) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 | 384 |
367 | 385 |
368 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) { | 386 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) { |
369 // ExpressionStatement | LabelledStatement :: | 387 // ExpressionStatement | LabelledStatement :: |
370 // Expression ';' | 388 // Expression ';' |
371 // Identifier ':' Statement | 389 // Identifier ':' Statement |
372 | 390 |
373 Expression expr = ParseExpression(true, CHECK_OK); | 391 Expression expr = ParseExpression(true, CHECK_OK); |
374 if (expr.IsRawIdentifier()) { | 392 if (expr.IsRawIdentifier()) { |
375 if (peek() == i::Token::COLON && | 393 if (peek() == i::Token::COLON && |
376 (!strict_mode() || !expr.AsIdentifier().IsFutureReserved())) { | 394 (!strict_mode() || !expr.AsIdentifier().IsFutureReserved())) { |
Steven
2011/09/21 12:03:28
While we are already here. This check is off right
Lasse Reichstein
2011/09/21 20:11:45
We "should" disallow FutureReserved in non-strict
Steven
2011/09/21 22:42:07
Actually we do follow ES5 already and for labelled
| |
377 Consume(i::Token::COLON); | 395 Consume(i::Token::COLON); |
378 i::Scanner::Location start_location = scanner_->peek_location(); | 396 return ParseStatement(CHECK_OK); |
Lasse Reichstein
2011/09/21 10:29:34
CHECK_OK -> ok
We won't be checking the result aft
Lasse Reichstein
2011/09/21 10:29:34
So this is how we allow function declarations in a
Steven
2011/09/21 12:03:28
Yes. This is closely following the spec. We have
L
Steven
2011/09/21 12:03:28
Done.
| |
379 Statement statement = ParseStatement(CHECK_OK); | |
380 if (strict_mode() && statement.IsFunctionDeclaration()) { | |
381 i::Scanner::Location end_location = scanner_->location(); | |
382 ReportMessageAt(start_location.beg_pos, end_location.end_pos, | |
383 "strict_function", NULL); | |
384 *ok = false; | |
385 } | |
386 return Statement::Default(); | |
387 } | 397 } |
388 // Preparsing is disabled for extensions (because the extension details | 398 // Preparsing is disabled for extensions (because the extension details |
389 // aren't passed to lazily compiled functions), so we don't | 399 // aren't passed to lazily compiled functions), so we don't |
390 // accept "native function" in the preparser. | 400 // accept "native function" in the preparser. |
391 } | 401 } |
392 // Parsed expression statement. | 402 // Parsed expression statement. |
393 ExpectSemicolon(CHECK_OK); | 403 ExpectSemicolon(CHECK_OK); |
394 return Statement::ExpressionStatement(expr); | 404 return Statement::ExpressionStatement(expr); |
395 } | 405 } |
396 | 406 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
506 i::Token::Value token = peek(); | 516 i::Token::Value token = peek(); |
507 while (token != i::Token::RBRACE) { | 517 while (token != i::Token::RBRACE) { |
508 if (token == i::Token::CASE) { | 518 if (token == i::Token::CASE) { |
509 Expect(i::Token::CASE, CHECK_OK); | 519 Expect(i::Token::CASE, CHECK_OK); |
510 ParseExpression(true, CHECK_OK); | 520 ParseExpression(true, CHECK_OK); |
511 Expect(i::Token::COLON, CHECK_OK); | 521 Expect(i::Token::COLON, CHECK_OK); |
512 } else if (token == i::Token::DEFAULT) { | 522 } else if (token == i::Token::DEFAULT) { |
513 Expect(i::Token::DEFAULT, CHECK_OK); | 523 Expect(i::Token::DEFAULT, CHECK_OK); |
514 Expect(i::Token::COLON, CHECK_OK); | 524 Expect(i::Token::COLON, CHECK_OK); |
515 } else { | 525 } else { |
516 i::Scanner::Location start_location = scanner_->peek_location(); | 526 ParseStatement(CHECK_OK); |
517 Statement statement = ParseStatement(CHECK_OK); | |
518 if (strict_mode() && statement.IsFunctionDeclaration()) { | |
519 i::Scanner::Location end_location = scanner_->location(); | |
520 ReportMessageAt(start_location.beg_pos, end_location.end_pos, | |
521 "strict_function", NULL); | |
522 *ok = false; | |
523 return Statement::Default(); | |
524 } | |
525 } | 527 } |
526 token = peek(); | 528 token = peek(); |
527 } | 529 } |
528 Expect(i::Token::RBRACE, ok); | 530 Expect(i::Token::RBRACE, ok); |
529 return Statement::Default(); | 531 return Statement::Default(); |
530 } | 532 } |
531 | 533 |
532 | 534 |
533 PreParser::Statement PreParser::ParseDoWhileStatement(bool* ok) { | 535 PreParser::Statement PreParser::ParseDoWhileStatement(bool* ok) { |
534 // DoStatement :: | 536 // DoStatement :: |
(...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1670 backing_store_.Add(static_cast<byte>((ascii_length >> 14) | 0x80u)); | 1672 backing_store_.Add(static_cast<byte>((ascii_length >> 14) | 0x80u)); |
1671 } | 1673 } |
1672 backing_store_.Add(static_cast<byte>((ascii_length >> 7) | 0x80u)); | 1674 backing_store_.Add(static_cast<byte>((ascii_length >> 7) | 0x80u)); |
1673 } | 1675 } |
1674 backing_store_.Add(static_cast<byte>(ascii_length & 0x7f)); | 1676 backing_store_.Add(static_cast<byte>(ascii_length & 0x7f)); |
1675 | 1677 |
1676 backing_store_.AddBlock(bytes); | 1678 backing_store_.AddBlock(bytes); |
1677 return backing_store_.EndSequence().start(); | 1679 return backing_store_.EndSequence().start(); |
1678 } | 1680 } |
1679 } } // v8::preparser | 1681 } } // v8::preparser |
OLD | NEW |