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

Side by Side Diff: src/parser.cc

Issue 152813005: Make strict more error messages about "eval" and "arguments" less specific. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: . Created 6 years, 10 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/parser.h ('k') | src/preparser.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 965 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 } 976 }
977 } 977 }
978 } 978 }
979 979
980 980
981 Statement* Parser::ParseModuleDeclaration(ZoneStringList* names, bool* ok) { 981 Statement* Parser::ParseModuleDeclaration(ZoneStringList* names, bool* ok) {
982 // ModuleDeclaration: 982 // ModuleDeclaration:
983 // 'module' Identifier Module 983 // 'module' Identifier Module
984 984
985 int pos = peek_position(); 985 int pos = peek_position();
986 Handle<String> name = ParseIdentifier(CHECK_OK); 986 Handle<String> name = ParseIdentifier(false, CHECK_OK);
ulan 2014/02/05 16:05:42 I prefer enums to flags, because they are more rea
marja 2014/02/05 16:18:02 Done: kDontAllowEnumOrArguments and kAllowEnumOrAr
987 987
988 #ifdef DEBUG 988 #ifdef DEBUG
989 if (FLAG_print_interface_details) 989 if (FLAG_print_interface_details)
990 PrintF("# Module %s...\n", name->ToAsciiArray()); 990 PrintF("# Module %s...\n", name->ToAsciiArray());
991 #endif 991 #endif
992 992
993 Module* module = ParseModule(CHECK_OK); 993 Module* module = ParseModule(CHECK_OK);
994 VariableProxy* proxy = NewUnresolved(name, MODULE, module->interface()); 994 VariableProxy* proxy = NewUnresolved(name, MODULE, module->interface());
995 Declaration* declaration = 995 Declaration* declaration =
996 factory()->NewModuleDeclaration(proxy, module, top_scope_, pos); 996 factory()->NewModuleDeclaration(proxy, module, top_scope_, pos);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 1129
1130 return result; 1130 return result;
1131 } 1131 }
1132 1132
1133 1133
1134 Module* Parser::ParseModuleVariable(bool* ok) { 1134 Module* Parser::ParseModuleVariable(bool* ok) {
1135 // ModulePath: 1135 // ModulePath:
1136 // Identifier 1136 // Identifier
1137 1137
1138 int pos = peek_position(); 1138 int pos = peek_position();
1139 Handle<String> name = ParseIdentifier(CHECK_OK); 1139 Handle<String> name = ParseIdentifier(false, CHECK_OK);
1140 #ifdef DEBUG 1140 #ifdef DEBUG
1141 if (FLAG_print_interface_details) 1141 if (FLAG_print_interface_details)
1142 PrintF("# Module variable %s ", name->ToAsciiArray()); 1142 PrintF("# Module variable %s ", name->ToAsciiArray());
1143 #endif 1143 #endif
1144 VariableProxy* proxy = top_scope_->NewUnresolved( 1144 VariableProxy* proxy = top_scope_->NewUnresolved(
1145 factory(), name, Interface::NewModule(zone()), 1145 factory(), name, Interface::NewModule(zone()),
1146 scanner().location().beg_pos); 1146 scanner().location().beg_pos);
1147 1147
1148 return factory()->NewModuleVariable(proxy, pos); 1148 return factory()->NewModuleVariable(proxy, pos);
1149 } 1149 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 // 1254 //
1255 // TODO(ES6): implement structuring ExportSpecifiers 1255 // TODO(ES6): implement structuring ExportSpecifiers
1256 1256
1257 Expect(Token::EXPORT, CHECK_OK); 1257 Expect(Token::EXPORT, CHECK_OK);
1258 1258
1259 Statement* result = NULL; 1259 Statement* result = NULL;
1260 ZoneStringList names(1, zone()); 1260 ZoneStringList names(1, zone());
1261 switch (peek()) { 1261 switch (peek()) {
1262 case Token::IDENTIFIER: { 1262 case Token::IDENTIFIER: {
1263 int pos = position(); 1263 int pos = position();
1264 Handle<String> name = ParseIdentifier(CHECK_OK); 1264 Handle<String> name = ParseIdentifier(false, CHECK_OK);
1265 // Handle 'module' as a context-sensitive keyword. 1265 // Handle 'module' as a context-sensitive keyword.
1266 if (!name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("module"))) { 1266 if (!name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("module"))) {
1267 names.Add(name, zone()); 1267 names.Add(name, zone());
1268 while (peek() == Token::COMMA) { 1268 while (peek() == Token::COMMA) {
1269 Consume(Token::COMMA); 1269 Consume(Token::COMMA);
1270 name = ParseIdentifier(CHECK_OK); 1270 name = ParseIdentifier(false, CHECK_OK);
1271 names.Add(name, zone()); 1271 names.Add(name, zone());
1272 } 1272 }
1273 ExpectSemicolon(CHECK_OK); 1273 ExpectSemicolon(CHECK_OK);
1274 result = factory()->NewEmptyStatement(pos); 1274 result = factory()->NewEmptyStatement(pos);
1275 } else { 1275 } else {
1276 result = ParseModuleDeclaration(&names, CHECK_OK); 1276 result = ParseModuleDeclaration(&names, CHECK_OK);
1277 } 1277 }
1278 break; 1278 break;
1279 } 1279 }
1280 1280
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1625 } 1625 }
1626 1626
1627 1627
1628 // Language extension which is only enabled for source files loaded 1628 // Language extension which is only enabled for source files loaded
1629 // through the API's extension mechanism. A native function 1629 // through the API's extension mechanism. A native function
1630 // declaration is resolved by looking up the function through a 1630 // declaration is resolved by looking up the function through a
1631 // callback provided by the extension. 1631 // callback provided by the extension.
1632 Statement* Parser::ParseNativeDeclaration(bool* ok) { 1632 Statement* Parser::ParseNativeDeclaration(bool* ok) {
1633 int pos = peek_position(); 1633 int pos = peek_position();
1634 Expect(Token::FUNCTION, CHECK_OK); 1634 Expect(Token::FUNCTION, CHECK_OK);
1635 Handle<String> name = ParseIdentifier(CHECK_OK); 1635 // Allow "eval" or "arguments" for backward compatibility.
1636 Handle<String> name = ParseIdentifier(true, CHECK_OK);
1636 Expect(Token::LPAREN, CHECK_OK); 1637 Expect(Token::LPAREN, CHECK_OK);
1637 bool done = (peek() == Token::RPAREN); 1638 bool done = (peek() == Token::RPAREN);
1638 while (!done) { 1639 while (!done) {
1639 ParseIdentifier(CHECK_OK); 1640 ParseIdentifier(true, CHECK_OK);
1640 done = (peek() == Token::RPAREN); 1641 done = (peek() == Token::RPAREN);
1641 if (!done) { 1642 if (!done) {
1642 Expect(Token::COMMA, CHECK_OK); 1643 Expect(Token::COMMA, CHECK_OK);
1643 } 1644 }
1644 } 1645 }
1645 Expect(Token::RPAREN, CHECK_OK); 1646 Expect(Token::RPAREN, CHECK_OK);
1646 Expect(Token::SEMICOLON, CHECK_OK); 1647 Expect(Token::SEMICOLON, CHECK_OK);
1647 1648
1648 // Make sure that the function containing the native declaration 1649 // Make sure that the function containing the native declaration
1649 // isn't lazily compiled. The extension structures are only 1650 // isn't lazily compiled. The extension structures are only
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1893 // 1894 //
1894 // Create new block with one expected declaration. 1895 // Create new block with one expected declaration.
1895 Block* block = factory()->NewBlock(NULL, 1, true, pos); 1896 Block* block = factory()->NewBlock(NULL, 1, true, pos);
1896 int nvars = 0; // the number of variables declared 1897 int nvars = 0; // the number of variables declared
1897 Handle<String> name; 1898 Handle<String> name;
1898 do { 1899 do {
1899 if (fni_ != NULL) fni_->Enter(); 1900 if (fni_ != NULL) fni_->Enter();
1900 1901
1901 // Parse variable name. 1902 // Parse variable name.
1902 if (nvars > 0) Consume(Token::COMMA); 1903 if (nvars > 0) Consume(Token::COMMA);
1903 name = ParseIdentifier(CHECK_OK); 1904 name = ParseIdentifier(false, CHECK_OK);
1904 if (fni_ != NULL) fni_->PushVariableName(name); 1905 if (fni_ != NULL) fni_->PushVariableName(name);
1905 1906
1906 // Strict mode variables may not be named eval or arguments
1907 if (!declaration_scope->is_classic_mode() && IsEvalOrArguments(name)) {
1908 ReportMessage("strict_var_name", Vector<const char*>::empty());
1909 *ok = false;
1910 return NULL;
1911 }
1912
1913 // Declare variable. 1907 // Declare variable.
1914 // Note that we *always* must treat the initial value via a separate init 1908 // Note that we *always* must treat the initial value via a separate init
1915 // assignment for variables and constants because the value must be assigned 1909 // assignment for variables and constants because the value must be assigned
1916 // when the variable is encountered in the source. But the variable/constant 1910 // when the variable is encountered in the source. But the variable/constant
1917 // is declared (and set to 'undefined') upon entering the function within 1911 // is declared (and set to 'undefined') upon entering the function within
1918 // which the variable or constant is declared. Only function variables have 1912 // which the variable or constant is declared. Only function variables have
1919 // an initial value in the declaration (because they are initialized upon 1913 // an initial value in the declaration (because they are initialized upon
1920 // entering the function). 1914 // entering the function).
1921 // 1915 //
1922 // If we have a const declaration, in an inner scope, the proxy is always 1916 // If we have a const declaration, in an inner scope, the proxy is always
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
2217 Statement* Parser::ParseContinueStatement(bool* ok) { 2211 Statement* Parser::ParseContinueStatement(bool* ok) {
2218 // ContinueStatement :: 2212 // ContinueStatement ::
2219 // 'continue' Identifier? ';' 2213 // 'continue' Identifier? ';'
2220 2214
2221 int pos = peek_position(); 2215 int pos = peek_position();
2222 Expect(Token::CONTINUE, CHECK_OK); 2216 Expect(Token::CONTINUE, CHECK_OK);
2223 Handle<String> label = Handle<String>::null(); 2217 Handle<String> label = Handle<String>::null();
2224 Token::Value tok = peek(); 2218 Token::Value tok = peek();
2225 if (!scanner().HasAnyLineTerminatorBeforeNext() && 2219 if (!scanner().HasAnyLineTerminatorBeforeNext() &&
2226 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { 2220 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) {
2227 label = ParseIdentifier(CHECK_OK); 2221 // ECMA allows "eval" or "arguments" as labels even in strict mode.
2222 label = ParseIdentifier(true, CHECK_OK);
2228 } 2223 }
2229 IterationStatement* target = NULL; 2224 IterationStatement* target = NULL;
2230 target = LookupContinueTarget(label, CHECK_OK); 2225 target = LookupContinueTarget(label, CHECK_OK);
2231 if (target == NULL) { 2226 if (target == NULL) {
2232 // Illegal continue statement. 2227 // Illegal continue statement.
2233 const char* message = "illegal_continue"; 2228 const char* message = "illegal_continue";
2234 Vector<Handle<String> > args; 2229 Vector<Handle<String> > args;
2235 if (!label.is_null()) { 2230 if (!label.is_null()) {
2236 message = "unknown_label"; 2231 message = "unknown_label";
2237 args = Vector<Handle<String> >(&label, 1); 2232 args = Vector<Handle<String> >(&label, 1);
(...skipping 10 matching lines...) Expand all
2248 Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) { 2243 Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) {
2249 // BreakStatement :: 2244 // BreakStatement ::
2250 // 'break' Identifier? ';' 2245 // 'break' Identifier? ';'
2251 2246
2252 int pos = peek_position(); 2247 int pos = peek_position();
2253 Expect(Token::BREAK, CHECK_OK); 2248 Expect(Token::BREAK, CHECK_OK);
2254 Handle<String> label; 2249 Handle<String> label;
2255 Token::Value tok = peek(); 2250 Token::Value tok = peek();
2256 if (!scanner().HasAnyLineTerminatorBeforeNext() && 2251 if (!scanner().HasAnyLineTerminatorBeforeNext() &&
2257 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) { 2252 tok != Token::SEMICOLON && tok != Token::RBRACE && tok != Token::EOS) {
2258 label = ParseIdentifier(CHECK_OK); 2253 // ECMA allows "eval" or "arguments" as labels even in strict mode.
2254 label = ParseIdentifier(true, CHECK_OK);
2259 } 2255 }
2260 // Parse labeled break statements that target themselves into 2256 // Parse labeled break statements that target themselves into
2261 // empty statements, e.g. 'l1: l2: l3: break l2;' 2257 // empty statements, e.g. 'l1: l2: l3: break l2;'
2262 if (!label.is_null() && ContainsLabel(labels, label)) { 2258 if (!label.is_null() && ContainsLabel(labels, label)) {
2263 ExpectSemicolon(CHECK_OK); 2259 ExpectSemicolon(CHECK_OK);
2264 return factory()->NewEmptyStatement(pos); 2260 return factory()->NewEmptyStatement(pos);
2265 } 2261 }
2266 BreakableStatement* target = NULL; 2262 BreakableStatement* target = NULL;
2267 target = LookupBreakTarget(label, CHECK_OK); 2263 target = LookupBreakTarget(label, CHECK_OK);
2268 if (target == NULL) { 2264 if (target == NULL) {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
2478 Scope* catch_scope = NULL; 2474 Scope* catch_scope = NULL;
2479 Variable* catch_variable = NULL; 2475 Variable* catch_variable = NULL;
2480 Block* catch_block = NULL; 2476 Block* catch_block = NULL;
2481 Handle<String> name; 2477 Handle<String> name;
2482 if (tok == Token::CATCH) { 2478 if (tok == Token::CATCH) {
2483 Consume(Token::CATCH); 2479 Consume(Token::CATCH);
2484 2480
2485 Expect(Token::LPAREN, CHECK_OK); 2481 Expect(Token::LPAREN, CHECK_OK);
2486 catch_scope = NewScope(top_scope_, CATCH_SCOPE); 2482 catch_scope = NewScope(top_scope_, CATCH_SCOPE);
2487 catch_scope->set_start_position(scanner().location().beg_pos); 2483 catch_scope->set_start_position(scanner().location().beg_pos);
2488 name = ParseIdentifier(CHECK_OK); 2484 name = ParseIdentifier(false, CHECK_OK);
2489
2490 if (!top_scope_->is_classic_mode() && IsEvalOrArguments(name)) {
2491 ReportMessage("strict_catch_variable", Vector<const char*>::empty());
2492 *ok = false;
2493 return NULL;
2494 }
2495 2485
2496 Expect(Token::RPAREN, CHECK_OK); 2486 Expect(Token::RPAREN, CHECK_OK);
2497 2487
2498 if (peek() == Token::LBRACE) { 2488 if (peek() == Token::LBRACE) {
2499 Target target(&this->target_stack_, &catch_collector); 2489 Target target(&this->target_stack_, &catch_collector);
2500 VariableMode mode = is_extended_mode() ? LET : VAR; 2490 VariableMode mode = is_extended_mode() ? LET : VAR;
2501 catch_variable = 2491 catch_variable =
2502 catch_scope->DeclareLocal(name, mode, kCreatedInitialized); 2492 catch_scope->DeclareLocal(name, mode, kCreatedInitialized);
2503 2493
2504 BlockState block_state(this, catch_scope); 2494 BlockState block_state(this, catch_scope);
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
2932 // runtime. 2922 // runtime.
2933 // TODO(ES5): Should change parsing for spec conformance. 2923 // TODO(ES5): Should change parsing for spec conformance.
2934 if (expression == NULL || !expression->IsValidLeftHandSide()) { 2924 if (expression == NULL || !expression->IsValidLeftHandSide()) {
2935 Handle<String> message = 2925 Handle<String> message =
2936 isolate()->factory()->invalid_lhs_in_assignment_string(); 2926 isolate()->factory()->invalid_lhs_in_assignment_string();
2937 expression = NewThrowReferenceError(message); 2927 expression = NewThrowReferenceError(message);
2938 } 2928 }
2939 2929
2940 if (!top_scope_->is_classic_mode()) { 2930 if (!top_scope_->is_classic_mode()) {
2941 // Assignment to eval or arguments is disallowed in strict mode. 2931 // Assignment to eval or arguments is disallowed in strict mode.
2942 CheckStrictModeLValue(expression, "strict_lhs_assignment", CHECK_OK); 2932 CheckStrictModeLValue(expression, CHECK_OK);
2943 } 2933 }
2944 MarkAsLValue(expression); 2934 MarkAsLValue(expression);
2945 2935
2946 Token::Value op = Next(); // Get assignment operator. 2936 Token::Value op = Next(); // Get assignment operator.
2947 int pos = position(); 2937 int pos = position();
2948 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); 2938 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK);
2949 2939
2950 // TODO(1231235): We try to estimate the set of properties set by 2940 // TODO(1231235): We try to estimate the set of properties set by
2951 // constructors. We define a new property whenever there is an 2941 // constructors. We define a new property whenever there is an
2952 // assignment to a property of 'this'. We should probably only add 2942 // assignment to a property of 'this'. We should probably only add
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
3212 // error here but for compatibility with JSC we choose to report the 3202 // error here but for compatibility with JSC we choose to report the
3213 // error at runtime. 3203 // error at runtime.
3214 if (expression == NULL || !expression->IsValidLeftHandSide()) { 3204 if (expression == NULL || !expression->IsValidLeftHandSide()) {
3215 Handle<String> message = 3205 Handle<String> message =
3216 isolate()->factory()->invalid_lhs_in_prefix_op_string(); 3206 isolate()->factory()->invalid_lhs_in_prefix_op_string();
3217 expression = NewThrowReferenceError(message); 3207 expression = NewThrowReferenceError(message);
3218 } 3208 }
3219 3209
3220 if (!top_scope_->is_classic_mode()) { 3210 if (!top_scope_->is_classic_mode()) {
3221 // Prefix expression operand in strict mode may not be eval or arguments. 3211 // Prefix expression operand in strict mode may not be eval or arguments.
3222 CheckStrictModeLValue(expression, "strict_lhs_prefix", CHECK_OK); 3212 CheckStrictModeLValue(expression, CHECK_OK);
3223 } 3213 }
3224 MarkAsLValue(expression); 3214 MarkAsLValue(expression);
3225 3215
3226 return factory()->NewCountOperation(op, 3216 return factory()->NewCountOperation(op,
3227 true /* prefix */, 3217 true /* prefix */,
3228 expression, 3218 expression,
3229 position()); 3219 position());
3230 3220
3231 } else { 3221 } else {
3232 return ParsePostfixExpression(ok); 3222 return ParsePostfixExpression(ok);
(...skipping 13 matching lines...) Expand all
3246 // error here but for compatibility with JSC we choose to report the 3236 // error here but for compatibility with JSC we choose to report the
3247 // error at runtime. 3237 // error at runtime.
3248 if (expression == NULL || !expression->IsValidLeftHandSide()) { 3238 if (expression == NULL || !expression->IsValidLeftHandSide()) {
3249 Handle<String> message = 3239 Handle<String> message =
3250 isolate()->factory()->invalid_lhs_in_postfix_op_string(); 3240 isolate()->factory()->invalid_lhs_in_postfix_op_string();
3251 expression = NewThrowReferenceError(message); 3241 expression = NewThrowReferenceError(message);
3252 } 3242 }
3253 3243
3254 if (!top_scope_->is_classic_mode()) { 3244 if (!top_scope_->is_classic_mode()) {
3255 // Postfix expression operand in strict mode may not be eval or arguments. 3245 // Postfix expression operand in strict mode may not be eval or arguments.
3256 CheckStrictModeLValue(expression, "strict_lhs_postfix", CHECK_OK); 3246 CheckStrictModeLValue(expression, CHECK_OK);
3257 } 3247 }
3258 MarkAsLValue(expression); 3248 MarkAsLValue(expression);
3259 3249
3260 Token::Value next = Next(); 3250 Token::Value next = Next();
3261 expression = 3251 expression =
3262 factory()->NewCountOperation(next, 3252 factory()->NewCountOperation(next,
3263 false /* postfix */, 3253 false /* postfix */,
3264 expression, 3254 expression,
3265 position()); 3255 position());
3266 } 3256 }
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
3556 break; 3546 break;
3557 3547
3558 case Token::FALSE_LITERAL: 3548 case Token::FALSE_LITERAL:
3559 Consume(Token::FALSE_LITERAL); 3549 Consume(Token::FALSE_LITERAL);
3560 result = factory()->NewLiteral(isolate()->factory()->false_value(), pos); 3550 result = factory()->NewLiteral(isolate()->factory()->false_value(), pos);
3561 break; 3551 break;
3562 3552
3563 case Token::IDENTIFIER: 3553 case Token::IDENTIFIER:
3564 case Token::YIELD: 3554 case Token::YIELD:
3565 case Token::FUTURE_STRICT_RESERVED_WORD: { 3555 case Token::FUTURE_STRICT_RESERVED_WORD: {
3566 Handle<String> name = ParseIdentifier(CHECK_OK); 3556 // Using eval or arguments in this context is OK even in strict mode.
3557 Handle<String> name = ParseIdentifier(true, CHECK_OK);
3567 if (fni_ != NULL) fni_->PushVariableName(name); 3558 if (fni_ != NULL) fni_->PushVariableName(name);
3568 // The name may refer to a module instance object, so its type is unknown. 3559 // The name may refer to a module instance object, so its type is unknown.
3569 #ifdef DEBUG 3560 #ifdef DEBUG
3570 if (FLAG_print_interface_details) 3561 if (FLAG_print_interface_details)
3571 PrintF("# Variable %s ", name->ToAsciiArray()); 3562 PrintF("# Variable %s ", name->ToAsciiArray());
3572 #endif 3563 #endif
3573 Interface* interface = Interface::NewUnknown(zone()); 3564 Interface* interface = Interface::NewUnknown(zone());
3574 result = top_scope_->NewUnresolved(factory(), name, interface, pos); 3565 result = top_scope_->NewUnresolved(factory(), name, interface, pos);
3575 break; 3566 break;
3576 } 3567 }
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
4296 handler_count = function_state.handler_count(); 4287 handler_count = function_state.handler_count();
4297 4288
4298 Expect(Token::RBRACE, CHECK_OK); 4289 Expect(Token::RBRACE, CHECK_OK);
4299 scope->set_end_position(scanner().location().end_pos); 4290 scope->set_end_position(scanner().location().end_pos);
4300 } 4291 }
4301 4292
4302 // Validate strict mode. 4293 // Validate strict mode.
4303 if (!top_scope_->is_classic_mode()) { 4294 if (!top_scope_->is_classic_mode()) {
4304 if (IsEvalOrArguments(function_name)) { 4295 if (IsEvalOrArguments(function_name)) {
4305 ReportMessageAt(function_name_location, 4296 ReportMessageAt(function_name_location,
4306 "strict_function_name", 4297 "strict_eval_arguments",
4307 Vector<const char*>::empty()); 4298 Vector<const char*>::empty());
4308 *ok = false; 4299 *ok = false;
4309 return NULL; 4300 return NULL;
4310 } 4301 }
4311 if (name_loc.IsValid()) { 4302 if (name_loc.IsValid()) {
4312 ReportMessageAt(name_loc, "strict_param_name", 4303 ReportMessageAt(name_loc, "strict_eval_arguments",
4313 Vector<const char*>::empty()); 4304 Vector<const char*>::empty());
4314 *ok = false; 4305 *ok = false;
4315 return NULL; 4306 return NULL;
4316 } 4307 }
4317 if (dupe_loc.IsValid()) { 4308 if (dupe_loc.IsValid()) {
4318 ReportMessageAt(dupe_loc, "strict_param_dupe", 4309 ReportMessageAt(dupe_loc, "strict_param_dupe",
4319 Vector<const char*>::empty()); 4310 Vector<const char*>::empty());
4320 *ok = false; 4311 *ok = false;
4321 return NULL; 4312 return NULL;
4322 } 4313 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
4391 return result; 4382 return result;
4392 } 4383 }
4393 4384
4394 4385
4395 Expression* Parser::ParseV8Intrinsic(bool* ok) { 4386 Expression* Parser::ParseV8Intrinsic(bool* ok) {
4396 // CallRuntime :: 4387 // CallRuntime ::
4397 // '%' Identifier Arguments 4388 // '%' Identifier Arguments
4398 4389
4399 int pos = peek_position(); 4390 int pos = peek_position();
4400 Expect(Token::MOD, CHECK_OK); 4391 Expect(Token::MOD, CHECK_OK);
4401 Handle<String> name = ParseIdentifier(CHECK_OK); 4392 // Allow "eval" or "arguments" for backward compatibility.
4393 Handle<String> name = ParseIdentifier(true, CHECK_OK);
4402 ZoneList<Expression*>* args = ParseArguments(CHECK_OK); 4394 ZoneList<Expression*>* args = ParseArguments(CHECK_OK);
4403 4395
4404 if (extension_ != NULL) { 4396 if (extension_ != NULL) {
4405 // The extension structures are only accessible while parsing the 4397 // The extension structures are only accessible while parsing the
4406 // very first time not when reparsing because of lazy compilation. 4398 // very first time not when reparsing because of lazy compilation.
4407 top_scope_->DeclarationScope()->ForceEagerCompilation(); 4399 top_scope_->DeclarationScope()->ForceEagerCompilation();
4408 } 4400 }
4409 4401
4410 const Runtime::Function* function = Runtime::FunctionForName(name); 4402 const Runtime::Function* function = Runtime::FunctionForName(name);
4411 4403
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
4498 } 4490 }
4499 4491
4500 4492
4501 Literal* Parser::GetLiteralTheHole(int position) { 4493 Literal* Parser::GetLiteralTheHole(int position) {
4502 return factory()->NewLiteral( 4494 return factory()->NewLiteral(
4503 isolate()->factory()->the_hole_value(), RelocInfo::kNoPosition); 4495 isolate()->factory()->the_hole_value(), RelocInfo::kNoPosition);
4504 } 4496 }
4505 4497
4506 4498
4507 // Parses an identifier that is valid for the current scope, in particular it 4499 // Parses an identifier that is valid for the current scope, in particular it
4508 // fails on strict mode future reserved keywords in a strict scope. 4500 // fails on strict mode future reserved keywords in a strict scope. If
4509 Handle<String> Parser::ParseIdentifier(bool* ok) { 4501 // allow_eval_arguments is true, we allow "eval" or "arguments" as identifier
4502 // even in strict mode (this is needed in cases like "var foo = eval;").
4503 Handle<String> Parser::ParseIdentifier(bool allow_eval_arguments, bool* ok) {
4510 Token::Value next = Next(); 4504 Token::Value next = Next();
4511 if (next == Token::IDENTIFIER || 4505 if (next == Token::IDENTIFIER) {
4512 (top_scope_->is_classic_mode() && 4506 Handle<String> name = GetSymbol();
4513 (next == Token::FUTURE_STRICT_RESERVED_WORD || 4507 if (!allow_eval_arguments && !top_scope_->is_classic_mode() &&
4514 (next == Token::YIELD && !is_generator())))) { 4508 IsEvalOrArguments(name)) {
4509 ReportMessage("strict_eval_arguments", Vector<const char*>::empty());
4510 *ok = false;
4511 }
4512 return name;
4513 } else if (top_scope_->is_classic_mode() &&
4514 (next == Token::FUTURE_STRICT_RESERVED_WORD ||
4515 (next == Token::YIELD && !is_generator()))) {
4515 return GetSymbol(); 4516 return GetSymbol();
4516 } else { 4517 } else {
4517 ReportUnexpectedToken(next); 4518 ReportUnexpectedToken(next);
4518 *ok = false; 4519 *ok = false;
4519 return Handle<String>(); 4520 return Handle<String>();
4520 } 4521 }
4521 } 4522 }
4522 4523
4523 4524
4524 // Parses and identifier or a strict mode future reserved word, and indicate 4525 // Parses and identifier or a strict mode future reserved word, and indicate
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
4559 ? expression->AsVariableProxy() 4560 ? expression->AsVariableProxy()
4560 : NULL; 4561 : NULL;
4561 4562
4562 if (proxy != NULL) proxy->MarkAsLValue(); 4563 if (proxy != NULL) proxy->MarkAsLValue();
4563 } 4564 }
4564 4565
4565 4566
4566 // Checks LHS expression for assignment and prefix/postfix increment/decrement 4567 // Checks LHS expression for assignment and prefix/postfix increment/decrement
4567 // in strict mode. 4568 // in strict mode.
4568 void Parser::CheckStrictModeLValue(Expression* expression, 4569 void Parser::CheckStrictModeLValue(Expression* expression,
4569 const char* error,
4570 bool* ok) { 4570 bool* ok) {
4571 ASSERT(!top_scope_->is_classic_mode()); 4571 ASSERT(!top_scope_->is_classic_mode());
4572 VariableProxy* lhs = expression != NULL 4572 VariableProxy* lhs = expression != NULL
4573 ? expression->AsVariableProxy() 4573 ? expression->AsVariableProxy()
4574 : NULL; 4574 : NULL;
4575 4575
4576 if (lhs != NULL && !lhs->is_this() && IsEvalOrArguments(lhs->name())) { 4576 if (lhs != NULL && !lhs->is_this() && IsEvalOrArguments(lhs->name())) {
4577 ReportMessage(error, Vector<const char*>::empty()); 4577 ReportMessage("strict_eval_arguments", Vector<const char*>::empty());
4578 *ok = false; 4578 *ok = false;
4579 } 4579 }
4580 } 4580 }
4581 4581
4582 4582
4583 // Checks whether an octal literal was last seen between beg_pos and end_pos. 4583 // Checks whether an octal literal was last seen between beg_pos and end_pos.
4584 // If so, reports an error. Only called for strict mode. 4584 // If so, reports an error. Only called for strict mode.
4585 void ParserBase::CheckOctalLiteral(int beg_pos, int end_pos, bool* ok) { 4585 void ParserBase::CheckOctalLiteral(int beg_pos, int end_pos, bool* ok) {
4586 Scanner::Location octal = scanner()->octal_position(); 4586 Scanner::Location octal = scanner()->octal_position();
4587 if (octal.IsValid() && beg_pos <= octal.beg_pos && octal.end_pos <= end_pos) { 4587 if (octal.IsValid() && beg_pos <= octal.beg_pos && octal.end_pos <= end_pos) {
(...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after
5684 ASSERT(info()->isolate()->has_pending_exception()); 5684 ASSERT(info()->isolate()->has_pending_exception());
5685 } else { 5685 } else {
5686 result = ParseProgram(); 5686 result = ParseProgram();
5687 } 5687 }
5688 } 5688 }
5689 info()->SetFunction(result); 5689 info()->SetFunction(result);
5690 return (result != NULL); 5690 return (result != NULL);
5691 } 5691 }
5692 5692
5693 } } // namespace v8::internal 5693 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698