OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast.h" | 8 #include "src/ast.h" |
9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 1331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1342 if (peek() == Token::RBRACE) break; | 1342 if (peek() == Token::RBRACE) break; |
1343 Expect(Token::COMMA, CHECK_OK); | 1343 Expect(Token::COMMA, CHECK_OK); |
1344 } | 1344 } |
1345 | 1345 |
1346 Expect(Token::RBRACE, CHECK_OK); | 1346 Expect(Token::RBRACE, CHECK_OK); |
1347 | 1347 |
1348 return 0; | 1348 return 0; |
1349 } | 1349 } |
1350 | 1350 |
1351 | 1351 |
1352 void* Parser::ParseNamedImports(ZoneList<const AstRawString*>* names, | 1352 void* Parser::ParseNamedImports(ZoneList<const AstRawString*>* import_names, |
1353 ZoneList<const AstRawString*>* local_names, | |
1353 bool* ok) { | 1354 bool* ok) { |
1354 // NamedImports : | 1355 // NamedImports : |
1355 // '{' '}' | 1356 // '{' '}' |
1356 // '{' ImportsList '}' | 1357 // '{' ImportsList '}' |
1357 // '{' ImportsList ',' '}' | 1358 // '{' ImportsList ',' '}' |
1358 // | 1359 // |
1359 // ImportsList : | 1360 // ImportsList : |
1360 // ImportSpecifier | 1361 // ImportSpecifier |
1361 // ImportsList ',' ImportSpecifier | 1362 // ImportsList ',' ImportSpecifier |
1362 // | 1363 // |
1363 // ImportSpecifier : | 1364 // ImportSpecifier : |
1364 // BindingIdentifier | 1365 // BindingIdentifier |
1365 // IdentifierName 'as' BindingIdentifier | 1366 // IdentifierName 'as' BindingIdentifier |
1366 | 1367 |
1367 Expect(Token::LBRACE, CHECK_OK); | 1368 Expect(Token::LBRACE, CHECK_OK); |
1368 | 1369 |
1369 Token::Value name_tok; | 1370 while (peek() != Token::RBRACE) { |
1370 while ((name_tok = peek()) != Token::RBRACE) { | 1371 const AstRawString* import_name = ParseIdentifierName(CHECK_OK); |
1371 const AstRawString* name = ParseIdentifierName(CHECK_OK); | 1372 const AstRawString* local_name = import_name; |
1372 const AstRawString* import_name = NULL; | |
1373 // In the presence of 'as', the left-side of the 'as' can | 1373 // In the presence of 'as', the left-side of the 'as' can |
1374 // be any IdentifierName. But without 'as', it must be a valid | 1374 // be any IdentifierName. But without 'as', it must be a valid |
1375 // BindingIdentiifer. | 1375 // BindingIdentifier. |
1376 if (CheckContextualKeyword(CStrVector("as"))) { | 1376 if (CheckContextualKeyword(CStrVector("as"))) { |
1377 import_name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); | 1377 local_name = ParseIdentifierName(CHECK_OK); |
1378 } else if (!Token::IsIdentifier(name_tok, STRICT, false)) { | 1378 } |
1379 if (!Token::IsIdentifier(scanner()->current_token(), STRICT, false)) { | |
1379 *ok = false; | 1380 *ok = false; |
1380 ReportMessageAt(scanner()->location(), "unexpected_reserved"); | 1381 ReportMessage("unexpected_reserved"); |
1381 return NULL; | 1382 return NULL; |
1382 } else if (IsEvalOrArguments(name)) { | 1383 } else if (IsEvalOrArguments(local_name)) { |
1383 *ok = false; | 1384 *ok = false; |
1384 ReportMessageAt(scanner()->location(), "strict_eval_arguments"); | 1385 ReportMessage("strict_eval_arguments"); |
1385 return NULL; | 1386 return NULL; |
1386 } | 1387 } |
1387 // TODO(ES6): Return the import_name as well as the name. | 1388 import_names->Add(import_name, zone()); |
1388 names->Add(name, zone()); | 1389 local_names->Add(local_name, zone()); |
1389 USE(import_name); | |
1390 if (peek() == Token::RBRACE) break; | 1390 if (peek() == Token::RBRACE) break; |
1391 Expect(Token::COMMA, CHECK_OK); | 1391 Expect(Token::COMMA, CHECK_OK); |
1392 } | 1392 } |
1393 | 1393 |
1394 Expect(Token::RBRACE, CHECK_OK); | 1394 Expect(Token::RBRACE, CHECK_OK); |
1395 | 1395 |
1396 return NULL; | 1396 return NULL; |
1397 } | 1397 } |
1398 | 1398 |
1399 | 1399 |
(...skipping 12 matching lines...) Expand all Loading... | |
1412 // NameSpaceImport : | 1412 // NameSpaceImport : |
1413 // '*' 'as' ImportedBinding | 1413 // '*' 'as' ImportedBinding |
1414 | 1414 |
1415 int pos = peek_position(); | 1415 int pos = peek_position(); |
1416 Expect(Token::IMPORT, CHECK_OK); | 1416 Expect(Token::IMPORT, CHECK_OK); |
1417 | 1417 |
1418 Token::Value tok = peek(); | 1418 Token::Value tok = peek(); |
1419 | 1419 |
1420 // 'import' ModuleSpecifier ';' | 1420 // 'import' ModuleSpecifier ';' |
1421 if (tok == Token::STRING) { | 1421 if (tok == Token::STRING) { |
1422 ParseModuleSpecifier(CHECK_OK); | 1422 Literal* module = ParseModuleSpecifier(CHECK_OK); |
arv (Not doing code reviews)
2015/02/25 15:33:07
nit: module_specifier
adamk
2015/02/25 19:02:33
Done.
| |
1423 ExpectSemicolon(CHECK_OK); | 1423 ExpectSemicolon(CHECK_OK); |
1424 // TODO(ES6): Add module to the requested modules of scope_->module(). | |
1425 USE(module); | |
1424 return factory()->NewEmptyStatement(pos); | 1426 return factory()->NewEmptyStatement(pos); |
1425 } | 1427 } |
1426 | 1428 |
1427 // Parse ImportedDefaultBinding if present. | 1429 // Parse ImportedDefaultBinding if present. |
1428 const AstRawString* imported_default_binding = NULL; | 1430 const AstRawString* imported_default_binding = NULL; |
1429 if (tok != Token::MUL && tok != Token::LBRACE) { | 1431 if (tok != Token::MUL && tok != Token::LBRACE) { |
1430 imported_default_binding = | 1432 imported_default_binding = |
1431 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); | 1433 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); |
1432 } | 1434 } |
1433 | 1435 |
1434 const AstRawString* module_instance_binding = NULL; | 1436 const AstRawString* module_instance_binding = NULL; |
1435 ZoneList<const AstRawString*> names(1, zone()); | 1437 ZoneList<const AstRawString*> local_names(1, zone()); |
1438 ZoneList<const AstRawString*> import_names(1, zone()); | |
1436 if (imported_default_binding == NULL || Check(Token::COMMA)) { | 1439 if (imported_default_binding == NULL || Check(Token::COMMA)) { |
1437 switch (peek()) { | 1440 switch (peek()) { |
1438 case Token::MUL: { | 1441 case Token::MUL: { |
1439 Consume(Token::MUL); | 1442 Consume(Token::MUL); |
1440 ExpectContextualKeyword(CStrVector("as"), CHECK_OK); | 1443 ExpectContextualKeyword(CStrVector("as"), CHECK_OK); |
1441 module_instance_binding = | 1444 module_instance_binding = |
1442 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); | 1445 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); |
1443 break; | 1446 break; |
1444 } | 1447 } |
1445 | 1448 |
1446 case Token::LBRACE: | 1449 case Token::LBRACE: |
1447 ParseNamedImports(&names, CHECK_OK); | 1450 ParseNamedImports(&import_names, &local_names, CHECK_OK); |
1448 break; | 1451 break; |
1449 | 1452 |
1450 default: | 1453 default: |
1451 *ok = false; | 1454 *ok = false; |
1452 ReportUnexpectedToken(scanner()->current_token()); | 1455 ReportUnexpectedToken(scanner()->current_token()); |
1453 return NULL; | 1456 return NULL; |
1454 } | 1457 } |
1455 } | 1458 } |
1456 | 1459 |
1457 ExpectContextualKeyword(CStrVector("from"), CHECK_OK); | 1460 ExpectContextualKeyword(CStrVector("from"), CHECK_OK); |
1458 Literal* module = ParseModuleSpecifier(CHECK_OK); | 1461 Literal* module = ParseModuleSpecifier(CHECK_OK); |
1459 USE(module); | 1462 USE(module); |
1460 | 1463 |
1461 ExpectSemicolon(CHECK_OK); | 1464 ExpectSemicolon(CHECK_OK); |
1462 | 1465 |
1463 if (module_instance_binding != NULL) { | 1466 if (module_instance_binding != NULL) { |
1464 // TODO(ES6): Bind name to the Module Instance Object of module. | 1467 // TODO(ES6): Bind name to the Module Instance Object of module. |
1465 } | 1468 } |
1466 | 1469 |
1467 if (imported_default_binding != NULL) { | 1470 if (imported_default_binding != NULL) { |
1468 // TODO(ES6): Add an appropriate declaration. | 1471 // TODO(ES6): Add an appropriate declaration. |
1469 } | 1472 } |
1470 | 1473 |
1471 for (int i = 0; i < names.length(); ++i) { | 1474 const int length = import_names.length(); |
1475 DCHECK_EQ(length, local_names.length()); | |
1476 for (int i = 0; i < length; ++i) { | |
1472 // TODO(ES6): Add an appropriate declaration for each name | 1477 // TODO(ES6): Add an appropriate declaration for each name |
1473 } | 1478 } |
1474 | 1479 |
1475 return factory()->NewEmptyStatement(pos); | 1480 return factory()->NewEmptyStatement(pos); |
1476 } | 1481 } |
1477 | 1482 |
1478 | 1483 |
1479 Statement* Parser::ParseExportDefault(bool* ok) { | 1484 Statement* Parser::ParseExportDefault(bool* ok) { |
1480 // Supports the following productions, starting after the 'default' token: | 1485 // Supports the following productions, starting after the 'default' token: |
1481 // 'export' 'default' FunctionDeclaration | 1486 // 'export' 'default' FunctionDeclaration |
(...skipping 3993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5475 } else { | 5480 } else { |
5476 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); | 5481 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); |
5477 running_hash = StringHasher::ComputeRunningHash(running_hash, data, | 5482 running_hash = StringHasher::ComputeRunningHash(running_hash, data, |
5478 raw_string->length()); | 5483 raw_string->length()); |
5479 } | 5484 } |
5480 } | 5485 } |
5481 | 5486 |
5482 return running_hash; | 5487 return running_hash; |
5483 } | 5488 } |
5484 } } // namespace v8::internal | 5489 } } // namespace v8::internal |
OLD | NEW |