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 1320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1331 if (peek() == Token::RBRACE) break; | 1331 if (peek() == Token::RBRACE) break; |
1332 Expect(Token::COMMA, CHECK_OK); | 1332 Expect(Token::COMMA, CHECK_OK); |
1333 } | 1333 } |
1334 | 1334 |
1335 Expect(Token::RBRACE, CHECK_OK); | 1335 Expect(Token::RBRACE, CHECK_OK); |
1336 | 1336 |
1337 return 0; | 1337 return 0; |
1338 } | 1338 } |
1339 | 1339 |
1340 | 1340 |
1341 void* Parser::ParseNamedImports(ZoneList<const AstRawString*>* names, | 1341 void* Parser::ParseNamedImports(ZoneList<const AstRawString*>* import_names, |
| 1342 ZoneList<const AstRawString*>* local_names, |
1342 bool* ok) { | 1343 bool* ok) { |
1343 // NamedImports : | 1344 // NamedImports : |
1344 // '{' '}' | 1345 // '{' '}' |
1345 // '{' ImportsList '}' | 1346 // '{' ImportsList '}' |
1346 // '{' ImportsList ',' '}' | 1347 // '{' ImportsList ',' '}' |
1347 // | 1348 // |
1348 // ImportsList : | 1349 // ImportsList : |
1349 // ImportSpecifier | 1350 // ImportSpecifier |
1350 // ImportsList ',' ImportSpecifier | 1351 // ImportsList ',' ImportSpecifier |
1351 // | 1352 // |
1352 // ImportSpecifier : | 1353 // ImportSpecifier : |
1353 // BindingIdentifier | 1354 // BindingIdentifier |
1354 // IdentifierName 'as' BindingIdentifier | 1355 // IdentifierName 'as' BindingIdentifier |
1355 | 1356 |
1356 Expect(Token::LBRACE, CHECK_OK); | 1357 Expect(Token::LBRACE, CHECK_OK); |
1357 | 1358 |
1358 Token::Value name_tok; | 1359 while (peek() != Token::RBRACE) { |
1359 while ((name_tok = peek()) != Token::RBRACE) { | 1360 const AstRawString* import_name = ParseIdentifierName(CHECK_OK); |
1360 const AstRawString* name = ParseIdentifierName(CHECK_OK); | 1361 const AstRawString* local_name = import_name; |
1361 const AstRawString* import_name = NULL; | |
1362 // In the presence of 'as', the left-side of the 'as' can | 1362 // In the presence of 'as', the left-side of the 'as' can |
1363 // be any IdentifierName. But without 'as', it must be a valid | 1363 // be any IdentifierName. But without 'as', it must be a valid |
1364 // BindingIdentiifer. | 1364 // BindingIdentifier. |
1365 if (CheckContextualKeyword(CStrVector("as"))) { | 1365 if (CheckContextualKeyword(CStrVector("as"))) { |
1366 import_name = ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); | 1366 local_name = ParseIdentifierName(CHECK_OK); |
1367 } else if (!Token::IsIdentifier(name_tok, STRICT, false)) { | 1367 } |
| 1368 if (!Token::IsIdentifier(scanner()->current_token(), STRICT, false)) { |
1368 *ok = false; | 1369 *ok = false; |
1369 ReportMessageAt(scanner()->location(), "unexpected_reserved"); | 1370 ReportMessage("unexpected_reserved"); |
1370 return NULL; | 1371 return NULL; |
1371 } else if (IsEvalOrArguments(name)) { | 1372 } else if (IsEvalOrArguments(local_name)) { |
1372 *ok = false; | 1373 *ok = false; |
1373 ReportMessageAt(scanner()->location(), "strict_eval_arguments"); | 1374 ReportMessage("strict_eval_arguments"); |
1374 return NULL; | 1375 return NULL; |
1375 } | 1376 } |
1376 // TODO(ES6): Return the import_name as well as the name. | 1377 import_names->Add(import_name, zone()); |
1377 names->Add(name, zone()); | 1378 local_names->Add(local_name, zone()); |
1378 USE(import_name); | |
1379 if (peek() == Token::RBRACE) break; | 1379 if (peek() == Token::RBRACE) break; |
1380 Expect(Token::COMMA, CHECK_OK); | 1380 Expect(Token::COMMA, CHECK_OK); |
1381 } | 1381 } |
1382 | 1382 |
1383 Expect(Token::RBRACE, CHECK_OK); | 1383 Expect(Token::RBRACE, CHECK_OK); |
1384 | 1384 |
1385 return NULL; | 1385 return NULL; |
1386 } | 1386 } |
1387 | 1387 |
1388 | 1388 |
(...skipping 12 matching lines...) Expand all Loading... |
1401 // NameSpaceImport : | 1401 // NameSpaceImport : |
1402 // '*' 'as' ImportedBinding | 1402 // '*' 'as' ImportedBinding |
1403 | 1403 |
1404 int pos = peek_position(); | 1404 int pos = peek_position(); |
1405 Expect(Token::IMPORT, CHECK_OK); | 1405 Expect(Token::IMPORT, CHECK_OK); |
1406 | 1406 |
1407 Token::Value tok = peek(); | 1407 Token::Value tok = peek(); |
1408 | 1408 |
1409 // 'import' ModuleSpecifier ';' | 1409 // 'import' ModuleSpecifier ';' |
1410 if (tok == Token::STRING) { | 1410 if (tok == Token::STRING) { |
1411 ParseModuleSpecifier(CHECK_OK); | 1411 Literal* module_specifier = ParseModuleSpecifier(CHECK_OK); |
1412 ExpectSemicolon(CHECK_OK); | 1412 ExpectSemicolon(CHECK_OK); |
| 1413 // TODO(ES6): Add module to the requested modules of scope_->module(). |
| 1414 USE(module_specifier); |
1413 return factory()->NewEmptyStatement(pos); | 1415 return factory()->NewEmptyStatement(pos); |
1414 } | 1416 } |
1415 | 1417 |
1416 // Parse ImportedDefaultBinding if present. | 1418 // Parse ImportedDefaultBinding if present. |
1417 const AstRawString* imported_default_binding = NULL; | 1419 const AstRawString* imported_default_binding = NULL; |
1418 if (tok != Token::MUL && tok != Token::LBRACE) { | 1420 if (tok != Token::MUL && tok != Token::LBRACE) { |
1419 imported_default_binding = | 1421 imported_default_binding = |
1420 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); | 1422 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); |
1421 } | 1423 } |
1422 | 1424 |
1423 const AstRawString* module_instance_binding = NULL; | 1425 const AstRawString* module_instance_binding = NULL; |
1424 ZoneList<const AstRawString*> names(1, zone()); | 1426 ZoneList<const AstRawString*> local_names(1, zone()); |
| 1427 ZoneList<const AstRawString*> import_names(1, zone()); |
1425 if (imported_default_binding == NULL || Check(Token::COMMA)) { | 1428 if (imported_default_binding == NULL || Check(Token::COMMA)) { |
1426 switch (peek()) { | 1429 switch (peek()) { |
1427 case Token::MUL: { | 1430 case Token::MUL: { |
1428 Consume(Token::MUL); | 1431 Consume(Token::MUL); |
1429 ExpectContextualKeyword(CStrVector("as"), CHECK_OK); | 1432 ExpectContextualKeyword(CStrVector("as"), CHECK_OK); |
1430 module_instance_binding = | 1433 module_instance_binding = |
1431 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); | 1434 ParseIdentifier(kDontAllowEvalOrArguments, CHECK_OK); |
1432 break; | 1435 break; |
1433 } | 1436 } |
1434 | 1437 |
1435 case Token::LBRACE: | 1438 case Token::LBRACE: |
1436 ParseNamedImports(&names, CHECK_OK); | 1439 ParseNamedImports(&import_names, &local_names, CHECK_OK); |
1437 break; | 1440 break; |
1438 | 1441 |
1439 default: | 1442 default: |
1440 *ok = false; | 1443 *ok = false; |
1441 ReportUnexpectedToken(scanner()->current_token()); | 1444 ReportUnexpectedToken(scanner()->current_token()); |
1442 return NULL; | 1445 return NULL; |
1443 } | 1446 } |
1444 } | 1447 } |
1445 | 1448 |
1446 ExpectContextualKeyword(CStrVector("from"), CHECK_OK); | 1449 ExpectContextualKeyword(CStrVector("from"), CHECK_OK); |
1447 Literal* module = ParseModuleSpecifier(CHECK_OK); | 1450 Literal* module = ParseModuleSpecifier(CHECK_OK); |
1448 USE(module); | 1451 USE(module); |
1449 | 1452 |
1450 ExpectSemicolon(CHECK_OK); | 1453 ExpectSemicolon(CHECK_OK); |
1451 | 1454 |
1452 if (module_instance_binding != NULL) { | 1455 if (module_instance_binding != NULL) { |
1453 // TODO(ES6): Bind name to the Module Instance Object of module. | 1456 // TODO(ES6): Bind name to the Module Instance Object of module. |
1454 } | 1457 } |
1455 | 1458 |
1456 if (imported_default_binding != NULL) { | 1459 if (imported_default_binding != NULL) { |
1457 // TODO(ES6): Add an appropriate declaration. | 1460 // TODO(ES6): Add an appropriate declaration. |
1458 } | 1461 } |
1459 | 1462 |
1460 for (int i = 0; i < names.length(); ++i) { | 1463 const int length = import_names.length(); |
| 1464 DCHECK_EQ(length, local_names.length()); |
| 1465 for (int i = 0; i < length; ++i) { |
1461 // TODO(ES6): Add an appropriate declaration for each name | 1466 // TODO(ES6): Add an appropriate declaration for each name |
1462 } | 1467 } |
1463 | 1468 |
1464 return factory()->NewEmptyStatement(pos); | 1469 return factory()->NewEmptyStatement(pos); |
1465 } | 1470 } |
1466 | 1471 |
1467 | 1472 |
1468 Statement* Parser::ParseExportDefault(bool* ok) { | 1473 Statement* Parser::ParseExportDefault(bool* ok) { |
1469 // Supports the following productions, starting after the 'default' token: | 1474 // Supports the following productions, starting after the 'default' token: |
1470 // 'export' 'default' FunctionDeclaration | 1475 // 'export' 'default' FunctionDeclaration |
(...skipping 3943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5414 } else { | 5419 } else { |
5415 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); | 5420 const uc16* data = reinterpret_cast<const uc16*>(raw_string->raw_data()); |
5416 running_hash = StringHasher::ComputeRunningHash(running_hash, data, | 5421 running_hash = StringHasher::ComputeRunningHash(running_hash, data, |
5417 raw_string->length()); | 5422 raw_string->length()); |
5418 } | 5423 } |
5419 } | 5424 } |
5420 | 5425 |
5421 return running_hash; | 5426 return running_hash; |
5422 } | 5427 } |
5423 } } // namespace v8::internal | 5428 } } // namespace v8::internal |
OLD | NEW |