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 1299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1310 Statement* stat = ParseModuleElement(NULL, CHECK_OK); | 1310 Statement* stat = ParseModuleElement(NULL, CHECK_OK); |
1311 if (stat && !stat->IsEmpty()) { | 1311 if (stat && !stat->IsEmpty()) { |
1312 body->AddStatement(stat); | 1312 body->AddStatement(stat); |
1313 block_finder.Update(stat); | 1313 block_finder.Update(stat); |
1314 } | 1314 } |
1315 } | 1315 } |
1316 } | 1316 } |
1317 | 1317 |
1318 Expect(Token::RBRACE, CHECK_OK); | 1318 Expect(Token::RBRACE, CHECK_OK); |
1319 scope->set_end_position(scanner().location().end_pos); | 1319 scope->set_end_position(scanner().location().end_pos); |
1320 body->set_block_scope(scope); | 1320 body->set_scope(scope); |
1321 | 1321 |
1322 scope->interface()->Freeze(ok); | 1322 // Instance objects have to be created ahead of time (before code generation |
| 1323 // linking them) because of potentially cyclic references between them. |
| 1324 // We create them here, to avoid another pass over the AST. |
| 1325 Interface* interface = scope->interface(); |
| 1326 interface->MakeModule(ok); |
1323 ASSERT(ok); | 1327 ASSERT(ok); |
1324 return factory()->NewModuleLiteral(body, scope->interface()); | 1328 interface->MakeSingleton(Isolate::Current()->factory()->NewJSModule(), ok); |
| 1329 ASSERT(ok); |
| 1330 interface->Freeze(ok); |
| 1331 ASSERT(ok); |
| 1332 return factory()->NewModuleLiteral(body, interface); |
1325 } | 1333 } |
1326 | 1334 |
1327 | 1335 |
1328 Module* Parser::ParseModulePath(bool* ok) { | 1336 Module* Parser::ParseModulePath(bool* ok) { |
1329 // ModulePath: | 1337 // ModulePath: |
1330 // Identifier | 1338 // Identifier |
1331 // ModulePath '.' Identifier | 1339 // ModulePath '.' Identifier |
1332 | 1340 |
1333 Module* result = ParseModuleVariable(CHECK_OK); | 1341 Module* result = ParseModuleVariable(CHECK_OK); |
1334 while (Check(Token::PERIOD)) { | 1342 while (Check(Token::PERIOD)) { |
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1992 Statement* stat = ParseBlockElement(NULL, CHECK_OK); | 2000 Statement* stat = ParseBlockElement(NULL, CHECK_OK); |
1993 if (stat && !stat->IsEmpty()) { | 2001 if (stat && !stat->IsEmpty()) { |
1994 body->AddStatement(stat); | 2002 body->AddStatement(stat); |
1995 block_finder.Update(stat); | 2003 block_finder.Update(stat); |
1996 } | 2004 } |
1997 } | 2005 } |
1998 } | 2006 } |
1999 Expect(Token::RBRACE, CHECK_OK); | 2007 Expect(Token::RBRACE, CHECK_OK); |
2000 block_scope->set_end_position(scanner().location().end_pos); | 2008 block_scope->set_end_position(scanner().location().end_pos); |
2001 block_scope = block_scope->FinalizeBlockScope(); | 2009 block_scope = block_scope->FinalizeBlockScope(); |
2002 body->set_block_scope(block_scope); | 2010 body->set_scope(block_scope); |
2003 return body; | 2011 return body; |
2004 } | 2012 } |
2005 | 2013 |
2006 | 2014 |
2007 Block* Parser::ParseVariableStatement(VariableDeclarationContext var_context, | 2015 Block* Parser::ParseVariableStatement(VariableDeclarationContext var_context, |
2008 ZoneStringList* names, | 2016 ZoneStringList* names, |
2009 bool* ok) { | 2017 bool* ok) { |
2010 // VariableStatement :: | 2018 // VariableStatement :: |
2011 // VariableDeclarations ';' | 2019 // VariableDeclarations ';' |
2012 | 2020 |
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2894 Token::ASSIGN, each, temp_proxy, RelocInfo::kNoPosition); | 2902 Token::ASSIGN, each, temp_proxy, RelocInfo::kNoPosition); |
2895 Statement* assignment_statement = | 2903 Statement* assignment_statement = |
2896 factory()->NewExpressionStatement(assignment); | 2904 factory()->NewExpressionStatement(assignment); |
2897 body_block->AddStatement(variable_statement); | 2905 body_block->AddStatement(variable_statement); |
2898 body_block->AddStatement(assignment_statement); | 2906 body_block->AddStatement(assignment_statement); |
2899 body_block->AddStatement(body); | 2907 body_block->AddStatement(body); |
2900 loop->Initialize(temp_proxy, enumerable, body_block); | 2908 loop->Initialize(temp_proxy, enumerable, body_block); |
2901 top_scope_ = saved_scope; | 2909 top_scope_ = saved_scope; |
2902 for_scope->set_end_position(scanner().location().end_pos); | 2910 for_scope->set_end_position(scanner().location().end_pos); |
2903 for_scope = for_scope->FinalizeBlockScope(); | 2911 for_scope = for_scope->FinalizeBlockScope(); |
2904 body_block->set_block_scope(for_scope); | 2912 body_block->set_scope(for_scope); |
2905 // Parsed for-in loop w/ let declaration. | 2913 // Parsed for-in loop w/ let declaration. |
2906 return loop; | 2914 return loop; |
2907 | 2915 |
2908 } else { | 2916 } else { |
2909 init = variable_statement; | 2917 init = variable_statement; |
2910 } | 2918 } |
2911 } else { | 2919 } else { |
2912 Expression* expression = ParseExpression(false, CHECK_OK); | 2920 Expression* expression = ParseExpression(false, CHECK_OK); |
2913 if (peek() == Token::IN) { | 2921 if (peek() == Token::IN) { |
2914 // Signal a reference error if the expression is an invalid | 2922 // Signal a reference error if the expression is an invalid |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2974 // into | 2982 // into |
2975 // | 2983 // |
2976 // { | 2984 // { |
2977 // let x = i; | 2985 // let x = i; |
2978 // for (; c; n) b | 2986 // for (; c; n) b |
2979 // } | 2987 // } |
2980 ASSERT(init != NULL); | 2988 ASSERT(init != NULL); |
2981 Block* result = factory()->NewBlock(NULL, 2, false); | 2989 Block* result = factory()->NewBlock(NULL, 2, false); |
2982 result->AddStatement(init); | 2990 result->AddStatement(init); |
2983 result->AddStatement(loop); | 2991 result->AddStatement(loop); |
2984 result->set_block_scope(for_scope); | 2992 result->set_scope(for_scope); |
2985 if (loop) loop->Initialize(NULL, cond, next, body); | 2993 if (loop) loop->Initialize(NULL, cond, next, body); |
2986 return result; | 2994 return result; |
2987 } else { | 2995 } else { |
2988 if (loop) loop->Initialize(init, cond, next, body); | 2996 if (loop) loop->Initialize(init, cond, next, body); |
2989 return loop; | 2997 return loop; |
2990 } | 2998 } |
2991 } | 2999 } |
2992 | 3000 |
2993 | 3001 |
2994 // Precedence = 1 | 3002 // Precedence = 1 |
(...skipping 3003 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5998 ASSERT(info->isolate()->has_pending_exception()); | 6006 ASSERT(info->isolate()->has_pending_exception()); |
5999 } else { | 6007 } else { |
6000 result = parser.ParseProgram(info); | 6008 result = parser.ParseProgram(info); |
6001 } | 6009 } |
6002 } | 6010 } |
6003 info->SetFunction(result); | 6011 info->SetFunction(result); |
6004 return (result != NULL); | 6012 return (result != NULL); |
6005 } | 6013 } |
6006 | 6014 |
6007 } } // namespace v8::internal | 6015 } } // namespace v8::internal |
OLD | NEW |