| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1302 // For instance declarations inside an eval scope need to be added | 1302 // For instance declarations inside an eval scope need to be added |
| 1303 // to the calling function context. | 1303 // to the calling function context. |
| 1304 // Similarly, strict mode eval scope does not leak variable declarations to | 1304 // Similarly, strict mode eval scope does not leak variable declarations to |
| 1305 // the caller's scope so we declare all locals, too. | 1305 // the caller's scope so we declare all locals, too. |
| 1306 if (top_scope_->is_function_scope() || | 1306 if (top_scope_->is_function_scope() || |
| 1307 top_scope_->is_strict_mode_eval_scope()) { | 1307 top_scope_->is_strict_mode_eval_scope()) { |
| 1308 // Declare the variable in the function scope. | 1308 // Declare the variable in the function scope. |
| 1309 var = top_scope_->LocalLookup(name); | 1309 var = top_scope_->LocalLookup(name); |
| 1310 if (var == NULL) { | 1310 if (var == NULL) { |
| 1311 // Declare the name. | 1311 // Declare the name. |
| 1312 var = top_scope_->DeclareLocal(name, mode); | 1312 var = top_scope_->DeclareLocal(name, mode, Scope::VAR_OR_CONST); |
| 1313 } else { | 1313 } else { |
| 1314 // The name was declared before; check for conflicting | 1314 // The name was declared before; check for conflicting |
| 1315 // re-declarations. If the previous declaration was a const or the | 1315 // re-declarations. If the previous declaration was a const or the |
| 1316 // current declaration is a const then we have a conflict. There is | 1316 // current declaration is a const then we have a conflict. There is |
| 1317 // similar code in runtime.cc in the Declare functions. | 1317 // similar code in runtime.cc in the Declare functions. |
| 1318 if ((mode == Variable::CONST) || (var->mode() == Variable::CONST)) { | 1318 if ((mode == Variable::CONST) || (var->mode() == Variable::CONST)) { |
| 1319 // We only have vars and consts in declarations. | 1319 // We only have vars and consts in declarations. |
| 1320 ASSERT(var->mode() == Variable::VAR || | 1320 ASSERT(var->mode() == Variable::VAR || |
| 1321 var->mode() == Variable::CONST); | 1321 var->mode() == Variable::CONST); |
| 1322 const char* type = (var->mode() == Variable::VAR) ? "var" : "const"; | 1322 const char* type = (var->mode() == Variable::VAR) ? "var" : "const"; |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1574 // an initial value in the declaration (because they are initialized upon | 1574 // an initial value in the declaration (because they are initialized upon |
| 1575 // entering the function). | 1575 // entering the function). |
| 1576 // | 1576 // |
| 1577 // If we have a const declaration, in an inner scope, the proxy is always | 1577 // If we have a const declaration, in an inner scope, the proxy is always |
| 1578 // bound to the declared variable (independent of possibly surrounding with | 1578 // bound to the declared variable (independent of possibly surrounding with |
| 1579 // statements). | 1579 // statements). |
| 1580 last_var = Declare(name, mode, NULL, | 1580 last_var = Declare(name, mode, NULL, |
| 1581 is_const /* always bound for CONST! */, | 1581 is_const /* always bound for CONST! */, |
| 1582 CHECK_OK); | 1582 CHECK_OK); |
| 1583 nvars++; | 1583 nvars++; |
| 1584 if (top_scope_->num_var_or_const() > kMaxNumFunctionLocals) { |
| 1585 ReportMessageAt(scanner().location(), "too_many_variables", |
| 1586 Vector<const char*>::empty()); |
| 1587 *ok = false; |
| 1588 return NULL; |
| 1589 } |
| 1584 | 1590 |
| 1585 // Parse initialization expression if present and/or needed. A | 1591 // Parse initialization expression if present and/or needed. A |
| 1586 // declaration of the form: | 1592 // declaration of the form: |
| 1587 // | 1593 // |
| 1588 // var v = x; | 1594 // var v = x; |
| 1589 // | 1595 // |
| 1590 // is syntactic sugar for: | 1596 // is syntactic sugar for: |
| 1591 // | 1597 // |
| 1592 // var v; v = x; | 1598 // var v; v = x; |
| 1593 // | 1599 // |
| (...skipping 1942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3536 bool only_simple_this_property_assignments; | 3542 bool only_simple_this_property_assignments; |
| 3537 Handle<FixedArray> this_property_assignments; | 3543 Handle<FixedArray> this_property_assignments; |
| 3538 // Parse function body. | 3544 // Parse function body. |
| 3539 { LexicalScope lexical_scope(this, scope, isolate()); | 3545 { LexicalScope lexical_scope(this, scope, isolate()); |
| 3540 top_scope_->SetScopeName(name); | 3546 top_scope_->SetScopeName(name); |
| 3541 | 3547 |
| 3542 // FormalParameterList :: | 3548 // FormalParameterList :: |
| 3543 // '(' (Identifier)*[','] ')' | 3549 // '(' (Identifier)*[','] ')' |
| 3544 Expect(Token::LPAREN, CHECK_OK); | 3550 Expect(Token::LPAREN, CHECK_OK); |
| 3545 start_pos = scanner().location().beg_pos; | 3551 start_pos = scanner().location().beg_pos; |
| 3546 Scanner::Location name_loc = Scanner::NoLocation(); | 3552 Scanner::Location name_loc = Scanner::Location::invalid(); |
| 3547 Scanner::Location dupe_loc = Scanner::NoLocation(); | 3553 Scanner::Location dupe_loc = Scanner::Location::invalid(); |
| 3548 Scanner::Location reserved_loc = Scanner::NoLocation(); | 3554 Scanner::Location reserved_loc = Scanner::Location::invalid(); |
| 3549 | 3555 |
| 3550 bool done = (peek() == Token::RPAREN); | 3556 bool done = (peek() == Token::RPAREN); |
| 3551 while (!done) { | 3557 while (!done) { |
| 3552 bool is_reserved = false; | 3558 bool is_reserved = false; |
| 3553 Handle<String> param_name = | 3559 Handle<String> param_name = |
| 3554 ParseIdentifierOrReservedWord(&is_reserved, CHECK_OK); | 3560 ParseIdentifierOrReservedWord(&is_reserved, CHECK_OK); |
| 3555 | 3561 |
| 3556 // Store locations for possible future error reports. | 3562 // Store locations for possible future error reports. |
| 3557 if (!name_loc.IsValid() && IsEvalOrArguments(param_name)) { | 3563 if (!name_loc.IsValid() && IsEvalOrArguments(param_name)) { |
| 3558 name_loc = scanner().location(); | 3564 name_loc = scanner().location(); |
| 3559 } | 3565 } |
| 3560 if (!dupe_loc.IsValid() && top_scope_->IsDeclared(param_name)) { | 3566 if (!dupe_loc.IsValid() && top_scope_->IsDeclared(param_name)) { |
| 3561 dupe_loc = scanner().location(); | 3567 dupe_loc = scanner().location(); |
| 3562 } | 3568 } |
| 3563 if (!reserved_loc.IsValid() && is_reserved) { | 3569 if (!reserved_loc.IsValid() && is_reserved) { |
| 3564 reserved_loc = scanner().location(); | 3570 reserved_loc = scanner().location(); |
| 3565 } | 3571 } |
| 3566 | 3572 |
| 3567 Variable* parameter = top_scope_->DeclareLocal(param_name, Variable::VAR); | 3573 Variable* parameter = top_scope_->DeclareLocal(param_name, |
| 3574 Variable::VAR, |
| 3575 Scope::PARAMETER); |
| 3568 top_scope_->AddParameter(parameter); | 3576 top_scope_->AddParameter(parameter); |
| 3569 num_parameters++; | 3577 num_parameters++; |
| 3570 if (num_parameters > kMaxNumFunctionParameters) { | 3578 if (num_parameters > kMaxNumFunctionParameters) { |
| 3571 ReportMessageAt(scanner().location(), "too_many_parameters", | 3579 ReportMessageAt(scanner().location(), "too_many_parameters", |
| 3572 Vector<const char*>::empty()); | 3580 Vector<const char*>::empty()); |
| 3573 *ok = false; | 3581 *ok = false; |
| 3574 return NULL; | 3582 return NULL; |
| 3575 } | 3583 } |
| 3576 done = (peek() == Token::RPAREN); | 3584 done = (peek() == Token::RPAREN); |
| 3577 if (!done) Expect(Token::COMMA, CHECK_OK); | 3585 if (!done) Expect(Token::COMMA, CHECK_OK); |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3857 ? expression->AsVariableProxy() | 3865 ? expression->AsVariableProxy() |
| 3858 : NULL; | 3866 : NULL; |
| 3859 | 3867 |
| 3860 if (lhs != NULL && !lhs->is_this() && IsEvalOrArguments(lhs->name())) { | 3868 if (lhs != NULL && !lhs->is_this() && IsEvalOrArguments(lhs->name())) { |
| 3861 ReportMessage(error, Vector<const char*>::empty()); | 3869 ReportMessage(error, Vector<const char*>::empty()); |
| 3862 *ok = false; | 3870 *ok = false; |
| 3863 } | 3871 } |
| 3864 } | 3872 } |
| 3865 | 3873 |
| 3866 | 3874 |
| 3867 // Checks whether octal literal last seen is between beg_pos and end_pos. | 3875 // Checks whether an octal literal was last seen between beg_pos and end_pos. |
| 3868 // If so, reports an error. | 3876 // If so, reports an error. Only called for strict mode. |
| 3869 void Parser::CheckOctalLiteral(int beg_pos, int end_pos, bool* ok) { | 3877 void Parser::CheckOctalLiteral(int beg_pos, int end_pos, bool* ok) { |
| 3870 int octal = scanner().octal_position(); | 3878 Scanner::Location octal = scanner().octal_position(); |
| 3871 if (beg_pos <= octal && octal <= end_pos) { | 3879 if (octal.IsValid() && |
| 3872 ReportMessageAt(Scanner::Location(octal, octal + 1), "strict_octal_literal", | 3880 beg_pos <= octal.beg_pos && |
| 3881 octal.end_pos <= end_pos) { |
| 3882 ReportMessageAt(octal, "strict_octal_literal", |
| 3873 Vector<const char*>::empty()); | 3883 Vector<const char*>::empty()); |
| 3874 scanner().clear_octal_position(); | 3884 scanner().clear_octal_position(); |
| 3875 *ok = false; | 3885 *ok = false; |
| 3876 } | 3886 } |
| 3877 } | 3887 } |
| 3878 | 3888 |
| 3879 | 3889 |
| 3880 // This function reads an identifier and determines whether or not it | 3890 // This function reads an identifier and determines whether or not it |
| 3881 // is 'get' or 'set'. | 3891 // is 'get' or 'set'. |
| 3882 Handle<String> Parser::ParseIdentifierOrGetOrSet(bool* is_get, | 3892 Handle<String> Parser::ParseIdentifierOrGetOrSet(bool* is_get, |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4075 if (scanner_.is_literal_ascii()) { | 4085 if (scanner_.is_literal_ascii()) { |
| 4076 return isolate()->factory()->NewStringFromAscii( | 4086 return isolate()->factory()->NewStringFromAscii( |
| 4077 scanner_.literal_ascii_string()); | 4087 scanner_.literal_ascii_string()); |
| 4078 } else { | 4088 } else { |
| 4079 return isolate()->factory()->NewStringFromTwoByte( | 4089 return isolate()->factory()->NewStringFromTwoByte( |
| 4080 scanner_.literal_uc16_string()); | 4090 scanner_.literal_uc16_string()); |
| 4081 } | 4091 } |
| 4082 } | 4092 } |
| 4083 | 4093 |
| 4084 | 4094 |
| 4095 Handle<String> JsonParser::GetSymbol() { |
| 4096 int literal_length = scanner_.literal_length(); |
| 4097 if (literal_length == 0) { |
| 4098 return isolate()->factory()->empty_string(); |
| 4099 } |
| 4100 if (scanner_.is_literal_ascii()) { |
| 4101 return isolate()->factory()->LookupAsciiSymbol( |
| 4102 scanner_.literal_ascii_string()); |
| 4103 } else { |
| 4104 return isolate()->factory()->LookupTwoByteSymbol( |
| 4105 scanner_.literal_uc16_string()); |
| 4106 } |
| 4107 } |
| 4108 |
| 4109 |
| 4085 // Parse any JSON value. | 4110 // Parse any JSON value. |
| 4086 Handle<Object> JsonParser::ParseJsonValue() { | 4111 Handle<Object> JsonParser::ParseJsonValue() { |
| 4087 Token::Value token = scanner_.Next(); | 4112 Token::Value token = scanner_.Next(); |
| 4088 switch (token) { | 4113 switch (token) { |
| 4089 case Token::STRING: | 4114 case Token::STRING: |
| 4090 return GetString(); | 4115 return GetString(); |
| 4091 case Token::NUMBER: | 4116 case Token::NUMBER: |
| 4092 return isolate()->factory()->NewNumber(scanner_.number()); | 4117 return isolate()->factory()->NewNumber(scanner_.number()); |
| 4093 case Token::FALSE_LITERAL: | 4118 case Token::FALSE_LITERAL: |
| 4094 return isolate()->factory()->false_value(); | 4119 return isolate()->factory()->false_value(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 4116 scanner_.Next(); | 4141 scanner_.Next(); |
| 4117 } else { | 4142 } else { |
| 4118 if (StackLimitCheck(isolate()).HasOverflowed()) { | 4143 if (StackLimitCheck(isolate()).HasOverflowed()) { |
| 4119 stack_overflow_ = true; | 4144 stack_overflow_ = true; |
| 4120 return Handle<Object>::null(); | 4145 return Handle<Object>::null(); |
| 4121 } | 4146 } |
| 4122 do { | 4147 do { |
| 4123 if (scanner_.Next() != Token::STRING) { | 4148 if (scanner_.Next() != Token::STRING) { |
| 4124 return ReportUnexpectedToken(); | 4149 return ReportUnexpectedToken(); |
| 4125 } | 4150 } |
| 4126 Handle<String> key = GetString(); | 4151 Handle<String> key = GetSymbol(); |
| 4127 if (scanner_.Next() != Token::COLON) { | 4152 if (scanner_.Next() != Token::COLON) { |
| 4128 return ReportUnexpectedToken(); | 4153 return ReportUnexpectedToken(); |
| 4129 } | 4154 } |
| 4130 Handle<Object> value = ParseJsonValue(); | 4155 Handle<Object> value = ParseJsonValue(); |
| 4131 if (value.is_null()) return Handle<Object>::null(); | 4156 if (value.is_null()) return Handle<Object>::null(); |
| 4132 uint32_t index; | 4157 uint32_t index; |
| 4133 if (key->AsArrayIndex(&index)) { | 4158 if (key->AsArrayIndex(&index)) { |
| 4134 SetOwnElement(json_object, index, value, kNonStrictMode); | 4159 SetOwnElement(json_object, index, value, kNonStrictMode); |
| 4135 } else if (key->Equals(isolate()->heap()->Proto_symbol())) { | 4160 } else if (key->Equals(isolate()->heap()->Proto_symbol())) { |
| 4136 // We can't remove the __proto__ accessor since it's hardcoded | 4161 // We can't remove the __proto__ accessor since it's hardcoded |
| (...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5153 info->is_global(), | 5178 info->is_global(), |
| 5154 info->StrictMode()); | 5179 info->StrictMode()); |
| 5155 } | 5180 } |
| 5156 } | 5181 } |
| 5157 | 5182 |
| 5158 info->SetFunction(result); | 5183 info->SetFunction(result); |
| 5159 return (result != NULL); | 5184 return (result != NULL); |
| 5160 } | 5185 } |
| 5161 | 5186 |
| 5162 } } // namespace v8::internal | 5187 } } // namespace v8::internal |
| OLD | NEW |