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

Side by Side Diff: src/parser.cc

Issue 242124: Follow the spec in disallow function declarations without a name. We... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 2 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
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 1906 matching lines...) Expand 10 before | Expand all | Expand 10 after
1917 // other functions are setup when entering the surrounding scope. 1917 // other functions are setup when entering the surrounding scope.
1918 FunctionBoilerplateLiteral* lit = 1918 FunctionBoilerplateLiteral* lit =
1919 NEW(FunctionBoilerplateLiteral(boilerplate)); 1919 NEW(FunctionBoilerplateLiteral(boilerplate));
1920 VariableProxy* var = Declare(name, Variable::VAR, NULL, true, CHECK_OK); 1920 VariableProxy* var = Declare(name, Variable::VAR, NULL, true, CHECK_OK);
1921 return NEW(ExpressionStatement( 1921 return NEW(ExpressionStatement(
1922 new Assignment(Token::INIT_VAR, var, lit, RelocInfo::kNoPosition))); 1922 new Assignment(Token::INIT_VAR, var, lit, RelocInfo::kNoPosition)));
1923 } 1923 }
1924 1924
1925 1925
1926 Statement* Parser::ParseFunctionDeclaration(bool* ok) { 1926 Statement* Parser::ParseFunctionDeclaration(bool* ok) {
1927 // Parse a function literal. We may or may not have a function name. 1927 // FunctionDeclaration ::
1928 // If we have a name we use it as the variable name for the function 1928 // 'function' Identifier '(' FormalParameterListopt ')' '{' FunctionBody '}'
1929 // (a function declaration) and not as the function name of a function
1930 // expression.
1931
1932 Expect(Token::FUNCTION, CHECK_OK); 1929 Expect(Token::FUNCTION, CHECK_OK);
1933 int function_token_position = scanner().location().beg_pos; 1930 int function_token_position = scanner().location().beg_pos;
1934 1931 Handle<String> name = ParseIdentifier(CHECK_OK);
1935 Handle<String> name; 1932 FunctionLiteral* fun = ParseFunctionLiteral(name,
1936 if (peek() == Token::IDENTIFIER) name = ParseIdentifier(CHECK_OK); 1933 function_token_position,
1937 FunctionLiteral* fun = ParseFunctionLiteral(name, function_token_position, 1934 DECLARATION,
1938 DECLARATION, CHECK_OK); 1935 CHECK_OK);
1939 1936 // Even if we're not at the top-level of the global or a function
1940 if (name.is_null()) { 1937 // scope, we treat is as such and introduce the function with it's
1941 // We don't have a name - it is always an anonymous function 1938 // initial value upon entering the corresponding scope.
1942 // expression. 1939 Declare(name, Variable::VAR, fun, true, CHECK_OK);
1943 return NEW(ExpressionStatement(fun)); 1940 return factory()->EmptyStatement();
1944 } else {
1945 // We have a name so even if we're not at the top-level of the
1946 // global or a function scope, we treat is as such and introduce
1947 // the function with it's initial value upon entering the
1948 // corresponding scope.
1949 Declare(name, Variable::VAR, fun, true, CHECK_OK);
1950 return factory()->EmptyStatement();
1951 }
1952 } 1941 }
1953 1942
1954 1943
1955 Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) { 1944 Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) {
1956 // Block :: 1945 // Block ::
1957 // '{' Statement* '}' 1946 // '{' Statement* '}'
1958 1947
1959 // Note that a Block does not introduce a new execution scope! 1948 // Note that a Block does not introduce a new execution scope!
1960 // (ECMA-262, 3rd, 12.2) 1949 // (ECMA-262, 3rd, 12.2)
1961 // 1950 //
(...skipping 2875 matching lines...) Expand 10 before | Expand all | Expand 10 after
4837 start_position, 4826 start_position,
4838 is_expression); 4827 is_expression);
4839 return result; 4828 return result;
4840 } 4829 }
4841 4830
4842 4831
4843 #undef NEW 4832 #undef NEW
4844 4833
4845 4834
4846 } } // namespace v8::internal 4835 } } // namespace v8::internal
OLDNEW
« src/debug-delay.js ('K') | « src/debug-delay.js ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698