| 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 | 202 |
| 203 case i::Token::THROW: | 203 case i::Token::THROW: |
| 204 return ParseThrowStatement(ok); | 204 return ParseThrowStatement(ok); |
| 205 | 205 |
| 206 case i::Token::TRY: | 206 case i::Token::TRY: |
| 207 return ParseTryStatement(ok); | 207 return ParseTryStatement(ok); |
| 208 | 208 |
| 209 case i::Token::FUNCTION: | 209 case i::Token::FUNCTION: |
| 210 return ParseFunctionDeclaration(ok); | 210 return ParseFunctionDeclaration(ok); |
| 211 | 211 |
| 212 case i::Token::NATIVE: | |
| 213 return ParseNativeDeclaration(ok); | |
| 214 | |
| 215 case i::Token::DEBUGGER: | 212 case i::Token::DEBUGGER: |
| 216 return ParseDebuggerStatement(ok); | 213 return ParseDebuggerStatement(ok); |
| 217 | 214 |
| 218 default: | 215 default: |
| 219 return ParseExpressionOrLabelledStatement(ok); | 216 return ParseExpressionOrLabelledStatement(ok); |
| 220 } | 217 } |
| 221 } | 218 } |
| 222 | 219 |
| 223 | 220 |
| 224 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { | 221 PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 239 if (identifier.IsFutureReserved()) { | 236 if (identifier.IsFutureReserved()) { |
| 240 type = "strict_reserved_word"; | 237 type = "strict_reserved_word"; |
| 241 } | 238 } |
| 242 ReportMessageAt(location.beg_pos, location.end_pos, type, NULL); | 239 ReportMessageAt(location.beg_pos, location.end_pos, type, NULL); |
| 243 *ok = false; | 240 *ok = false; |
| 244 } | 241 } |
| 245 return Statement::FunctionDeclaration(); | 242 return Statement::FunctionDeclaration(); |
| 246 } | 243 } |
| 247 | 244 |
| 248 | 245 |
| 249 // Language extension which is only enabled for source files loaded | |
| 250 // through the API's extension mechanism. A native function | |
| 251 // declaration is resolved by looking up the function through a | |
| 252 // callback provided by the extension. | |
| 253 PreParser::Statement PreParser::ParseNativeDeclaration(bool* ok) { | |
| 254 Expect(i::Token::NATIVE, CHECK_OK); | |
| 255 Expect(i::Token::FUNCTION, CHECK_OK); | |
| 256 ParseIdentifier(CHECK_OK); | |
| 257 Expect(i::Token::LPAREN, CHECK_OK); | |
| 258 bool done = (peek() == i::Token::RPAREN); | |
| 259 while (!done) { | |
| 260 ParseIdentifier(CHECK_OK); | |
| 261 done = (peek() == i::Token::RPAREN); | |
| 262 if (!done) { | |
| 263 Expect(i::Token::COMMA, CHECK_OK); | |
| 264 } | |
| 265 } | |
| 266 Expect(i::Token::RPAREN, CHECK_OK); | |
| 267 Expect(i::Token::SEMICOLON, CHECK_OK); | |
| 268 return Statement::Default(); | |
| 269 } | |
| 270 | |
| 271 | |
| 272 PreParser::Statement PreParser::ParseBlock(bool* ok) { | 246 PreParser::Statement PreParser::ParseBlock(bool* ok) { |
| 273 // Block :: | 247 // Block :: |
| 274 // '{' Statement* '}' | 248 // '{' Statement* '}' |
| 275 | 249 |
| 276 // Note that a Block does not introduce a new execution scope! | 250 // Note that a Block does not introduce a new execution scope! |
| 277 // (ECMA-262, 3rd, 12.2) | 251 // (ECMA-262, 3rd, 12.2) |
| 278 // | 252 // |
| 279 Expect(i::Token::LBRACE, CHECK_OK); | 253 Expect(i::Token::LBRACE, CHECK_OK); |
| 280 while (peek() != i::Token::RBRACE) { | 254 while (peek() != i::Token::RBRACE) { |
| 281 i::Scanner::Location start_location = scanner_->peek_location(); | 255 i::Scanner::Location start_location = scanner_->peek_location(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 return Statement::Default(); | 329 return Statement::Default(); |
| 356 } | 330 } |
| 357 | 331 |
| 358 | 332 |
| 359 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) { | 333 PreParser::Statement PreParser::ParseExpressionOrLabelledStatement(bool* ok) { |
| 360 // ExpressionStatement | LabelledStatement :: | 334 // ExpressionStatement | LabelledStatement :: |
| 361 // Expression ';' | 335 // Expression ';' |
| 362 // Identifier ':' Statement | 336 // Identifier ':' Statement |
| 363 | 337 |
| 364 Expression expr = ParseExpression(true, CHECK_OK); | 338 Expression expr = ParseExpression(true, CHECK_OK); |
| 365 if (peek() == i::Token::COLON && expr.IsRawIdentifier()) { | 339 if (expr.IsRawIdentifier()) { |
| 366 if (!strict_mode() || !expr.AsIdentifier().IsFutureReserved()) { | 340 if (peek() == i::Token::COLON && |
| 341 (!strict_mode() || !expr.AsIdentifier().IsFutureReserved())) { |
| 367 Consume(i::Token::COLON); | 342 Consume(i::Token::COLON); |
| 368 i::Scanner::Location start_location = scanner_->peek_location(); | 343 i::Scanner::Location start_location = scanner_->peek_location(); |
| 369 Statement statement = ParseStatement(CHECK_OK); | 344 Statement statement = ParseStatement(CHECK_OK); |
| 370 if (strict_mode() && statement.IsFunctionDeclaration()) { | 345 if (strict_mode() && statement.IsFunctionDeclaration()) { |
| 371 i::Scanner::Location end_location = scanner_->location(); | 346 i::Scanner::Location end_location = scanner_->location(); |
| 372 ReportMessageAt(start_location.beg_pos, end_location.end_pos, | 347 ReportMessageAt(start_location.beg_pos, end_location.end_pos, |
| 373 "strict_function", NULL); | 348 "strict_function", NULL); |
| 374 *ok = false; | 349 *ok = false; |
| 375 } | 350 } |
| 376 return Statement::Default(); | 351 return Statement::Default(); |
| 377 } | 352 } |
| 353 // Preparsing is disabled for extensions (because the extension details |
| 354 // aren't passed to lazily compiled functions), so we don't |
| 355 // accept "native function" in the preparser. |
| 378 } | 356 } |
| 379 // Parsed expression statement. | 357 // Parsed expression statement. |
| 380 ExpectSemicolon(CHECK_OK); | 358 ExpectSemicolon(CHECK_OK); |
| 381 return Statement::ExpressionStatement(expr); | 359 return Statement::ExpressionStatement(expr); |
| 382 } | 360 } |
| 383 | 361 |
| 384 | 362 |
| 385 PreParser::Statement PreParser::ParseIfStatement(bool* ok) { | 363 PreParser::Statement PreParser::ParseIfStatement(bool* ok) { |
| 386 // IfStatement :: | 364 // IfStatement :: |
| 387 // 'if' '(' Expression ')' Statement ('else' Statement)? | 365 // 'if' '(' Expression ')' Statement ('else' Statement)? |
| (...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1442 } | 1420 } |
| 1443 return result; | 1421 return result; |
| 1444 } | 1422 } |
| 1445 | 1423 |
| 1446 bool PreParser::peek_any_identifier() { | 1424 bool PreParser::peek_any_identifier() { |
| 1447 i::Token::Value next = peek(); | 1425 i::Token::Value next = peek(); |
| 1448 return next == i::Token::IDENTIFIER || | 1426 return next == i::Token::IDENTIFIER || |
| 1449 next == i::Token::FUTURE_RESERVED_WORD; | 1427 next == i::Token::FUTURE_RESERVED_WORD; |
| 1450 } | 1428 } |
| 1451 } } // v8::preparser | 1429 } } // v8::preparser |
| OLD | NEW |