OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1326 Statement* stat = ParseModuleElement(NULL, CHECK_OK); | 1326 Statement* stat = ParseModuleElement(NULL, CHECK_OK); |
1327 if (stat && !stat->IsEmpty()) { | 1327 if (stat && !stat->IsEmpty()) { |
1328 body->AddStatement(stat); | 1328 body->AddStatement(stat); |
1329 block_finder.Update(stat); | 1329 block_finder.Update(stat); |
1330 } | 1330 } |
1331 } | 1331 } |
1332 } | 1332 } |
1333 | 1333 |
1334 Expect(Token::RBRACE, CHECK_OK); | 1334 Expect(Token::RBRACE, CHECK_OK); |
1335 scope->set_end_position(scanner().location().end_pos); | 1335 scope->set_end_position(scanner().location().end_pos); |
1336 body->set_block_scope(scope); | 1336 body->set_scope(scope); |
1337 | 1337 |
1338 scope->interface()->Freeze(ok); | 1338 // Instance objects have to be created ahead of time (before code generation |
| 1339 // linking them) because of potentially cyclic references between them. |
| 1340 // We create them here, to avoid another pass over the AST. |
| 1341 Interface* interface = scope->interface(); |
| 1342 interface->MakeModule(ok); |
1339 ASSERT(ok); | 1343 ASSERT(ok); |
1340 return factory()->NewModuleLiteral(body, scope->interface()); | 1344 interface->MakeSingleton(Isolate::Current()->factory()->NewJSModule(), ok); |
| 1345 ASSERT(ok); |
| 1346 interface->Freeze(ok); |
| 1347 ASSERT(ok); |
| 1348 return factory()->NewModuleLiteral(body, interface); |
1341 } | 1349 } |
1342 | 1350 |
1343 | 1351 |
1344 Module* Parser::ParseModulePath(bool* ok) { | 1352 Module* Parser::ParseModulePath(bool* ok) { |
1345 // ModulePath: | 1353 // ModulePath: |
1346 // Identifier | 1354 // Identifier |
1347 // ModulePath '.' Identifier | 1355 // ModulePath '.' Identifier |
1348 | 1356 |
1349 Module* result = ParseModuleVariable(CHECK_OK); | 1357 Module* result = ParseModuleVariable(CHECK_OK); |
1350 while (Check(Token::PERIOD)) { | 1358 while (Check(Token::PERIOD)) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1396 // String | 1404 // String |
1397 | 1405 |
1398 Expect(Token::STRING, CHECK_OK); | 1406 Expect(Token::STRING, CHECK_OK); |
1399 Handle<String> symbol = GetSymbol(CHECK_OK); | 1407 Handle<String> symbol = GetSymbol(CHECK_OK); |
1400 | 1408 |
1401 // TODO(ES6): Request JS resource from environment... | 1409 // TODO(ES6): Request JS resource from environment... |
1402 | 1410 |
1403 #ifdef DEBUG | 1411 #ifdef DEBUG |
1404 if (FLAG_print_interface_details) PrintF("# Url "); | 1412 if (FLAG_print_interface_details) PrintF("# Url "); |
1405 #endif | 1413 #endif |
1406 return factory()->NewModuleUrl(symbol); | 1414 |
| 1415 Module* result = factory()->NewModuleUrl(symbol); |
| 1416 Interface* interface = result->interface(); |
| 1417 interface->MakeSingleton(Isolate::Current()->factory()->NewJSModule(), ok); |
| 1418 ASSERT(ok); |
| 1419 interface->Freeze(ok); |
| 1420 ASSERT(ok); |
| 1421 return result; |
1407 } | 1422 } |
1408 | 1423 |
1409 | 1424 |
1410 Module* Parser::ParseModuleSpecifier(bool* ok) { | 1425 Module* Parser::ParseModuleSpecifier(bool* ok) { |
1411 // ModuleSpecifier: | 1426 // ModuleSpecifier: |
1412 // String | 1427 // String |
1413 // ModulePath | 1428 // ModulePath |
1414 | 1429 |
1415 if (peek() == Token::STRING) { | 1430 if (peek() == Token::STRING) { |
1416 return ParseModuleUrl(ok); | 1431 return ParseModuleUrl(ok); |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2008 Statement* stat = ParseBlockElement(NULL, CHECK_OK); | 2023 Statement* stat = ParseBlockElement(NULL, CHECK_OK); |
2009 if (stat && !stat->IsEmpty()) { | 2024 if (stat && !stat->IsEmpty()) { |
2010 body->AddStatement(stat); | 2025 body->AddStatement(stat); |
2011 block_finder.Update(stat); | 2026 block_finder.Update(stat); |
2012 } | 2027 } |
2013 } | 2028 } |
2014 } | 2029 } |
2015 Expect(Token::RBRACE, CHECK_OK); | 2030 Expect(Token::RBRACE, CHECK_OK); |
2016 block_scope->set_end_position(scanner().location().end_pos); | 2031 block_scope->set_end_position(scanner().location().end_pos); |
2017 block_scope = block_scope->FinalizeBlockScope(); | 2032 block_scope = block_scope->FinalizeBlockScope(); |
2018 body->set_block_scope(block_scope); | 2033 body->set_scope(block_scope); |
2019 return body; | 2034 return body; |
2020 } | 2035 } |
2021 | 2036 |
2022 | 2037 |
2023 Block* Parser::ParseVariableStatement(VariableDeclarationContext var_context, | 2038 Block* Parser::ParseVariableStatement(VariableDeclarationContext var_context, |
2024 ZoneStringList* names, | 2039 ZoneStringList* names, |
2025 bool* ok) { | 2040 bool* ok) { |
2026 // VariableStatement :: | 2041 // VariableStatement :: |
2027 // VariableDeclarations ';' | 2042 // VariableDeclarations ';' |
2028 | 2043 |
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2910 Token::ASSIGN, each, temp_proxy, RelocInfo::kNoPosition); | 2925 Token::ASSIGN, each, temp_proxy, RelocInfo::kNoPosition); |
2911 Statement* assignment_statement = | 2926 Statement* assignment_statement = |
2912 factory()->NewExpressionStatement(assignment); | 2927 factory()->NewExpressionStatement(assignment); |
2913 body_block->AddStatement(variable_statement); | 2928 body_block->AddStatement(variable_statement); |
2914 body_block->AddStatement(assignment_statement); | 2929 body_block->AddStatement(assignment_statement); |
2915 body_block->AddStatement(body); | 2930 body_block->AddStatement(body); |
2916 loop->Initialize(temp_proxy, enumerable, body_block); | 2931 loop->Initialize(temp_proxy, enumerable, body_block); |
2917 top_scope_ = saved_scope; | 2932 top_scope_ = saved_scope; |
2918 for_scope->set_end_position(scanner().location().end_pos); | 2933 for_scope->set_end_position(scanner().location().end_pos); |
2919 for_scope = for_scope->FinalizeBlockScope(); | 2934 for_scope = for_scope->FinalizeBlockScope(); |
2920 body_block->set_block_scope(for_scope); | 2935 body_block->set_scope(for_scope); |
2921 // Parsed for-in loop w/ let declaration. | 2936 // Parsed for-in loop w/ let declaration. |
2922 return loop; | 2937 return loop; |
2923 | 2938 |
2924 } else { | 2939 } else { |
2925 init = variable_statement; | 2940 init = variable_statement; |
2926 } | 2941 } |
2927 } else { | 2942 } else { |
2928 Expression* expression = ParseExpression(false, CHECK_OK); | 2943 Expression* expression = ParseExpression(false, CHECK_OK); |
2929 if (peek() == Token::IN) { | 2944 if (peek() == Token::IN) { |
2930 // Signal a reference error if the expression is an invalid | 2945 // Signal a reference error if the expression is an invalid |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2990 // into | 3005 // into |
2991 // | 3006 // |
2992 // { | 3007 // { |
2993 // let x = i; | 3008 // let x = i; |
2994 // for (; c; n) b | 3009 // for (; c; n) b |
2995 // } | 3010 // } |
2996 ASSERT(init != NULL); | 3011 ASSERT(init != NULL); |
2997 Block* result = factory()->NewBlock(NULL, 2, false); | 3012 Block* result = factory()->NewBlock(NULL, 2, false); |
2998 result->AddStatement(init); | 3013 result->AddStatement(init); |
2999 result->AddStatement(loop); | 3014 result->AddStatement(loop); |
3000 result->set_block_scope(for_scope); | 3015 result->set_scope(for_scope); |
3001 if (loop) loop->Initialize(NULL, cond, next, body); | 3016 if (loop) loop->Initialize(NULL, cond, next, body); |
3002 return result; | 3017 return result; |
3003 } else { | 3018 } else { |
3004 if (loop) loop->Initialize(init, cond, next, body); | 3019 if (loop) loop->Initialize(init, cond, next, body); |
3005 return loop; | 3020 return loop; |
3006 } | 3021 } |
3007 } | 3022 } |
3008 | 3023 |
3009 | 3024 |
3010 // Precedence = 1 | 3025 // Precedence = 1 |
(...skipping 3004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6015 ASSERT(info->isolate()->has_pending_exception()); | 6030 ASSERT(info->isolate()->has_pending_exception()); |
6016 } else { | 6031 } else { |
6017 result = parser.ParseProgram(info); | 6032 result = parser.ParseProgram(info); |
6018 } | 6033 } |
6019 } | 6034 } |
6020 info->SetFunction(result); | 6035 info->SetFunction(result); |
6021 return (result != NULL); | 6036 return (result != NULL); |
6022 } | 6037 } |
6023 | 6038 |
6024 } } // namespace v8::internal | 6039 } } // namespace v8::internal |
OLD | NEW |