Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(708)

Side by Side Diff: src/parser.cc

Issue 10105026: Version 3.10.3 (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/objects-visiting-inl.h ('k') | src/platform.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
2247 } 2262 }
2248 2263
2249 // Make sure that 'const x' and 'let x' initialize 'x' to undefined. 2264 // Make sure that 'const x' and 'let x' initialize 'x' to undefined.
2250 if (value == NULL && needs_init) { 2265 if (value == NULL && needs_init) {
2251 value = GetLiteralUndefined(); 2266 value = GetLiteralUndefined();
2252 } 2267 }
2253 2268
2254 // Global variable declarations must be compiled in a specific 2269 // Global variable declarations must be compiled in a specific
2255 // way. When the script containing the global variable declaration 2270 // way. When the script containing the global variable declaration
2256 // is entered, the global variable must be declared, so that if it 2271 // is entered, the global variable must be declared, so that if it
2257 // doesn't exist (not even in a prototype of the global object) it 2272 // doesn't exist (on the global object itself, see ES5 errata) it
2258 // gets created with an initial undefined value. This is handled 2273 // gets created with an initial undefined value. This is handled
2259 // by the declarations part of the function representing the 2274 // by the declarations part of the function representing the
2260 // top-level global code; see Runtime::DeclareGlobalVariable. If 2275 // top-level global code; see Runtime::DeclareGlobalVariable. If
2261 // it already exists (in the object or in a prototype), it is 2276 // it already exists (in the object or in a prototype), it is
2262 // *not* touched until the variable declaration statement is 2277 // *not* touched until the variable declaration statement is
2263 // executed. 2278 // executed.
2264 // 2279 //
2265 // Executing the variable declaration statement will always 2280 // Executing the variable declaration statement will always
2266 // guarantee to give the global object a "local" variable; a 2281 // guarantee to give the global object a "local" variable; a
2267 // variable defined in the global object and not in any 2282 // variable defined in the global object and not in any
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 1442 matching lines...) Expand 10 before | Expand all | Expand 10 after
4453 4468
4454 // If we have a named function expression, we add a local variable 4469 // If we have a named function expression, we add a local variable
4455 // declaration to the body of the function with the name of the 4470 // declaration to the body of the function with the name of the
4456 // function and let it refer to the function itself (closure). 4471 // function and let it refer to the function itself (closure).
4457 // NOTE: We create a proxy and resolve it here so that in the 4472 // NOTE: We create a proxy and resolve it here so that in the
4458 // future we can change the AST to only refer to VariableProxies 4473 // future we can change the AST to only refer to VariableProxies
4459 // instead of Variables and Proxis as is the case now. 4474 // instead of Variables and Proxis as is the case now.
4460 Variable* fvar = NULL; 4475 Variable* fvar = NULL;
4461 Token::Value fvar_init_op = Token::INIT_CONST; 4476 Token::Value fvar_init_op = Token::INIT_CONST;
4462 if (type == FunctionLiteral::NAMED_EXPRESSION) { 4477 if (type == FunctionLiteral::NAMED_EXPRESSION) {
4463 VariableMode fvar_mode; 4478 if (is_extended_mode()) fvar_init_op = Token::INIT_CONST_HARMONY;
4464 if (is_extended_mode()) { 4479 VariableMode fvar_mode = is_extended_mode() ? CONST_HARMONY : CONST;
4465 fvar_mode = CONST_HARMONY; 4480 fvar = new(zone()) Variable(top_scope_,
4466 fvar_init_op = Token::INIT_CONST_HARMONY; 4481 function_name, fvar_mode, true /* is valid LHS */,
4467 } else { 4482 Variable::NORMAL, kCreatedInitialized);
4468 fvar_mode = CONST; 4483 VariableProxy* proxy = factory()->NewVariableProxy(fvar);
4469 } 4484 VariableDeclaration* fvar_declaration =
4470 fvar = 4485 factory()->NewVariableDeclaration(proxy, fvar_mode, top_scope_);
4471 top_scope_->DeclareFunctionVar(function_name, fvar_mode, factory()); 4486 top_scope_->DeclareFunctionVar(fvar_declaration);
4472 } 4487 }
4473 4488
4474 // Determine whether the function will be lazily compiled. 4489 // Determine whether the function will be lazily compiled.
4475 // The heuristics are: 4490 // The heuristics are:
4476 // - It must not have been prohibited by the caller to Parse (some callers 4491 // - It must not have been prohibited by the caller to Parse (some callers
4477 // need a full AST). 4492 // need a full AST).
4478 // - The outer scope must be trivial (only global variables in scope). 4493 // - The outer scope must be trivial (only global variables in scope).
4479 // - The function mustn't be a function expression with an open parenthesis 4494 // - The function mustn't be a function expression with an open parenthesis
4480 // before; we consider that a hint that the function will be called 4495 // before; we consider that a hint that the function will be called
4481 // immediately, and it would be a waste of time to make it lazily 4496 // immediately, and it would be a waste of time to make it lazily
(...skipping 1533 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « src/objects-visiting-inl.h ('k') | src/platform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698