| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 , last_added_(ADD_NONE) | 96 , last_added_(ADD_NONE) |
| 97 #endif | 97 #endif |
| 98 {} | 98 {} |
| 99 | 99 |
| 100 | 100 |
| 101 void RegExpBuilder::FlushCharacters() { | 101 void RegExpBuilder::FlushCharacters() { |
| 102 pending_empty_ = false; | 102 pending_empty_ = false; |
| 103 if (characters_ != NULL) { | 103 if (characters_ != NULL) { |
| 104 RegExpTree* atom = new(zone()) RegExpAtom(characters_->ToConstVector()); | 104 RegExpTree* atom = new(zone()) RegExpAtom(characters_->ToConstVector()); |
| 105 characters_ = NULL; | 105 characters_ = NULL; |
| 106 text_.Add(atom); | 106 text_.Add(atom, zone()); |
| 107 LAST(ADD_ATOM); | 107 LAST(ADD_ATOM); |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 | 110 |
| 111 | 111 |
| 112 void RegExpBuilder::FlushText() { | 112 void RegExpBuilder::FlushText() { |
| 113 FlushCharacters(); | 113 FlushCharacters(); |
| 114 int num_text = text_.length(); | 114 int num_text = text_.length(); |
| 115 if (num_text == 0) { | 115 if (num_text == 0) { |
| 116 return; | 116 return; |
| 117 } else if (num_text == 1) { | 117 } else if (num_text == 1) { |
| 118 terms_.Add(text_.last()); | 118 terms_.Add(text_.last(), zone()); |
| 119 } else { | 119 } else { |
| 120 RegExpText* text = new(zone()) RegExpText(); | 120 RegExpText* text = new(zone()) RegExpText(zone()); |
| 121 for (int i = 0; i < num_text; i++) | 121 for (int i = 0; i < num_text; i++) |
| 122 text_.Get(i)->AppendToText(text); | 122 text_.Get(i)->AppendToText(text, zone()); |
| 123 terms_.Add(text); | 123 terms_.Add(text, zone()); |
| 124 } | 124 } |
| 125 text_.Clear(); | 125 text_.Clear(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 | 128 |
| 129 void RegExpBuilder::AddCharacter(uc16 c) { | 129 void RegExpBuilder::AddCharacter(uc16 c) { |
| 130 pending_empty_ = false; | 130 pending_empty_ = false; |
| 131 if (characters_ == NULL) { | 131 if (characters_ == NULL) { |
| 132 characters_ = new(zone()) ZoneList<uc16>(4); | 132 characters_ = new(zone()) ZoneList<uc16>(4, zone()); |
| 133 } | 133 } |
| 134 characters_->Add(c); | 134 characters_->Add(c, zone()); |
| 135 LAST(ADD_CHAR); | 135 LAST(ADD_CHAR); |
| 136 } | 136 } |
| 137 | 137 |
| 138 | 138 |
| 139 void RegExpBuilder::AddEmpty() { | 139 void RegExpBuilder::AddEmpty() { |
| 140 pending_empty_ = true; | 140 pending_empty_ = true; |
| 141 } | 141 } |
| 142 | 142 |
| 143 | 143 |
| 144 void RegExpBuilder::AddAtom(RegExpTree* term) { | 144 void RegExpBuilder::AddAtom(RegExpTree* term) { |
| 145 if (term->IsEmpty()) { | 145 if (term->IsEmpty()) { |
| 146 AddEmpty(); | 146 AddEmpty(); |
| 147 return; | 147 return; |
| 148 } | 148 } |
| 149 if (term->IsTextElement()) { | 149 if (term->IsTextElement()) { |
| 150 FlushCharacters(); | 150 FlushCharacters(); |
| 151 text_.Add(term); | 151 text_.Add(term, zone()); |
| 152 } else { | 152 } else { |
| 153 FlushText(); | 153 FlushText(); |
| 154 terms_.Add(term); | 154 terms_.Add(term, zone()); |
| 155 } | 155 } |
| 156 LAST(ADD_ATOM); | 156 LAST(ADD_ATOM); |
| 157 } | 157 } |
| 158 | 158 |
| 159 | 159 |
| 160 void RegExpBuilder::AddAssertion(RegExpTree* assert) { | 160 void RegExpBuilder::AddAssertion(RegExpTree* assert) { |
| 161 FlushText(); | 161 FlushText(); |
| 162 terms_.Add(assert); | 162 terms_.Add(assert, zone()); |
| 163 LAST(ADD_ASSERT); | 163 LAST(ADD_ASSERT); |
| 164 } | 164 } |
| 165 | 165 |
| 166 | 166 |
| 167 void RegExpBuilder::NewAlternative() { | 167 void RegExpBuilder::NewAlternative() { |
| 168 FlushTerms(); | 168 FlushTerms(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 | 171 |
| 172 void RegExpBuilder::FlushTerms() { | 172 void RegExpBuilder::FlushTerms() { |
| 173 FlushText(); | 173 FlushText(); |
| 174 int num_terms = terms_.length(); | 174 int num_terms = terms_.length(); |
| 175 RegExpTree* alternative; | 175 RegExpTree* alternative; |
| 176 if (num_terms == 0) { | 176 if (num_terms == 0) { |
| 177 alternative = RegExpEmpty::GetInstance(); | 177 alternative = RegExpEmpty::GetInstance(); |
| 178 } else if (num_terms == 1) { | 178 } else if (num_terms == 1) { |
| 179 alternative = terms_.last(); | 179 alternative = terms_.last(); |
| 180 } else { | 180 } else { |
| 181 alternative = new(zone()) RegExpAlternative(terms_.GetList()); | 181 alternative = new(zone()) RegExpAlternative(terms_.GetList(zone())); |
| 182 } | 182 } |
| 183 alternatives_.Add(alternative); | 183 alternatives_.Add(alternative, zone()); |
| 184 terms_.Clear(); | 184 terms_.Clear(); |
| 185 LAST(ADD_NONE); | 185 LAST(ADD_NONE); |
| 186 } | 186 } |
| 187 | 187 |
| 188 | 188 |
| 189 RegExpTree* RegExpBuilder::ToRegExp() { | 189 RegExpTree* RegExpBuilder::ToRegExp() { |
| 190 FlushTerms(); | 190 FlushTerms(); |
| 191 int num_alternatives = alternatives_.length(); | 191 int num_alternatives = alternatives_.length(); |
| 192 if (num_alternatives == 0) { | 192 if (num_alternatives == 0) { |
| 193 return RegExpEmpty::GetInstance(); | 193 return RegExpEmpty::GetInstance(); |
| 194 } | 194 } |
| 195 if (num_alternatives == 1) { | 195 if (num_alternatives == 1) { |
| 196 return alternatives_.last(); | 196 return alternatives_.last(); |
| 197 } | 197 } |
| 198 return new(zone()) RegExpDisjunction(alternatives_.GetList()); | 198 return new(zone()) RegExpDisjunction(alternatives_.GetList(zone())); |
| 199 } | 199 } |
| 200 | 200 |
| 201 | 201 |
| 202 void RegExpBuilder::AddQuantifierToAtom(int min, | 202 void RegExpBuilder::AddQuantifierToAtom(int min, |
| 203 int max, | 203 int max, |
| 204 RegExpQuantifier::Type type) { | 204 RegExpQuantifier::Type type) { |
| 205 if (pending_empty_) { | 205 if (pending_empty_) { |
| 206 pending_empty_ = false; | 206 pending_empty_ = false; |
| 207 return; | 207 return; |
| 208 } | 208 } |
| 209 RegExpTree* atom; | 209 RegExpTree* atom; |
| 210 if (characters_ != NULL) { | 210 if (characters_ != NULL) { |
| 211 ASSERT(last_added_ == ADD_CHAR); | 211 ASSERT(last_added_ == ADD_CHAR); |
| 212 // Last atom was character. | 212 // Last atom was character. |
| 213 Vector<const uc16> char_vector = characters_->ToConstVector(); | 213 Vector<const uc16> char_vector = characters_->ToConstVector(); |
| 214 int num_chars = char_vector.length(); | 214 int num_chars = char_vector.length(); |
| 215 if (num_chars > 1) { | 215 if (num_chars > 1) { |
| 216 Vector<const uc16> prefix = char_vector.SubVector(0, num_chars - 1); | 216 Vector<const uc16> prefix = char_vector.SubVector(0, num_chars - 1); |
| 217 text_.Add(new(zone()) RegExpAtom(prefix)); | 217 text_.Add(new(zone()) RegExpAtom(prefix), zone()); |
| 218 char_vector = char_vector.SubVector(num_chars - 1, num_chars); | 218 char_vector = char_vector.SubVector(num_chars - 1, num_chars); |
| 219 } | 219 } |
| 220 characters_ = NULL; | 220 characters_ = NULL; |
| 221 atom = new(zone()) RegExpAtom(char_vector); | 221 atom = new(zone()) RegExpAtom(char_vector); |
| 222 FlushText(); | 222 FlushText(); |
| 223 } else if (text_.length() > 0) { | 223 } else if (text_.length() > 0) { |
| 224 ASSERT(last_added_ == ADD_ATOM); | 224 ASSERT(last_added_ == ADD_ATOM); |
| 225 atom = text_.RemoveLast(); | 225 atom = text_.RemoveLast(); |
| 226 FlushText(); | 226 FlushText(); |
| 227 } else if (terms_.length() > 0) { | 227 } else if (terms_.length() > 0) { |
| 228 ASSERT(last_added_ == ADD_ATOM); | 228 ASSERT(last_added_ == ADD_ATOM); |
| 229 atom = terms_.RemoveLast(); | 229 atom = terms_.RemoveLast(); |
| 230 if (atom->max_match() == 0) { | 230 if (atom->max_match() == 0) { |
| 231 // Guaranteed to only match an empty string. | 231 // Guaranteed to only match an empty string. |
| 232 LAST(ADD_TERM); | 232 LAST(ADD_TERM); |
| 233 if (min == 0) { | 233 if (min == 0) { |
| 234 return; | 234 return; |
| 235 } | 235 } |
| 236 terms_.Add(atom); | 236 terms_.Add(atom, zone()); |
| 237 return; | 237 return; |
| 238 } | 238 } |
| 239 } else { | 239 } else { |
| 240 // Only call immediately after adding an atom or character! | 240 // Only call immediately after adding an atom or character! |
| 241 UNREACHABLE(); | 241 UNREACHABLE(); |
| 242 return; | 242 return; |
| 243 } | 243 } |
| 244 terms_.Add(new(zone()) RegExpQuantifier(min, max, type, atom)); | 244 terms_.Add(new(zone()) RegExpQuantifier(min, max, type, atom), zone()); |
| 245 LAST(ADD_TERM); | 245 LAST(ADD_TERM); |
| 246 } | 246 } |
| 247 | 247 |
| 248 | 248 |
| 249 Handle<String> Parser::LookupSymbol(int symbol_id) { | 249 Handle<String> Parser::LookupSymbol(int symbol_id) { |
| 250 // Length of symbol cache is the number of identified symbols. | 250 // Length of symbol cache is the number of identified symbols. |
| 251 // If we are larger than that, or negative, it's not a cached symbol. | 251 // If we are larger than that, or negative, it's not a cached symbol. |
| 252 // This might also happen if there is no preparser symbol data, even | 252 // This might also happen if there is no preparser symbol data, even |
| 253 // if there is some preparser data. | 253 // if there is some preparser data. |
| 254 if (static_cast<unsigned>(symbol_id) | 254 if (static_cast<unsigned>(symbol_id) |
| 255 >= static_cast<unsigned>(symbol_cache_.length())) { | 255 >= static_cast<unsigned>(symbol_cache_.length())) { |
| 256 if (scanner().is_literal_ascii()) { | 256 if (scanner().is_literal_ascii()) { |
| 257 return isolate()->factory()->LookupAsciiSymbol( | 257 return isolate()->factory()->LookupAsciiSymbol( |
| 258 scanner().literal_ascii_string()); | 258 scanner().literal_ascii_string()); |
| 259 } else { | 259 } else { |
| 260 return isolate()->factory()->LookupTwoByteSymbol( | 260 return isolate()->factory()->LookupTwoByteSymbol( |
| 261 scanner().literal_utf16_string()); | 261 scanner().literal_utf16_string()); |
| 262 } | 262 } |
| 263 } | 263 } |
| 264 return LookupCachedSymbol(symbol_id); | 264 return LookupCachedSymbol(symbol_id); |
| 265 } | 265 } |
| 266 | 266 |
| 267 | 267 |
| 268 Handle<String> Parser::LookupCachedSymbol(int symbol_id) { | 268 Handle<String> Parser::LookupCachedSymbol(int symbol_id) { |
| 269 // Make sure the cache is large enough to hold the symbol identifier. | 269 // Make sure the cache is large enough to hold the symbol identifier. |
| 270 if (symbol_cache_.length() <= symbol_id) { | 270 if (symbol_cache_.length() <= symbol_id) { |
| 271 // Increase length to index + 1. | 271 // Increase length to index + 1. |
| 272 symbol_cache_.AddBlock(Handle<String>::null(), | 272 symbol_cache_.AddBlock(Handle<String>::null(), |
| 273 symbol_id + 1 - symbol_cache_.length()); | 273 symbol_id + 1 - symbol_cache_.length(), zone()); |
| 274 } | 274 } |
| 275 Handle<String> result = symbol_cache_.at(symbol_id); | 275 Handle<String> result = symbol_cache_.at(symbol_id); |
| 276 if (result.is_null()) { | 276 if (result.is_null()) { |
| 277 if (scanner().is_literal_ascii()) { | 277 if (scanner().is_literal_ascii()) { |
| 278 result = isolate()->factory()->LookupAsciiSymbol( | 278 result = isolate()->factory()->LookupAsciiSymbol( |
| 279 scanner().literal_ascii_string()); | 279 scanner().literal_ascii_string()); |
| 280 } else { | 280 } else { |
| 281 result = isolate()->factory()->LookupTwoByteSymbol( | 281 result = isolate()->factory()->LookupTwoByteSymbol( |
| 282 scanner().literal_utf16_string()); | 282 scanner().literal_utf16_string()); |
| 283 } | 283 } |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 return store_[PreparseDataConstants::kHeaderSize + position]; | 401 return store_[PreparseDataConstants::kHeaderSize + position]; |
| 402 } | 402 } |
| 403 | 403 |
| 404 | 404 |
| 405 unsigned* ScriptDataImpl::ReadAddress(int position) { | 405 unsigned* ScriptDataImpl::ReadAddress(int position) { |
| 406 return &store_[PreparseDataConstants::kHeaderSize + position]; | 406 return &store_[PreparseDataConstants::kHeaderSize + position]; |
| 407 } | 407 } |
| 408 | 408 |
| 409 | 409 |
| 410 Scope* Parser::NewScope(Scope* parent, ScopeType type) { | 410 Scope* Parser::NewScope(Scope* parent, ScopeType type) { |
| 411 Scope* result = new(zone()) Scope(parent, type); | 411 Scope* result = new(zone()) Scope(parent, type, zone()); |
| 412 result->Initialize(); | 412 result->Initialize(); |
| 413 return result; | 413 return result; |
| 414 } | 414 } |
| 415 | 415 |
| 416 | 416 |
| 417 // ---------------------------------------------------------------------------- | 417 // ---------------------------------------------------------------------------- |
| 418 // Target is a support class to facilitate manipulation of the | 418 // Target is a support class to facilitate manipulation of the |
| 419 // Parser's target_stack_ (the stack of potential 'break' and | 419 // Parser's target_stack_ (the stack of potential 'break' and |
| 420 // 'continue' statement targets). Upon construction, a new target is | 420 // 'continue' statement targets). Upon construction, a new target is |
| 421 // added; it is removed upon destruction. | 421 // added; it is removed upon destruction. |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 | 531 |
| 532 // ---------------------------------------------------------------------------- | 532 // ---------------------------------------------------------------------------- |
| 533 // Implementation of Parser | 533 // Implementation of Parser |
| 534 | 534 |
| 535 Parser::Parser(Handle<Script> script, | 535 Parser::Parser(Handle<Script> script, |
| 536 int parser_flags, | 536 int parser_flags, |
| 537 v8::Extension* extension, | 537 v8::Extension* extension, |
| 538 ScriptDataImpl* pre_data, | 538 ScriptDataImpl* pre_data, |
| 539 Zone* zone) | 539 Zone* zone) |
| 540 : isolate_(script->GetIsolate()), | 540 : isolate_(script->GetIsolate()), |
| 541 symbol_cache_(pre_data ? pre_data->symbol_count() : 0), | 541 symbol_cache_(pre_data ? pre_data->symbol_count() : 0, zone), |
| 542 script_(script), | 542 script_(script), |
| 543 scanner_(isolate_->unicode_cache()), | 543 scanner_(isolate_->unicode_cache()), |
| 544 reusable_preparser_(NULL), | 544 reusable_preparser_(NULL), |
| 545 top_scope_(NULL), | 545 top_scope_(NULL), |
| 546 current_function_state_(NULL), | 546 current_function_state_(NULL), |
| 547 target_stack_(NULL), | 547 target_stack_(NULL), |
| 548 extension_(extension), | 548 extension_(extension), |
| 549 pre_data_(pre_data), | 549 pre_data_(pre_data), |
| 550 fni_(NULL), | 550 fni_(NULL), |
| 551 allow_natives_syntax_((parser_flags & kAllowNativesSyntax) != 0), | 551 allow_natives_syntax_((parser_flags & kAllowNativesSyntax) != 0), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 563 } | 563 } |
| 564 } | 564 } |
| 565 | 565 |
| 566 | 566 |
| 567 FunctionLiteral* Parser::ParseProgram(CompilationInfo* info) { | 567 FunctionLiteral* Parser::ParseProgram(CompilationInfo* info) { |
| 568 ZoneScope zone_scope(isolate(), DONT_DELETE_ON_EXIT); | 568 ZoneScope zone_scope(isolate(), DONT_DELETE_ON_EXIT); |
| 569 | 569 |
| 570 HistogramTimerScope timer(isolate()->counters()->parse()); | 570 HistogramTimerScope timer(isolate()->counters()->parse()); |
| 571 Handle<String> source(String::cast(script_->source())); | 571 Handle<String> source(String::cast(script_->source())); |
| 572 isolate()->counters()->total_parse_size()->Increment(source->length()); | 572 isolate()->counters()->total_parse_size()->Increment(source->length()); |
| 573 fni_ = new(zone()) FuncNameInferrer(isolate()); | 573 fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); |
| 574 | 574 |
| 575 // Initialize parser state. | 575 // Initialize parser state. |
| 576 source->TryFlatten(); | 576 source->TryFlatten(); |
| 577 if (source->IsExternalTwoByteString()) { | 577 if (source->IsExternalTwoByteString()) { |
| 578 // Notice that the stream is destroyed at the end of the branch block. | 578 // Notice that the stream is destroyed at the end of the branch block. |
| 579 // The last line of the blocks can't be moved outside, even though they're | 579 // The last line of the blocks can't be moved outside, even though they're |
| 580 // identical calls. | 580 // identical calls. |
| 581 ExternalTwoByteStringUtf16CharacterStream stream( | 581 ExternalTwoByteStringUtf16CharacterStream stream( |
| 582 Handle<ExternalTwoByteString>::cast(source), 0, source->length()); | 582 Handle<ExternalTwoByteString>::cast(source), 0, source->length()); |
| 583 scanner_.Initialize(&stream); | 583 scanner_.Initialize(&stream); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 602 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY; | 602 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY; |
| 603 | 603 |
| 604 Handle<String> no_name = isolate()->factory()->empty_symbol(); | 604 Handle<String> no_name = isolate()->factory()->empty_symbol(); |
| 605 | 605 |
| 606 FunctionLiteral* result = NULL; | 606 FunctionLiteral* result = NULL; |
| 607 { Scope* scope = NewScope(top_scope_, GLOBAL_SCOPE); | 607 { Scope* scope = NewScope(top_scope_, GLOBAL_SCOPE); |
| 608 info->SetGlobalScope(scope); | 608 info->SetGlobalScope(scope); |
| 609 if (info->is_eval()) { | 609 if (info->is_eval()) { |
| 610 Handle<SharedFunctionInfo> shared = info->shared_info(); | 610 Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 611 if (!info->is_global() && (shared.is_null() || shared->is_function())) { | 611 if (!info->is_global() && (shared.is_null() || shared->is_function())) { |
| 612 scope = Scope::DeserializeScopeChain(*info->calling_context(), scope); | 612 scope = Scope::DeserializeScopeChain(*info->calling_context(), scope, |
| 613 zone()); |
| 613 } | 614 } |
| 614 if (!scope->is_global_scope() || info->language_mode() != CLASSIC_MODE) { | 615 if (!scope->is_global_scope() || info->language_mode() != CLASSIC_MODE) { |
| 615 scope = NewScope(scope, EVAL_SCOPE); | 616 scope = NewScope(scope, EVAL_SCOPE); |
| 616 } | 617 } |
| 617 } | 618 } |
| 618 scope->set_start_position(0); | 619 scope->set_start_position(0); |
| 619 scope->set_end_position(source->length()); | 620 scope->set_end_position(source->length()); |
| 620 FunctionState function_state(this, scope, isolate()); | 621 FunctionState function_state(this, scope, isolate()); |
| 621 top_scope_->SetLanguageMode(info->language_mode()); | 622 top_scope_->SetLanguageMode(info->language_mode()); |
| 622 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16); | 623 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); |
| 623 bool ok = true; | 624 bool ok = true; |
| 624 int beg_loc = scanner().location().beg_pos; | 625 int beg_loc = scanner().location().beg_pos; |
| 625 ParseSourceElements(body, Token::EOS, info->is_eval(), &ok); | 626 ParseSourceElements(body, Token::EOS, info->is_eval(), &ok); |
| 626 if (ok && !top_scope_->is_classic_mode()) { | 627 if (ok && !top_scope_->is_classic_mode()) { |
| 627 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); | 628 CheckOctalLiteral(beg_loc, scanner().location().end_pos, &ok); |
| 628 } | 629 } |
| 629 | 630 |
| 630 if (ok && is_extended_mode()) { | 631 if (ok && is_extended_mode()) { |
| 631 CheckConflictingVarDeclarations(top_scope_, &ok); | 632 CheckConflictingVarDeclarations(top_scope_, &ok); |
| 632 } | 633 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 | 690 |
| 690 FunctionLiteral* Parser::ParseLazy(CompilationInfo* info, | 691 FunctionLiteral* Parser::ParseLazy(CompilationInfo* info, |
| 691 Utf16CharacterStream* source, | 692 Utf16CharacterStream* source, |
| 692 ZoneScope* zone_scope) { | 693 ZoneScope* zone_scope) { |
| 693 Handle<SharedFunctionInfo> shared_info = info->shared_info(); | 694 Handle<SharedFunctionInfo> shared_info = info->shared_info(); |
| 694 scanner_.Initialize(source); | 695 scanner_.Initialize(source); |
| 695 ASSERT(top_scope_ == NULL); | 696 ASSERT(top_scope_ == NULL); |
| 696 ASSERT(target_stack_ == NULL); | 697 ASSERT(target_stack_ == NULL); |
| 697 | 698 |
| 698 Handle<String> name(String::cast(shared_info->name())); | 699 Handle<String> name(String::cast(shared_info->name())); |
| 699 fni_ = new(zone()) FuncNameInferrer(isolate()); | 700 fni_ = new(zone()) FuncNameInferrer(isolate(), zone()); |
| 700 fni_->PushEnclosingName(name); | 701 fni_->PushEnclosingName(name); |
| 701 | 702 |
| 702 mode_ = PARSE_EAGERLY; | 703 mode_ = PARSE_EAGERLY; |
| 703 | 704 |
| 704 // Place holder for the result. | 705 // Place holder for the result. |
| 705 FunctionLiteral* result = NULL; | 706 FunctionLiteral* result = NULL; |
| 706 | 707 |
| 707 { | 708 { |
| 708 // Parse the function literal. | 709 // Parse the function literal. |
| 709 Scope* scope = NewScope(top_scope_, GLOBAL_SCOPE); | 710 Scope* scope = NewScope(top_scope_, GLOBAL_SCOPE); |
| 710 info->SetGlobalScope(scope); | 711 info->SetGlobalScope(scope); |
| 711 if (!info->closure().is_null()) { | 712 if (!info->closure().is_null()) { |
| 712 scope = Scope::DeserializeScopeChain(info->closure()->context(), scope); | 713 scope = Scope::DeserializeScopeChain(info->closure()->context(), scope, |
| 714 zone()); |
| 713 } | 715 } |
| 714 FunctionState function_state(this, scope, isolate()); | 716 FunctionState function_state(this, scope, isolate()); |
| 715 ASSERT(scope->language_mode() != STRICT_MODE || !info->is_classic_mode()); | 717 ASSERT(scope->language_mode() != STRICT_MODE || !info->is_classic_mode()); |
| 716 ASSERT(scope->language_mode() != EXTENDED_MODE || | 718 ASSERT(scope->language_mode() != EXTENDED_MODE || |
| 717 info->is_extended_mode()); | 719 info->is_extended_mode()); |
| 718 ASSERT(info->language_mode() == shared_info->language_mode()); | 720 ASSERT(info->language_mode() == shared_info->language_mode()); |
| 719 scope->SetLanguageMode(shared_info->language_mode()); | 721 scope->SetLanguageMode(shared_info->language_mode()); |
| 720 FunctionLiteral::Type type = shared_info->is_expression() | 722 FunctionLiteral::Type type = shared_info->is_expression() |
| 721 ? (shared_info->is_anonymous() | 723 ? (shared_info->is_anonymous() |
| 722 ? FunctionLiteral::ANONYMOUS_EXPRESSION | 724 ? FunctionLiteral::ANONYMOUS_EXPRESSION |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 | 939 |
| 938 DISALLOW_COPY_AND_ASSIGN(InitializationBlockFinder); | 940 DISALLOW_COPY_AND_ASSIGN(InitializationBlockFinder); |
| 939 }; | 941 }; |
| 940 | 942 |
| 941 | 943 |
| 942 // A ThisNamedPropertyAssignmentFinder finds and marks statements of the form | 944 // A ThisNamedPropertyAssignmentFinder finds and marks statements of the form |
| 943 // this.x = ...;, where x is a named property. It also determines whether a | 945 // this.x = ...;, where x is a named property. It also determines whether a |
| 944 // function contains only assignments of this type. | 946 // function contains only assignments of this type. |
| 945 class ThisNamedPropertyAssignmentFinder : public ParserFinder { | 947 class ThisNamedPropertyAssignmentFinder : public ParserFinder { |
| 946 public: | 948 public: |
| 947 explicit ThisNamedPropertyAssignmentFinder(Isolate* isolate) | 949 ThisNamedPropertyAssignmentFinder(Isolate* isolate, Zone* zone) |
| 948 : isolate_(isolate), | 950 : isolate_(isolate), |
| 949 only_simple_this_property_assignments_(true), | 951 only_simple_this_property_assignments_(true), |
| 950 names_(0), | 952 names_(0, zone), |
| 951 assigned_arguments_(0), | 953 assigned_arguments_(0, zone), |
| 952 assigned_constants_(0) { | 954 assigned_constants_(0, zone), |
| 955 zone_(zone) { |
| 953 } | 956 } |
| 954 | 957 |
| 955 void Update(Scope* scope, Statement* stat) { | 958 void Update(Scope* scope, Statement* stat) { |
| 956 // Bail out if function already has property assignment that are | 959 // Bail out if function already has property assignment that are |
| 957 // not simple this property assignments. | 960 // not simple this property assignments. |
| 958 if (!only_simple_this_property_assignments_) { | 961 if (!only_simple_this_property_assignments_) { |
| 959 return; | 962 return; |
| 960 } | 963 } |
| 961 | 964 |
| 962 // Check whether this statement is of the form this.x = ...; | 965 // Check whether this statement is of the form this.x = ...; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 // simple enough that the ordering does not matter. | 1054 // simple enough that the ordering does not matter. |
| 1052 void AssignmentFromParameter(Handle<String> name, int index) { | 1055 void AssignmentFromParameter(Handle<String> name, int index) { |
| 1053 EnsureInitialized(); | 1056 EnsureInitialized(); |
| 1054 for (int i = 0; i < names_.length(); ++i) { | 1057 for (int i = 0; i < names_.length(); ++i) { |
| 1055 if (name->Equals(*names_[i])) { | 1058 if (name->Equals(*names_[i])) { |
| 1056 assigned_arguments_[i] = index; | 1059 assigned_arguments_[i] = index; |
| 1057 assigned_constants_[i] = isolate_->factory()->undefined_value(); | 1060 assigned_constants_[i] = isolate_->factory()->undefined_value(); |
| 1058 return; | 1061 return; |
| 1059 } | 1062 } |
| 1060 } | 1063 } |
| 1061 names_.Add(name); | 1064 names_.Add(name, zone()); |
| 1062 assigned_arguments_.Add(index); | 1065 assigned_arguments_.Add(index, zone()); |
| 1063 assigned_constants_.Add(isolate_->factory()->undefined_value()); | 1066 assigned_constants_.Add(isolate_->factory()->undefined_value(), zone()); |
| 1064 } | 1067 } |
| 1065 | 1068 |
| 1066 void AssignmentFromConstant(Handle<String> name, Handle<Object> value) { | 1069 void AssignmentFromConstant(Handle<String> name, Handle<Object> value) { |
| 1067 EnsureInitialized(); | 1070 EnsureInitialized(); |
| 1068 for (int i = 0; i < names_.length(); ++i) { | 1071 for (int i = 0; i < names_.length(); ++i) { |
| 1069 if (name->Equals(*names_[i])) { | 1072 if (name->Equals(*names_[i])) { |
| 1070 assigned_arguments_[i] = -1; | 1073 assigned_arguments_[i] = -1; |
| 1071 assigned_constants_[i] = value; | 1074 assigned_constants_[i] = value; |
| 1072 return; | 1075 return; |
| 1073 } | 1076 } |
| 1074 } | 1077 } |
| 1075 names_.Add(name); | 1078 names_.Add(name, zone()); |
| 1076 assigned_arguments_.Add(-1); | 1079 assigned_arguments_.Add(-1, zone()); |
| 1077 assigned_constants_.Add(value); | 1080 assigned_constants_.Add(value, zone()); |
| 1078 } | 1081 } |
| 1079 | 1082 |
| 1080 void AssignmentFromSomethingElse() { | 1083 void AssignmentFromSomethingElse() { |
| 1081 // The this assignment is not a simple one. | 1084 // The this assignment is not a simple one. |
| 1082 only_simple_this_property_assignments_ = false; | 1085 only_simple_this_property_assignments_ = false; |
| 1083 } | 1086 } |
| 1084 | 1087 |
| 1085 void EnsureInitialized() { | 1088 void EnsureInitialized() { |
| 1086 if (names_.capacity() == 0) { | 1089 if (names_.capacity() == 0) { |
| 1087 ASSERT(assigned_arguments_.capacity() == 0); | 1090 ASSERT(assigned_arguments_.capacity() == 0); |
| 1088 ASSERT(assigned_constants_.capacity() == 0); | 1091 ASSERT(assigned_constants_.capacity() == 0); |
| 1089 names_.Initialize(4); | 1092 names_.Initialize(4, zone()); |
| 1090 assigned_arguments_.Initialize(4); | 1093 assigned_arguments_.Initialize(4, zone()); |
| 1091 assigned_constants_.Initialize(4); | 1094 assigned_constants_.Initialize(4, zone()); |
| 1092 } | 1095 } |
| 1093 } | 1096 } |
| 1094 | 1097 |
| 1098 Zone* zone() const { return zone_; } |
| 1099 |
| 1095 Isolate* isolate_; | 1100 Isolate* isolate_; |
| 1096 bool only_simple_this_property_assignments_; | 1101 bool only_simple_this_property_assignments_; |
| 1097 ZoneStringList names_; | 1102 ZoneStringList names_; |
| 1098 ZoneList<int> assigned_arguments_; | 1103 ZoneList<int> assigned_arguments_; |
| 1099 ZoneObjectList assigned_constants_; | 1104 ZoneObjectList assigned_constants_; |
| 1105 Zone* zone_; |
| 1100 }; | 1106 }; |
| 1101 | 1107 |
| 1102 | 1108 |
| 1103 void* Parser::ParseSourceElements(ZoneList<Statement*>* processor, | 1109 void* Parser::ParseSourceElements(ZoneList<Statement*>* processor, |
| 1104 int end_token, | 1110 int end_token, |
| 1105 bool is_eval, | 1111 bool is_eval, |
| 1106 bool* ok) { | 1112 bool* ok) { |
| 1107 // SourceElements :: | 1113 // SourceElements :: |
| 1108 // (ModuleElement)* <end_token> | 1114 // (ModuleElement)* <end_token> |
| 1109 | 1115 |
| 1110 // Allocate a target stack to use for this set of source | 1116 // Allocate a target stack to use for this set of source |
| 1111 // elements. This way, all scripts and functions get their own | 1117 // elements. This way, all scripts and functions get their own |
| 1112 // target stack thus avoiding illegal breaks and continues across | 1118 // target stack thus avoiding illegal breaks and continues across |
| 1113 // functions. | 1119 // functions. |
| 1114 TargetScope scope(&this->target_stack_); | 1120 TargetScope scope(&this->target_stack_); |
| 1115 | 1121 |
| 1116 ASSERT(processor != NULL); | 1122 ASSERT(processor != NULL); |
| 1117 InitializationBlockFinder block_finder(top_scope_, target_stack_); | 1123 InitializationBlockFinder block_finder(top_scope_, target_stack_); |
| 1118 ThisNamedPropertyAssignmentFinder this_property_assignment_finder(isolate()); | 1124 ThisNamedPropertyAssignmentFinder this_property_assignment_finder(isolate(), |
| 1125 zone()); |
| 1119 bool directive_prologue = true; // Parsing directive prologue. | 1126 bool directive_prologue = true; // Parsing directive prologue. |
| 1120 | 1127 |
| 1121 while (peek() != end_token) { | 1128 while (peek() != end_token) { |
| 1122 if (directive_prologue && peek() != Token::STRING) { | 1129 if (directive_prologue && peek() != Token::STRING) { |
| 1123 directive_prologue = false; | 1130 directive_prologue = false; |
| 1124 } | 1131 } |
| 1125 | 1132 |
| 1126 Scanner::Location token_loc = scanner().peek_location(); | 1133 Scanner::Location token_loc = scanner().peek_location(); |
| 1127 Statement* stat = ParseModuleElement(NULL, CHECK_OK); | 1134 Statement* stat = ParseModuleElement(NULL, CHECK_OK); |
| 1128 if (stat == NULL || stat->IsEmpty()) { | 1135 if (stat == NULL || stat->IsEmpty()) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1166 // End of the directive prologue. | 1173 // End of the directive prologue. |
| 1167 directive_prologue = false; | 1174 directive_prologue = false; |
| 1168 } | 1175 } |
| 1169 } | 1176 } |
| 1170 | 1177 |
| 1171 block_finder.Update(stat); | 1178 block_finder.Update(stat); |
| 1172 // Find and mark all assignments to named properties in this (this.x =) | 1179 // Find and mark all assignments to named properties in this (this.x =) |
| 1173 if (top_scope_->is_function_scope()) { | 1180 if (top_scope_->is_function_scope()) { |
| 1174 this_property_assignment_finder.Update(top_scope_, stat); | 1181 this_property_assignment_finder.Update(top_scope_, stat); |
| 1175 } | 1182 } |
| 1176 processor->Add(stat); | 1183 processor->Add(stat, zone()); |
| 1177 } | 1184 } |
| 1178 | 1185 |
| 1179 // Propagate the collected information on this property assignments. | 1186 // Propagate the collected information on this property assignments. |
| 1180 if (top_scope_->is_function_scope()) { | 1187 if (top_scope_->is_function_scope()) { |
| 1181 bool only_simple_this_property_assignments = | 1188 bool only_simple_this_property_assignments = |
| 1182 this_property_assignment_finder.only_simple_this_property_assignments() | 1189 this_property_assignment_finder.only_simple_this_property_assignments() |
| 1183 && top_scope_->declarations()->length() == 0; | 1190 && top_scope_->declarations()->length() == 0; |
| 1184 if (only_simple_this_property_assignments) { | 1191 if (only_simple_this_property_assignments) { |
| 1185 current_function_state_->SetThisPropertyAssignmentInfo( | 1192 current_function_state_->SetThisPropertyAssignmentInfo( |
| 1186 only_simple_this_property_assignments, | 1193 only_simple_this_property_assignments, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1237 } | 1244 } |
| 1238 } | 1245 } |
| 1239 } | 1246 } |
| 1240 | 1247 |
| 1241 | 1248 |
| 1242 Block* Parser::ParseModuleDeclaration(ZoneStringList* names, bool* ok) { | 1249 Block* Parser::ParseModuleDeclaration(ZoneStringList* names, bool* ok) { |
| 1243 // ModuleDeclaration: | 1250 // ModuleDeclaration: |
| 1244 // 'module' Identifier Module | 1251 // 'module' Identifier Module |
| 1245 | 1252 |
| 1246 // Create new block with one expected declaration. | 1253 // Create new block with one expected declaration. |
| 1247 Block* block = factory()->NewBlock(NULL, 1, true); | 1254 Block* block = factory()->NewBlock(NULL, 1, true, zone()); |
| 1248 Handle<String> name = ParseIdentifier(CHECK_OK); | 1255 Handle<String> name = ParseIdentifier(CHECK_OK); |
| 1249 | 1256 |
| 1250 #ifdef DEBUG | 1257 #ifdef DEBUG |
| 1251 if (FLAG_print_interface_details) | 1258 if (FLAG_print_interface_details) |
| 1252 PrintF("# Module %s...\n", name->ToAsciiArray()); | 1259 PrintF("# Module %s...\n", name->ToAsciiArray()); |
| 1253 #endif | 1260 #endif |
| 1254 | 1261 |
| 1255 Module* module = ParseModule(CHECK_OK); | 1262 Module* module = ParseModule(CHECK_OK); |
| 1256 VariableProxy* proxy = NewUnresolved(name, LET, module->interface()); | 1263 VariableProxy* proxy = NewUnresolved(name, LET, module->interface()); |
| 1257 Declaration* declaration = | 1264 Declaration* declaration = |
| 1258 factory()->NewModuleDeclaration(proxy, module, top_scope_); | 1265 factory()->NewModuleDeclaration(proxy, module, top_scope_); |
| 1259 Declare(declaration, true, CHECK_OK); | 1266 Declare(declaration, true, CHECK_OK); |
| 1260 | 1267 |
| 1261 #ifdef DEBUG | 1268 #ifdef DEBUG |
| 1262 if (FLAG_print_interface_details) | 1269 if (FLAG_print_interface_details) |
| 1263 PrintF("# Module %s.\n", name->ToAsciiArray()); | 1270 PrintF("# Module %s.\n", name->ToAsciiArray()); |
| 1264 | 1271 |
| 1265 if (FLAG_print_interfaces) { | 1272 if (FLAG_print_interfaces) { |
| 1266 PrintF("module %s : ", name->ToAsciiArray()); | 1273 PrintF("module %s : ", name->ToAsciiArray()); |
| 1267 module->interface()->Print(); | 1274 module->interface()->Print(); |
| 1268 } | 1275 } |
| 1269 #endif | 1276 #endif |
| 1270 | 1277 |
| 1271 // TODO(rossberg): Add initialization statement to block. | 1278 // TODO(rossberg): Add initialization statement to block. |
| 1272 | 1279 |
| 1273 if (names) names->Add(name); | 1280 if (names) names->Add(name, zone()); |
| 1274 return block; | 1281 return block; |
| 1275 } | 1282 } |
| 1276 | 1283 |
| 1277 | 1284 |
| 1278 Module* Parser::ParseModule(bool* ok) { | 1285 Module* Parser::ParseModule(bool* ok) { |
| 1279 // Module: | 1286 // Module: |
| 1280 // '{' ModuleElement '}' | 1287 // '{' ModuleElement '}' |
| 1281 // '=' ModulePath ';' | 1288 // '=' ModulePath ';' |
| 1282 // 'at' String ';' | 1289 // 'at' String ';' |
| 1283 | 1290 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1300 } | 1307 } |
| 1301 } | 1308 } |
| 1302 } | 1309 } |
| 1303 | 1310 |
| 1304 | 1311 |
| 1305 Module* Parser::ParseModuleLiteral(bool* ok) { | 1312 Module* Parser::ParseModuleLiteral(bool* ok) { |
| 1306 // Module: | 1313 // Module: |
| 1307 // '{' ModuleElement '}' | 1314 // '{' ModuleElement '}' |
| 1308 | 1315 |
| 1309 // Construct block expecting 16 statements. | 1316 // Construct block expecting 16 statements. |
| 1310 Block* body = factory()->NewBlock(NULL, 16, false); | 1317 Block* body = factory()->NewBlock(NULL, 16, false, zone()); |
| 1311 #ifdef DEBUG | 1318 #ifdef DEBUG |
| 1312 if (FLAG_print_interface_details) PrintF("# Literal "); | 1319 if (FLAG_print_interface_details) PrintF("# Literal "); |
| 1313 #endif | 1320 #endif |
| 1314 Scope* scope = NewScope(top_scope_, MODULE_SCOPE); | 1321 Scope* scope = NewScope(top_scope_, MODULE_SCOPE); |
| 1315 | 1322 |
| 1316 Expect(Token::LBRACE, CHECK_OK); | 1323 Expect(Token::LBRACE, CHECK_OK); |
| 1317 scope->set_start_position(scanner().location().beg_pos); | 1324 scope->set_start_position(scanner().location().beg_pos); |
| 1318 scope->SetLanguageMode(EXTENDED_MODE); | 1325 scope->SetLanguageMode(EXTENDED_MODE); |
| 1319 | 1326 |
| 1320 { | 1327 { |
| 1321 BlockState block_state(this, scope); | 1328 BlockState block_state(this, scope); |
| 1322 TargetCollector collector; | 1329 TargetCollector collector(zone()); |
| 1323 Target target(&this->target_stack_, &collector); | 1330 Target target(&this->target_stack_, &collector); |
| 1324 Target target_body(&this->target_stack_, body); | 1331 Target target_body(&this->target_stack_, body); |
| 1325 InitializationBlockFinder block_finder(top_scope_, target_stack_); | 1332 InitializationBlockFinder block_finder(top_scope_, target_stack_); |
| 1326 | 1333 |
| 1327 while (peek() != Token::RBRACE) { | 1334 while (peek() != Token::RBRACE) { |
| 1328 Statement* stat = ParseModuleElement(NULL, CHECK_OK); | 1335 Statement* stat = ParseModuleElement(NULL, CHECK_OK); |
| 1329 if (stat && !stat->IsEmpty()) { | 1336 if (stat && !stat->IsEmpty()) { |
| 1330 body->AddStatement(stat, zone()); | 1337 body->AddStatement(stat, zone()); |
| 1331 block_finder.Update(stat); | 1338 block_finder.Update(stat); |
| 1332 } | 1339 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1357 // ModulePath '.' Identifier | 1364 // ModulePath '.' Identifier |
| 1358 | 1365 |
| 1359 Module* result = ParseModuleVariable(CHECK_OK); | 1366 Module* result = ParseModuleVariable(CHECK_OK); |
| 1360 while (Check(Token::PERIOD)) { | 1367 while (Check(Token::PERIOD)) { |
| 1361 Handle<String> name = ParseIdentifierName(CHECK_OK); | 1368 Handle<String> name = ParseIdentifierName(CHECK_OK); |
| 1362 #ifdef DEBUG | 1369 #ifdef DEBUG |
| 1363 if (FLAG_print_interface_details) | 1370 if (FLAG_print_interface_details) |
| 1364 PrintF("# Path .%s ", name->ToAsciiArray()); | 1371 PrintF("# Path .%s ", name->ToAsciiArray()); |
| 1365 #endif | 1372 #endif |
| 1366 Module* member = factory()->NewModulePath(result, name); | 1373 Module* member = factory()->NewModulePath(result, name); |
| 1367 result->interface()->Add(name, member->interface(), ok); | 1374 result->interface()->Add(name, member->interface(), zone(), ok); |
| 1368 if (!*ok) { | 1375 if (!*ok) { |
| 1369 #ifdef DEBUG | 1376 #ifdef DEBUG |
| 1370 if (FLAG_print_interfaces) { | 1377 if (FLAG_print_interfaces) { |
| 1371 PrintF("PATH TYPE ERROR at '%s'\n", name->ToAsciiArray()); | 1378 PrintF("PATH TYPE ERROR at '%s'\n", name->ToAsciiArray()); |
| 1372 PrintF("result: "); | 1379 PrintF("result: "); |
| 1373 result->interface()->Print(); | 1380 result->interface()->Print(); |
| 1374 PrintF("member: "); | 1381 PrintF("member: "); |
| 1375 member->interface()->Print(); | 1382 member->interface()->Print(); |
| 1376 } | 1383 } |
| 1377 #endif | 1384 #endif |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1388 Module* Parser::ParseModuleVariable(bool* ok) { | 1395 Module* Parser::ParseModuleVariable(bool* ok) { |
| 1389 // ModulePath: | 1396 // ModulePath: |
| 1390 // Identifier | 1397 // Identifier |
| 1391 | 1398 |
| 1392 Handle<String> name = ParseIdentifier(CHECK_OK); | 1399 Handle<String> name = ParseIdentifier(CHECK_OK); |
| 1393 #ifdef DEBUG | 1400 #ifdef DEBUG |
| 1394 if (FLAG_print_interface_details) | 1401 if (FLAG_print_interface_details) |
| 1395 PrintF("# Module variable %s ", name->ToAsciiArray()); | 1402 PrintF("# Module variable %s ", name->ToAsciiArray()); |
| 1396 #endif | 1403 #endif |
| 1397 VariableProxy* proxy = top_scope_->NewUnresolved( | 1404 VariableProxy* proxy = top_scope_->NewUnresolved( |
| 1398 factory(), name, scanner().location().beg_pos, Interface::NewModule()); | 1405 factory(), name, scanner().location().beg_pos, |
| 1406 Interface::NewModule(zone())); |
| 1399 | 1407 |
| 1400 return factory()->NewModuleVariable(proxy); | 1408 return factory()->NewModuleVariable(proxy); |
| 1401 } | 1409 } |
| 1402 | 1410 |
| 1403 | 1411 |
| 1404 Module* Parser::ParseModuleUrl(bool* ok) { | 1412 Module* Parser::ParseModuleUrl(bool* ok) { |
| 1405 // Module: | 1413 // Module: |
| 1406 // String | 1414 // String |
| 1407 | 1415 |
| 1408 Expect(Token::STRING, CHECK_OK); | 1416 Expect(Token::STRING, CHECK_OK); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1437 } | 1445 } |
| 1438 | 1446 |
| 1439 | 1447 |
| 1440 Block* Parser::ParseImportDeclaration(bool* ok) { | 1448 Block* Parser::ParseImportDeclaration(bool* ok) { |
| 1441 // ImportDeclaration: | 1449 // ImportDeclaration: |
| 1442 // 'import' IdentifierName (',' IdentifierName)* 'from' ModuleSpecifier ';' | 1450 // 'import' IdentifierName (',' IdentifierName)* 'from' ModuleSpecifier ';' |
| 1443 // | 1451 // |
| 1444 // TODO(ES6): implement destructuring ImportSpecifiers | 1452 // TODO(ES6): implement destructuring ImportSpecifiers |
| 1445 | 1453 |
| 1446 Expect(Token::IMPORT, CHECK_OK); | 1454 Expect(Token::IMPORT, CHECK_OK); |
| 1447 ZoneStringList names(1); | 1455 ZoneStringList names(1, zone()); |
| 1448 | 1456 |
| 1449 Handle<String> name = ParseIdentifierName(CHECK_OK); | 1457 Handle<String> name = ParseIdentifierName(CHECK_OK); |
| 1450 names.Add(name); | 1458 names.Add(name, zone()); |
| 1451 while (peek() == Token::COMMA) { | 1459 while (peek() == Token::COMMA) { |
| 1452 Consume(Token::COMMA); | 1460 Consume(Token::COMMA); |
| 1453 name = ParseIdentifierName(CHECK_OK); | 1461 name = ParseIdentifierName(CHECK_OK); |
| 1454 names.Add(name); | 1462 names.Add(name, zone()); |
| 1455 } | 1463 } |
| 1456 | 1464 |
| 1457 ExpectContextualKeyword("from", CHECK_OK); | 1465 ExpectContextualKeyword("from", CHECK_OK); |
| 1458 Module* module = ParseModuleSpecifier(CHECK_OK); | 1466 Module* module = ParseModuleSpecifier(CHECK_OK); |
| 1459 ExpectSemicolon(CHECK_OK); | 1467 ExpectSemicolon(CHECK_OK); |
| 1460 | 1468 |
| 1461 // Generate a separate declaration for each identifier. | 1469 // Generate a separate declaration for each identifier. |
| 1462 // TODO(ES6): once we implement destructuring, make that one declaration. | 1470 // TODO(ES6): once we implement destructuring, make that one declaration. |
| 1463 Block* block = factory()->NewBlock(NULL, 1, true); | 1471 Block* block = factory()->NewBlock(NULL, 1, true, zone()); |
| 1464 for (int i = 0; i < names.length(); ++i) { | 1472 for (int i = 0; i < names.length(); ++i) { |
| 1465 #ifdef DEBUG | 1473 #ifdef DEBUG |
| 1466 if (FLAG_print_interface_details) | 1474 if (FLAG_print_interface_details) |
| 1467 PrintF("# Import %s ", names[i]->ToAsciiArray()); | 1475 PrintF("# Import %s ", names[i]->ToAsciiArray()); |
| 1468 #endif | 1476 #endif |
| 1469 Interface* interface = Interface::NewUnknown(); | 1477 Interface* interface = Interface::NewUnknown(zone()); |
| 1470 module->interface()->Add(names[i], interface, ok); | 1478 module->interface()->Add(names[i], interface, zone(), ok); |
| 1471 if (!*ok) { | 1479 if (!*ok) { |
| 1472 #ifdef DEBUG | 1480 #ifdef DEBUG |
| 1473 if (FLAG_print_interfaces) { | 1481 if (FLAG_print_interfaces) { |
| 1474 PrintF("IMPORT TYPE ERROR at '%s'\n", names[i]->ToAsciiArray()); | 1482 PrintF("IMPORT TYPE ERROR at '%s'\n", names[i]->ToAsciiArray()); |
| 1475 PrintF("module: "); | 1483 PrintF("module: "); |
| 1476 module->interface()->Print(); | 1484 module->interface()->Print(); |
| 1477 } | 1485 } |
| 1478 #endif | 1486 #endif |
| 1479 ReportMessage("invalid_module_path", Vector<Handle<String> >(&name, 1)); | 1487 ReportMessage("invalid_module_path", Vector<Handle<String> >(&name, 1)); |
| 1480 return NULL; | 1488 return NULL; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1495 // 'export' Identifier (',' Identifier)* ';' | 1503 // 'export' Identifier (',' Identifier)* ';' |
| 1496 // 'export' VariableDeclaration | 1504 // 'export' VariableDeclaration |
| 1497 // 'export' FunctionDeclaration | 1505 // 'export' FunctionDeclaration |
| 1498 // 'export' ModuleDeclaration | 1506 // 'export' ModuleDeclaration |
| 1499 // | 1507 // |
| 1500 // TODO(ES6): implement structuring ExportSpecifiers | 1508 // TODO(ES6): implement structuring ExportSpecifiers |
| 1501 | 1509 |
| 1502 Expect(Token::EXPORT, CHECK_OK); | 1510 Expect(Token::EXPORT, CHECK_OK); |
| 1503 | 1511 |
| 1504 Statement* result = NULL; | 1512 Statement* result = NULL; |
| 1505 ZoneStringList names(1); | 1513 ZoneStringList names(1, zone()); |
| 1506 switch (peek()) { | 1514 switch (peek()) { |
| 1507 case Token::IDENTIFIER: { | 1515 case Token::IDENTIFIER: { |
| 1508 Handle<String> name = ParseIdentifier(CHECK_OK); | 1516 Handle<String> name = ParseIdentifier(CHECK_OK); |
| 1509 // Handle 'module' as a context-sensitive keyword. | 1517 // Handle 'module' as a context-sensitive keyword. |
| 1510 if (!name->IsEqualTo(CStrVector("module"))) { | 1518 if (!name->IsEqualTo(CStrVector("module"))) { |
| 1511 names.Add(name); | 1519 names.Add(name, zone()); |
| 1512 while (peek() == Token::COMMA) { | 1520 while (peek() == Token::COMMA) { |
| 1513 Consume(Token::COMMA); | 1521 Consume(Token::COMMA); |
| 1514 name = ParseIdentifier(CHECK_OK); | 1522 name = ParseIdentifier(CHECK_OK); |
| 1515 names.Add(name); | 1523 names.Add(name, zone()); |
| 1516 } | 1524 } |
| 1517 ExpectSemicolon(CHECK_OK); | 1525 ExpectSemicolon(CHECK_OK); |
| 1518 result = factory()->NewEmptyStatement(); | 1526 result = factory()->NewEmptyStatement(); |
| 1519 } else { | 1527 } else { |
| 1520 result = ParseModuleDeclaration(&names, CHECK_OK); | 1528 result = ParseModuleDeclaration(&names, CHECK_OK); |
| 1521 } | 1529 } |
| 1522 break; | 1530 break; |
| 1523 } | 1531 } |
| 1524 | 1532 |
| 1525 case Token::FUNCTION: | 1533 case Token::FUNCTION: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1538 return NULL; | 1546 return NULL; |
| 1539 } | 1547 } |
| 1540 | 1548 |
| 1541 // Extract declared names into export declarations and interface. | 1549 // Extract declared names into export declarations and interface. |
| 1542 Interface* interface = top_scope_->interface(); | 1550 Interface* interface = top_scope_->interface(); |
| 1543 for (int i = 0; i < names.length(); ++i) { | 1551 for (int i = 0; i < names.length(); ++i) { |
| 1544 #ifdef DEBUG | 1552 #ifdef DEBUG |
| 1545 if (FLAG_print_interface_details) | 1553 if (FLAG_print_interface_details) |
| 1546 PrintF("# Export %s ", names[i]->ToAsciiArray()); | 1554 PrintF("# Export %s ", names[i]->ToAsciiArray()); |
| 1547 #endif | 1555 #endif |
| 1548 Interface* inner = Interface::NewUnknown(); | 1556 Interface* inner = Interface::NewUnknown(zone()); |
| 1549 interface->Add(names[i], inner, CHECK_OK); | 1557 interface->Add(names[i], inner, zone(), CHECK_OK); |
| 1558 if (!*ok) |
| 1559 return NULL; |
| 1550 VariableProxy* proxy = NewUnresolved(names[i], LET, inner); | 1560 VariableProxy* proxy = NewUnresolved(names[i], LET, inner); |
| 1551 USE(proxy); | 1561 USE(proxy); |
| 1552 // TODO(rossberg): Rethink whether we actually need to store export | 1562 // TODO(rossberg): Rethink whether we actually need to store export |
| 1553 // declarations (for compilation?). | 1563 // declarations (for compilation?). |
| 1554 // ExportDeclaration* declaration = | 1564 // ExportDeclaration* declaration = |
| 1555 // factory()->NewExportDeclaration(proxy, top_scope_); | 1565 // factory()->NewExportDeclaration(proxy, top_scope_); |
| 1556 // top_scope_->AddDeclaration(declaration); | 1566 // top_scope_->AddDeclaration(declaration); |
| 1557 } | 1567 } |
| 1558 | 1568 |
| 1559 ASSERT(result != NULL); | 1569 ASSERT(result != NULL); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1666 case Token::THROW: | 1676 case Token::THROW: |
| 1667 stmt = ParseThrowStatement(ok); | 1677 stmt = ParseThrowStatement(ok); |
| 1668 break; | 1678 break; |
| 1669 | 1679 |
| 1670 case Token::TRY: { | 1680 case Token::TRY: { |
| 1671 // NOTE: It is somewhat complicated to have labels on | 1681 // NOTE: It is somewhat complicated to have labels on |
| 1672 // try-statements. When breaking out of a try-finally statement, | 1682 // try-statements. When breaking out of a try-finally statement, |
| 1673 // one must take great care not to treat it as a | 1683 // one must take great care not to treat it as a |
| 1674 // fall-through. It is much easier just to wrap the entire | 1684 // fall-through. It is much easier just to wrap the entire |
| 1675 // try-statement in a statement block and put the labels there | 1685 // try-statement in a statement block and put the labels there |
| 1676 Block* result = factory()->NewBlock(labels, 1, false); | 1686 Block* result = factory()->NewBlock(labels, 1, false, zone()); |
| 1677 Target target(&this->target_stack_, result); | 1687 Target target(&this->target_stack_, result); |
| 1678 TryStatement* statement = ParseTryStatement(CHECK_OK); | 1688 TryStatement* statement = ParseTryStatement(CHECK_OK); |
| 1679 if (statement) { | 1689 if (statement) { |
| 1680 statement->set_statement_pos(statement_pos); | 1690 statement->set_statement_pos(statement_pos); |
| 1681 } | 1691 } |
| 1682 if (result) result->AddStatement(statement, zone()); | 1692 if (result) result->AddStatement(statement, zone()); |
| 1683 return result; | 1693 return result; |
| 1684 } | 1694 } |
| 1685 | 1695 |
| 1686 case Token::FUNCTION: { | 1696 case Token::FUNCTION: { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1865 // runtime needs to provide both. | 1875 // runtime needs to provide both. |
| 1866 if (resolve && var != NULL) { | 1876 if (resolve && var != NULL) { |
| 1867 proxy->BindTo(var); | 1877 proxy->BindTo(var); |
| 1868 | 1878 |
| 1869 if (FLAG_harmony_modules) { | 1879 if (FLAG_harmony_modules) { |
| 1870 bool ok; | 1880 bool ok; |
| 1871 #ifdef DEBUG | 1881 #ifdef DEBUG |
| 1872 if (FLAG_print_interface_details) | 1882 if (FLAG_print_interface_details) |
| 1873 PrintF("# Declare %s\n", var->name()->ToAsciiArray()); | 1883 PrintF("# Declare %s\n", var->name()->ToAsciiArray()); |
| 1874 #endif | 1884 #endif |
| 1875 proxy->interface()->Unify(var->interface(), &ok); | 1885 proxy->interface()->Unify(var->interface(), zone(), &ok); |
| 1876 if (!ok) { | 1886 if (!ok) { |
| 1877 #ifdef DEBUG | 1887 #ifdef DEBUG |
| 1878 if (FLAG_print_interfaces) { | 1888 if (FLAG_print_interfaces) { |
| 1879 PrintF("DECLARE TYPE ERROR\n"); | 1889 PrintF("DECLARE TYPE ERROR\n"); |
| 1880 PrintF("proxy: "); | 1890 PrintF("proxy: "); |
| 1881 proxy->interface()->Print(); | 1891 proxy->interface()->Print(); |
| 1882 PrintF("var: "); | 1892 PrintF("var: "); |
| 1883 var->interface()->Print(); | 1893 var->interface()->Print(); |
| 1884 } | 1894 } |
| 1885 #endif | 1895 #endif |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1964 FunctionLiteral::DECLARATION, | 1974 FunctionLiteral::DECLARATION, |
| 1965 CHECK_OK); | 1975 CHECK_OK); |
| 1966 // Even if we're not at the top-level of the global or a function | 1976 // Even if we're not at the top-level of the global or a function |
| 1967 // scope, we treat is as such and introduce the function with it's | 1977 // scope, we treat is as such and introduce the function with it's |
| 1968 // initial value upon entering the corresponding scope. | 1978 // initial value upon entering the corresponding scope. |
| 1969 VariableMode mode = is_extended_mode() ? LET : VAR; | 1979 VariableMode mode = is_extended_mode() ? LET : VAR; |
| 1970 VariableProxy* proxy = NewUnresolved(name, mode); | 1980 VariableProxy* proxy = NewUnresolved(name, mode); |
| 1971 Declaration* declaration = | 1981 Declaration* declaration = |
| 1972 factory()->NewFunctionDeclaration(proxy, mode, fun, top_scope_); | 1982 factory()->NewFunctionDeclaration(proxy, mode, fun, top_scope_); |
| 1973 Declare(declaration, true, CHECK_OK); | 1983 Declare(declaration, true, CHECK_OK); |
| 1974 if (names) names->Add(name); | 1984 if (names) names->Add(name, zone()); |
| 1975 return factory()->NewEmptyStatement(); | 1985 return factory()->NewEmptyStatement(); |
| 1976 } | 1986 } |
| 1977 | 1987 |
| 1978 | 1988 |
| 1979 Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) { | 1989 Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) { |
| 1980 if (top_scope_->is_extended_mode()) return ParseScopedBlock(labels, ok); | 1990 if (top_scope_->is_extended_mode()) return ParseScopedBlock(labels, ok); |
| 1981 | 1991 |
| 1982 // Block :: | 1992 // Block :: |
| 1983 // '{' Statement* '}' | 1993 // '{' Statement* '}' |
| 1984 | 1994 |
| 1985 // Note that a Block does not introduce a new execution scope! | 1995 // Note that a Block does not introduce a new execution scope! |
| 1986 // (ECMA-262, 3rd, 12.2) | 1996 // (ECMA-262, 3rd, 12.2) |
| 1987 // | 1997 // |
| 1988 // Construct block expecting 16 statements. | 1998 // Construct block expecting 16 statements. |
| 1989 Block* result = factory()->NewBlock(labels, 16, false); | 1999 Block* result = factory()->NewBlock(labels, 16, false, zone()); |
| 1990 Target target(&this->target_stack_, result); | 2000 Target target(&this->target_stack_, result); |
| 1991 Expect(Token::LBRACE, CHECK_OK); | 2001 Expect(Token::LBRACE, CHECK_OK); |
| 1992 InitializationBlockFinder block_finder(top_scope_, target_stack_); | 2002 InitializationBlockFinder block_finder(top_scope_, target_stack_); |
| 1993 while (peek() != Token::RBRACE) { | 2003 while (peek() != Token::RBRACE) { |
| 1994 Statement* stat = ParseStatement(NULL, CHECK_OK); | 2004 Statement* stat = ParseStatement(NULL, CHECK_OK); |
| 1995 if (stat && !stat->IsEmpty()) { | 2005 if (stat && !stat->IsEmpty()) { |
| 1996 result->AddStatement(stat, zone()); | 2006 result->AddStatement(stat, zone()); |
| 1997 block_finder.Update(stat); | 2007 block_finder.Update(stat); |
| 1998 } | 2008 } |
| 1999 } | 2009 } |
| 2000 Expect(Token::RBRACE, CHECK_OK); | 2010 Expect(Token::RBRACE, CHECK_OK); |
| 2001 return result; | 2011 return result; |
| 2002 } | 2012 } |
| 2003 | 2013 |
| 2004 | 2014 |
| 2005 Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) { | 2015 Block* Parser::ParseScopedBlock(ZoneStringList* labels, bool* ok) { |
| 2006 // The harmony mode uses block elements instead of statements. | 2016 // The harmony mode uses block elements instead of statements. |
| 2007 // | 2017 // |
| 2008 // Block :: | 2018 // Block :: |
| 2009 // '{' BlockElement* '}' | 2019 // '{' BlockElement* '}' |
| 2010 | 2020 |
| 2011 // Construct block expecting 16 statements. | 2021 // Construct block expecting 16 statements. |
| 2012 Block* body = factory()->NewBlock(labels, 16, false); | 2022 Block* body = factory()->NewBlock(labels, 16, false, zone()); |
| 2013 Scope* block_scope = NewScope(top_scope_, BLOCK_SCOPE); | 2023 Scope* block_scope = NewScope(top_scope_, BLOCK_SCOPE); |
| 2014 | 2024 |
| 2015 // Parse the statements and collect escaping labels. | 2025 // Parse the statements and collect escaping labels. |
| 2016 Expect(Token::LBRACE, CHECK_OK); | 2026 Expect(Token::LBRACE, CHECK_OK); |
| 2017 block_scope->set_start_position(scanner().location().beg_pos); | 2027 block_scope->set_start_position(scanner().location().beg_pos); |
| 2018 { BlockState block_state(this, block_scope); | 2028 { BlockState block_state(this, block_scope); |
| 2019 TargetCollector collector; | 2029 TargetCollector collector(zone()); |
| 2020 Target target(&this->target_stack_, &collector); | 2030 Target target(&this->target_stack_, &collector); |
| 2021 Target target_body(&this->target_stack_, body); | 2031 Target target_body(&this->target_stack_, body); |
| 2022 InitializationBlockFinder block_finder(top_scope_, target_stack_); | 2032 InitializationBlockFinder block_finder(top_scope_, target_stack_); |
| 2023 | 2033 |
| 2024 while (peek() != Token::RBRACE) { | 2034 while (peek() != Token::RBRACE) { |
| 2025 Statement* stat = ParseBlockElement(NULL, CHECK_OK); | 2035 Statement* stat = ParseBlockElement(NULL, CHECK_OK); |
| 2026 if (stat && !stat->IsEmpty()) { | 2036 if (stat && !stat->IsEmpty()) { |
| 2027 body->AddStatement(stat, zone()); | 2037 body->AddStatement(stat, zone()); |
| 2028 block_finder.Update(stat); | 2038 block_finder.Update(stat); |
| 2029 } | 2039 } |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2159 // Scope declaration, and rewrite the source-level initialization into an | 2169 // Scope declaration, and rewrite the source-level initialization into an |
| 2160 // assignment statement. We use a block to collect multiple assignments. | 2170 // assignment statement. We use a block to collect multiple assignments. |
| 2161 // | 2171 // |
| 2162 // We mark the block as initializer block because we don't want the | 2172 // We mark the block as initializer block because we don't want the |
| 2163 // rewriter to add a '.result' assignment to such a block (to get compliant | 2173 // rewriter to add a '.result' assignment to such a block (to get compliant |
| 2164 // behavior for code such as print(eval('var x = 7')), and for cosmetic | 2174 // behavior for code such as print(eval('var x = 7')), and for cosmetic |
| 2165 // reasons when pretty-printing. Also, unless an assignment (initialization) | 2175 // reasons when pretty-printing. Also, unless an assignment (initialization) |
| 2166 // is inside an initializer block, it is ignored. | 2176 // is inside an initializer block, it is ignored. |
| 2167 // | 2177 // |
| 2168 // Create new block with one expected declaration. | 2178 // Create new block with one expected declaration. |
| 2169 Block* block = factory()->NewBlock(NULL, 1, true); | 2179 Block* block = factory()->NewBlock(NULL, 1, true, zone()); |
| 2170 int nvars = 0; // the number of variables declared | 2180 int nvars = 0; // the number of variables declared |
| 2171 Handle<String> name; | 2181 Handle<String> name; |
| 2172 do { | 2182 do { |
| 2173 if (fni_ != NULL) fni_->Enter(); | 2183 if (fni_ != NULL) fni_->Enter(); |
| 2174 | 2184 |
| 2175 // Parse variable name. | 2185 // Parse variable name. |
| 2176 if (nvars > 0) Consume(Token::COMMA); | 2186 if (nvars > 0) Consume(Token::COMMA); |
| 2177 name = ParseIdentifier(CHECK_OK); | 2187 name = ParseIdentifier(CHECK_OK); |
| 2178 if (fni_ != NULL) fni_->PushVariableName(name); | 2188 if (fni_ != NULL) fni_->PushVariableName(name); |
| 2179 | 2189 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2203 Declaration* declaration = | 2213 Declaration* declaration = |
| 2204 factory()->NewVariableDeclaration(proxy, mode, top_scope_); | 2214 factory()->NewVariableDeclaration(proxy, mode, top_scope_); |
| 2205 Declare(declaration, mode != VAR, CHECK_OK); | 2215 Declare(declaration, mode != VAR, CHECK_OK); |
| 2206 nvars++; | 2216 nvars++; |
| 2207 if (declaration_scope->num_var_or_const() > kMaxNumFunctionLocals) { | 2217 if (declaration_scope->num_var_or_const() > kMaxNumFunctionLocals) { |
| 2208 ReportMessageAt(scanner().location(), "too_many_variables", | 2218 ReportMessageAt(scanner().location(), "too_many_variables", |
| 2209 Vector<const char*>::empty()); | 2219 Vector<const char*>::empty()); |
| 2210 *ok = false; | 2220 *ok = false; |
| 2211 return NULL; | 2221 return NULL; |
| 2212 } | 2222 } |
| 2213 if (names) names->Add(name); | 2223 if (names) names->Add(name, zone()); |
| 2214 | 2224 |
| 2215 // Parse initialization expression if present and/or needed. A | 2225 // Parse initialization expression if present and/or needed. A |
| 2216 // declaration of the form: | 2226 // declaration of the form: |
| 2217 // | 2227 // |
| 2218 // var v = x; | 2228 // var v = x; |
| 2219 // | 2229 // |
| 2220 // is syntactic sugar for: | 2230 // is syntactic sugar for: |
| 2221 // | 2231 // |
| 2222 // var v; v = x; | 2232 // var v; v = x; |
| 2223 // | 2233 // |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2282 // Executing the variable declaration statement will always | 2292 // Executing the variable declaration statement will always |
| 2283 // guarantee to give the global object a "local" variable; a | 2293 // guarantee to give the global object a "local" variable; a |
| 2284 // variable defined in the global object and not in any | 2294 // variable defined in the global object and not in any |
| 2285 // prototype. This way, global variable declarations can shadow | 2295 // prototype. This way, global variable declarations can shadow |
| 2286 // properties in the prototype chain, but only after the variable | 2296 // properties in the prototype chain, but only after the variable |
| 2287 // declaration statement has been executed. This is important in | 2297 // declaration statement has been executed. This is important in |
| 2288 // browsers where the global object (window) has lots of | 2298 // browsers where the global object (window) has lots of |
| 2289 // properties defined in prototype objects. | 2299 // properties defined in prototype objects. |
| 2290 if (initialization_scope->is_global_scope()) { | 2300 if (initialization_scope->is_global_scope()) { |
| 2291 // Compute the arguments for the runtime call. | 2301 // Compute the arguments for the runtime call. |
| 2292 ZoneList<Expression*>* arguments = new(zone()) ZoneList<Expression*>(3); | 2302 ZoneList<Expression*>* arguments = |
| 2303 new(zone()) ZoneList<Expression*>(3, zone()); |
| 2293 // We have at least 1 parameter. | 2304 // We have at least 1 parameter. |
| 2294 arguments->Add(factory()->NewLiteral(name)); | 2305 arguments->Add(factory()->NewLiteral(name), zone()); |
| 2295 CallRuntime* initialize; | 2306 CallRuntime* initialize; |
| 2296 | 2307 |
| 2297 if (is_const) { | 2308 if (is_const) { |
| 2298 arguments->Add(value); | 2309 arguments->Add(value, zone()); |
| 2299 value = NULL; // zap the value to avoid the unnecessary assignment | 2310 value = NULL; // zap the value to avoid the unnecessary assignment |
| 2300 | 2311 |
| 2301 // Construct the call to Runtime_InitializeConstGlobal | 2312 // Construct the call to Runtime_InitializeConstGlobal |
| 2302 // and add it to the initialization statement block. | 2313 // and add it to the initialization statement block. |
| 2303 // Note that the function does different things depending on | 2314 // Note that the function does different things depending on |
| 2304 // the number of arguments (1 or 2). | 2315 // the number of arguments (1 or 2). |
| 2305 initialize = factory()->NewCallRuntime( | 2316 initialize = factory()->NewCallRuntime( |
| 2306 isolate()->factory()->InitializeConstGlobal_symbol(), | 2317 isolate()->factory()->InitializeConstGlobal_symbol(), |
| 2307 Runtime::FunctionForId(Runtime::kInitializeConstGlobal), | 2318 Runtime::FunctionForId(Runtime::kInitializeConstGlobal), |
| 2308 arguments); | 2319 arguments); |
| 2309 } else { | 2320 } else { |
| 2310 // Add strict mode. | 2321 // Add strict mode. |
| 2311 // We may want to pass singleton to avoid Literal allocations. | 2322 // We may want to pass singleton to avoid Literal allocations. |
| 2312 LanguageMode language_mode = initialization_scope->language_mode(); | 2323 LanguageMode language_mode = initialization_scope->language_mode(); |
| 2313 arguments->Add(factory()->NewNumberLiteral(language_mode)); | 2324 arguments->Add(factory()->NewNumberLiteral(language_mode), zone()); |
| 2314 | 2325 |
| 2315 // Be careful not to assign a value to the global variable if | 2326 // Be careful not to assign a value to the global variable if |
| 2316 // we're in a with. The initialization value should not | 2327 // we're in a with. The initialization value should not |
| 2317 // necessarily be stored in the global object in that case, | 2328 // necessarily be stored in the global object in that case, |
| 2318 // which is why we need to generate a separate assignment node. | 2329 // which is why we need to generate a separate assignment node. |
| 2319 if (value != NULL && !inside_with()) { | 2330 if (value != NULL && !inside_with()) { |
| 2320 arguments->Add(value); | 2331 arguments->Add(value, zone()); |
| 2321 value = NULL; // zap the value to avoid the unnecessary assignment | 2332 value = NULL; // zap the value to avoid the unnecessary assignment |
| 2322 } | 2333 } |
| 2323 | 2334 |
| 2324 // Construct the call to Runtime_InitializeVarGlobal | 2335 // Construct the call to Runtime_InitializeVarGlobal |
| 2325 // and add it to the initialization statement block. | 2336 // and add it to the initialization statement block. |
| 2326 // Note that the function does different things depending on | 2337 // Note that the function does different things depending on |
| 2327 // the number of arguments (2 or 3). | 2338 // the number of arguments (2 or 3). |
| 2328 initialize = factory()->NewCallRuntime( | 2339 initialize = factory()->NewCallRuntime( |
| 2329 isolate()->factory()->InitializeVarGlobal_symbol(), | 2340 isolate()->factory()->InitializeVarGlobal_symbol(), |
| 2330 Runtime::FunctionForId(Runtime::kInitializeVarGlobal), | 2341 Runtime::FunctionForId(Runtime::kInitializeVarGlobal), |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2410 // structured. However, these are probably changes we want to | 2421 // structured. However, these are probably changes we want to |
| 2411 // make later anyway so we should go back and fix this then. | 2422 // make later anyway so we should go back and fix this then. |
| 2412 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) { | 2423 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) { |
| 2413 SmartArrayPointer<char> c_string = label->ToCString(DISALLOW_NULLS); | 2424 SmartArrayPointer<char> c_string = label->ToCString(DISALLOW_NULLS); |
| 2414 const char* elms[2] = { "Label", *c_string }; | 2425 const char* elms[2] = { "Label", *c_string }; |
| 2415 Vector<const char*> args(elms, 2); | 2426 Vector<const char*> args(elms, 2); |
| 2416 ReportMessage("redeclaration", args); | 2427 ReportMessage("redeclaration", args); |
| 2417 *ok = false; | 2428 *ok = false; |
| 2418 return NULL; | 2429 return NULL; |
| 2419 } | 2430 } |
| 2420 if (labels == NULL) labels = new(zone()) ZoneStringList(4); | 2431 if (labels == NULL) { |
| 2421 labels->Add(label); | 2432 labels = new(zone()) ZoneStringList(4, zone()); |
| 2433 } |
| 2434 labels->Add(label, zone()); |
| 2422 // Remove the "ghost" variable that turned out to be a label | 2435 // Remove the "ghost" variable that turned out to be a label |
| 2423 // from the top scope. This way, we don't try to resolve it | 2436 // from the top scope. This way, we don't try to resolve it |
| 2424 // during the scope processing. | 2437 // during the scope processing. |
| 2425 top_scope_->RemoveUnresolved(var); | 2438 top_scope_->RemoveUnresolved(var); |
| 2426 Expect(Token::COLON, CHECK_OK); | 2439 Expect(Token::COLON, CHECK_OK); |
| 2427 return ParseStatement(labels, ok); | 2440 return ParseStatement(labels, ok); |
| 2428 } | 2441 } |
| 2429 | 2442 |
| 2430 // If we have an extension, we allow a native function declaration. | 2443 // If we have an extension, we allow a native function declaration. |
| 2431 // A native function declaration starts with "native function" with | 2444 // A native function declaration starts with "native function" with |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2623 if (*default_seen_ptr) { | 2636 if (*default_seen_ptr) { |
| 2624 ReportMessage("multiple_defaults_in_switch", | 2637 ReportMessage("multiple_defaults_in_switch", |
| 2625 Vector<const char*>::empty()); | 2638 Vector<const char*>::empty()); |
| 2626 *ok = false; | 2639 *ok = false; |
| 2627 return NULL; | 2640 return NULL; |
| 2628 } | 2641 } |
| 2629 *default_seen_ptr = true; | 2642 *default_seen_ptr = true; |
| 2630 } | 2643 } |
| 2631 Expect(Token::COLON, CHECK_OK); | 2644 Expect(Token::COLON, CHECK_OK); |
| 2632 int pos = scanner().location().beg_pos; | 2645 int pos = scanner().location().beg_pos; |
| 2633 ZoneList<Statement*>* statements = new(zone()) ZoneList<Statement*>(5); | 2646 ZoneList<Statement*>* statements = |
| 2647 new(zone()) ZoneList<Statement*>(5, zone()); |
| 2634 while (peek() != Token::CASE && | 2648 while (peek() != Token::CASE && |
| 2635 peek() != Token::DEFAULT && | 2649 peek() != Token::DEFAULT && |
| 2636 peek() != Token::RBRACE) { | 2650 peek() != Token::RBRACE) { |
| 2637 Statement* stat = ParseStatement(NULL, CHECK_OK); | 2651 Statement* stat = ParseStatement(NULL, CHECK_OK); |
| 2638 statements->Add(stat); | 2652 statements->Add(stat, zone()); |
| 2639 } | 2653 } |
| 2640 | 2654 |
| 2641 return new(zone()) CaseClause(isolate(), label, statements, pos); | 2655 return new(zone()) CaseClause(isolate(), label, statements, pos); |
| 2642 } | 2656 } |
| 2643 | 2657 |
| 2644 | 2658 |
| 2645 SwitchStatement* Parser::ParseSwitchStatement(ZoneStringList* labels, | 2659 SwitchStatement* Parser::ParseSwitchStatement(ZoneStringList* labels, |
| 2646 bool* ok) { | 2660 bool* ok) { |
| 2647 // SwitchStatement :: | 2661 // SwitchStatement :: |
| 2648 // 'switch' '(' Expression ')' '{' CaseClause* '}' | 2662 // 'switch' '(' Expression ')' '{' CaseClause* '}' |
| 2649 | 2663 |
| 2650 SwitchStatement* statement = factory()->NewSwitchStatement(labels); | 2664 SwitchStatement* statement = factory()->NewSwitchStatement(labels); |
| 2651 Target target(&this->target_stack_, statement); | 2665 Target target(&this->target_stack_, statement); |
| 2652 | 2666 |
| 2653 Expect(Token::SWITCH, CHECK_OK); | 2667 Expect(Token::SWITCH, CHECK_OK); |
| 2654 Expect(Token::LPAREN, CHECK_OK); | 2668 Expect(Token::LPAREN, CHECK_OK); |
| 2655 Expression* tag = ParseExpression(true, CHECK_OK); | 2669 Expression* tag = ParseExpression(true, CHECK_OK); |
| 2656 Expect(Token::RPAREN, CHECK_OK); | 2670 Expect(Token::RPAREN, CHECK_OK); |
| 2657 | 2671 |
| 2658 bool default_seen = false; | 2672 bool default_seen = false; |
| 2659 ZoneList<CaseClause*>* cases = new(zone()) ZoneList<CaseClause*>(4); | 2673 ZoneList<CaseClause*>* cases = new(zone()) ZoneList<CaseClause*>(4, zone()); |
| 2660 Expect(Token::LBRACE, CHECK_OK); | 2674 Expect(Token::LBRACE, CHECK_OK); |
| 2661 while (peek() != Token::RBRACE) { | 2675 while (peek() != Token::RBRACE) { |
| 2662 CaseClause* clause = ParseCaseClause(&default_seen, CHECK_OK); | 2676 CaseClause* clause = ParseCaseClause(&default_seen, CHECK_OK); |
| 2663 cases->Add(clause); | 2677 cases->Add(clause, zone()); |
| 2664 } | 2678 } |
| 2665 Expect(Token::RBRACE, CHECK_OK); | 2679 Expect(Token::RBRACE, CHECK_OK); |
| 2666 | 2680 |
| 2667 if (statement) statement->Initialize(tag, cases); | 2681 if (statement) statement->Initialize(tag, cases); |
| 2668 return statement; | 2682 return statement; |
| 2669 } | 2683 } |
| 2670 | 2684 |
| 2671 | 2685 |
| 2672 Statement* Parser::ParseThrowStatement(bool* ok) { | 2686 Statement* Parser::ParseThrowStatement(bool* ok) { |
| 2673 // ThrowStatement :: | 2687 // ThrowStatement :: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2694 // 'try' Block Catch Finally | 2708 // 'try' Block Catch Finally |
| 2695 // | 2709 // |
| 2696 // Catch :: | 2710 // Catch :: |
| 2697 // 'catch' '(' Identifier ')' Block | 2711 // 'catch' '(' Identifier ')' Block |
| 2698 // | 2712 // |
| 2699 // Finally :: | 2713 // Finally :: |
| 2700 // 'finally' Block | 2714 // 'finally' Block |
| 2701 | 2715 |
| 2702 Expect(Token::TRY, CHECK_OK); | 2716 Expect(Token::TRY, CHECK_OK); |
| 2703 | 2717 |
| 2704 TargetCollector try_collector; | 2718 TargetCollector try_collector(zone()); |
| 2705 Block* try_block; | 2719 Block* try_block; |
| 2706 | 2720 |
| 2707 { Target target(&this->target_stack_, &try_collector); | 2721 { Target target(&this->target_stack_, &try_collector); |
| 2708 try_block = ParseBlock(NULL, CHECK_OK); | 2722 try_block = ParseBlock(NULL, CHECK_OK); |
| 2709 } | 2723 } |
| 2710 | 2724 |
| 2711 Token::Value tok = peek(); | 2725 Token::Value tok = peek(); |
| 2712 if (tok != Token::CATCH && tok != Token::FINALLY) { | 2726 if (tok != Token::CATCH && tok != Token::FINALLY) { |
| 2713 ReportMessage("no_catch_or_finally", Vector<const char*>::empty()); | 2727 ReportMessage("no_catch_or_finally", Vector<const char*>::empty()); |
| 2714 *ok = false; | 2728 *ok = false; |
| 2715 return NULL; | 2729 return NULL; |
| 2716 } | 2730 } |
| 2717 | 2731 |
| 2718 // If we can break out from the catch block and there is a finally block, | 2732 // If we can break out from the catch block and there is a finally block, |
| 2719 // then we will need to collect escaping targets from the catch | 2733 // then we will need to collect escaping targets from the catch |
| 2720 // block. Since we don't know yet if there will be a finally block, we | 2734 // block. Since we don't know yet if there will be a finally block, we |
| 2721 // always collect the targets. | 2735 // always collect the targets. |
| 2722 TargetCollector catch_collector; | 2736 TargetCollector catch_collector(zone()); |
| 2723 Scope* catch_scope = NULL; | 2737 Scope* catch_scope = NULL; |
| 2724 Variable* catch_variable = NULL; | 2738 Variable* catch_variable = NULL; |
| 2725 Block* catch_block = NULL; | 2739 Block* catch_block = NULL; |
| 2726 Handle<String> name; | 2740 Handle<String> name; |
| 2727 if (tok == Token::CATCH) { | 2741 if (tok == Token::CATCH) { |
| 2728 Consume(Token::CATCH); | 2742 Consume(Token::CATCH); |
| 2729 | 2743 |
| 2730 Expect(Token::LPAREN, CHECK_OK); | 2744 Expect(Token::LPAREN, CHECK_OK); |
| 2731 catch_scope = NewScope(top_scope_, CATCH_SCOPE); | 2745 catch_scope = NewScope(top_scope_, CATCH_SCOPE); |
| 2732 catch_scope->set_start_position(scanner().location().beg_pos); | 2746 catch_scope->set_start_position(scanner().location().beg_pos); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2766 // to: | 2780 // to: |
| 2767 // 'try { try B0 catch B1 } finally B2' | 2781 // 'try { try B0 catch B1 } finally B2' |
| 2768 | 2782 |
| 2769 if (catch_block != NULL && finally_block != NULL) { | 2783 if (catch_block != NULL && finally_block != NULL) { |
| 2770 // If we have both, create an inner try/catch. | 2784 // If we have both, create an inner try/catch. |
| 2771 ASSERT(catch_scope != NULL && catch_variable != NULL); | 2785 ASSERT(catch_scope != NULL && catch_variable != NULL); |
| 2772 int index = current_function_state_->NextHandlerIndex(); | 2786 int index = current_function_state_->NextHandlerIndex(); |
| 2773 TryCatchStatement* statement = factory()->NewTryCatchStatement( | 2787 TryCatchStatement* statement = factory()->NewTryCatchStatement( |
| 2774 index, try_block, catch_scope, catch_variable, catch_block); | 2788 index, try_block, catch_scope, catch_variable, catch_block); |
| 2775 statement->set_escaping_targets(try_collector.targets()); | 2789 statement->set_escaping_targets(try_collector.targets()); |
| 2776 try_block = factory()->NewBlock(NULL, 1, false); | 2790 try_block = factory()->NewBlock(NULL, 1, false, zone()); |
| 2777 try_block->AddStatement(statement, zone()); | 2791 try_block->AddStatement(statement, zone()); |
| 2778 catch_block = NULL; // Clear to indicate it's been handled. | 2792 catch_block = NULL; // Clear to indicate it's been handled. |
| 2779 } | 2793 } |
| 2780 | 2794 |
| 2781 TryStatement* result = NULL; | 2795 TryStatement* result = NULL; |
| 2782 if (catch_block != NULL) { | 2796 if (catch_block != NULL) { |
| 2783 ASSERT(finally_block == NULL); | 2797 ASSERT(finally_block == NULL); |
| 2784 ASSERT(catch_scope != NULL && catch_variable != NULL); | 2798 ASSERT(catch_scope != NULL && catch_variable != NULL); |
| 2785 int index = current_function_state_->NextHandlerIndex(); | 2799 int index = current_function_state_->NextHandlerIndex(); |
| 2786 result = factory()->NewTryCatchStatement( | 2800 result = factory()->NewTryCatchStatement( |
| 2787 index, try_block, catch_scope, catch_variable, catch_block); | 2801 index, try_block, catch_scope, catch_variable, catch_block); |
| 2788 } else { | 2802 } else { |
| 2789 ASSERT(finally_block != NULL); | 2803 ASSERT(finally_block != NULL); |
| 2790 int index = current_function_state_->NextHandlerIndex(); | 2804 int index = current_function_state_->NextHandlerIndex(); |
| 2791 result = factory()->NewTryFinallyStatement(index, try_block, finally_block); | 2805 result = factory()->NewTryFinallyStatement(index, try_block, finally_block); |
| 2792 // Combine the jump targets of the try block and the possible catch block. | 2806 // Combine the jump targets of the try block and the possible catch block. |
| 2793 try_collector.targets()->AddAll(*catch_collector.targets()); | 2807 try_collector.targets()->AddAll(*catch_collector.targets(), zone()); |
| 2794 } | 2808 } |
| 2795 | 2809 |
| 2796 result->set_escaping_targets(try_collector.targets()); | 2810 result->set_escaping_targets(try_collector.targets()); |
| 2797 return result; | 2811 return result; |
| 2798 } | 2812 } |
| 2799 | 2813 |
| 2800 | 2814 |
| 2801 DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels, | 2815 DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels, |
| 2802 bool* ok) { | 2816 bool* ok) { |
| 2803 // DoStatement :: | 2817 // DoStatement :: |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2872 VariableProxy* each = top_scope_->NewUnresolved(factory(), name); | 2886 VariableProxy* each = top_scope_->NewUnresolved(factory(), name); |
| 2873 ForInStatement* loop = factory()->NewForInStatement(labels); | 2887 ForInStatement* loop = factory()->NewForInStatement(labels); |
| 2874 Target target(&this->target_stack_, loop); | 2888 Target target(&this->target_stack_, loop); |
| 2875 | 2889 |
| 2876 Expect(Token::IN, CHECK_OK); | 2890 Expect(Token::IN, CHECK_OK); |
| 2877 Expression* enumerable = ParseExpression(true, CHECK_OK); | 2891 Expression* enumerable = ParseExpression(true, CHECK_OK); |
| 2878 Expect(Token::RPAREN, CHECK_OK); | 2892 Expect(Token::RPAREN, CHECK_OK); |
| 2879 | 2893 |
| 2880 Statement* body = ParseStatement(NULL, CHECK_OK); | 2894 Statement* body = ParseStatement(NULL, CHECK_OK); |
| 2881 loop->Initialize(each, enumerable, body); | 2895 loop->Initialize(each, enumerable, body); |
| 2882 Block* result = factory()->NewBlock(NULL, 2, false); | 2896 Block* result = factory()->NewBlock(NULL, 2, false, zone()); |
| 2883 result->AddStatement(variable_statement, zone()); | 2897 result->AddStatement(variable_statement, zone()); |
| 2884 result->AddStatement(loop, zone()); | 2898 result->AddStatement(loop, zone()); |
| 2885 top_scope_ = saved_scope; | 2899 top_scope_ = saved_scope; |
| 2886 for_scope->set_end_position(scanner().location().end_pos); | 2900 for_scope->set_end_position(scanner().location().end_pos); |
| 2887 for_scope = for_scope->FinalizeBlockScope(); | 2901 for_scope = for_scope->FinalizeBlockScope(); |
| 2888 ASSERT(for_scope == NULL); | 2902 ASSERT(for_scope == NULL); |
| 2889 // Parsed for-in loop w/ variable/const declaration. | 2903 // Parsed for-in loop w/ variable/const declaration. |
| 2890 return result; | 2904 return result; |
| 2891 } else { | 2905 } else { |
| 2892 init = variable_statement; | 2906 init = variable_statement; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2918 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); | 2932 VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); |
| 2919 VariableProxy* each = top_scope_->NewUnresolved(factory(), name); | 2933 VariableProxy* each = top_scope_->NewUnresolved(factory(), name); |
| 2920 ForInStatement* loop = factory()->NewForInStatement(labels); | 2934 ForInStatement* loop = factory()->NewForInStatement(labels); |
| 2921 Target target(&this->target_stack_, loop); | 2935 Target target(&this->target_stack_, loop); |
| 2922 | 2936 |
| 2923 Expect(Token::IN, CHECK_OK); | 2937 Expect(Token::IN, CHECK_OK); |
| 2924 Expression* enumerable = ParseExpression(true, CHECK_OK); | 2938 Expression* enumerable = ParseExpression(true, CHECK_OK); |
| 2925 Expect(Token::RPAREN, CHECK_OK); | 2939 Expect(Token::RPAREN, CHECK_OK); |
| 2926 | 2940 |
| 2927 Statement* body = ParseStatement(NULL, CHECK_OK); | 2941 Statement* body = ParseStatement(NULL, CHECK_OK); |
| 2928 Block* body_block = factory()->NewBlock(NULL, 3, false); | 2942 Block* body_block = factory()->NewBlock(NULL, 3, false, zone()); |
| 2929 Assignment* assignment = factory()->NewAssignment( | 2943 Assignment* assignment = factory()->NewAssignment( |
| 2930 Token::ASSIGN, each, temp_proxy, RelocInfo::kNoPosition); | 2944 Token::ASSIGN, each, temp_proxy, RelocInfo::kNoPosition); |
| 2931 Statement* assignment_statement = | 2945 Statement* assignment_statement = |
| 2932 factory()->NewExpressionStatement(assignment); | 2946 factory()->NewExpressionStatement(assignment); |
| 2933 body_block->AddStatement(variable_statement, zone()); | 2947 body_block->AddStatement(variable_statement, zone()); |
| 2934 body_block->AddStatement(assignment_statement, zone()); | 2948 body_block->AddStatement(assignment_statement, zone()); |
| 2935 body_block->AddStatement(body, zone()); | 2949 body_block->AddStatement(body, zone()); |
| 2936 loop->Initialize(temp_proxy, enumerable, body_block); | 2950 loop->Initialize(temp_proxy, enumerable, body_block); |
| 2937 top_scope_ = saved_scope; | 2951 top_scope_ = saved_scope; |
| 2938 for_scope->set_end_position(scanner().location().end_pos); | 2952 for_scope->set_end_position(scanner().location().end_pos); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3007 // | 3021 // |
| 3008 // for (let x = i; c; n) b | 3022 // for (let x = i; c; n) b |
| 3009 // | 3023 // |
| 3010 // into | 3024 // into |
| 3011 // | 3025 // |
| 3012 // { | 3026 // { |
| 3013 // let x = i; | 3027 // let x = i; |
| 3014 // for (; c; n) b | 3028 // for (; c; n) b |
| 3015 // } | 3029 // } |
| 3016 ASSERT(init != NULL); | 3030 ASSERT(init != NULL); |
| 3017 Block* result = factory()->NewBlock(NULL, 2, false); | 3031 Block* result = factory()->NewBlock(NULL, 2, false, zone()); |
| 3018 result->AddStatement(init, zone()); | 3032 result->AddStatement(init, zone()); |
| 3019 result->AddStatement(loop, zone()); | 3033 result->AddStatement(loop, zone()); |
| 3020 result->set_scope(for_scope); | 3034 result->set_scope(for_scope); |
| 3021 if (loop) loop->Initialize(NULL, cond, next, body); | 3035 if (loop) loop->Initialize(NULL, cond, next, body); |
| 3022 return result; | 3036 return result; |
| 3023 } else { | 3037 } else { |
| 3024 if (loop) loop->Initialize(init, cond, next, body); | 3038 if (loop) loop->Initialize(init, cond, next, body); |
| 3025 return loop; | 3039 return loop; |
| 3026 } | 3040 } |
| 3027 } | 3041 } |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3452 Expression* result; | 3466 Expression* result; |
| 3453 if (peek() == Token::NEW) { | 3467 if (peek() == Token::NEW) { |
| 3454 result = ParseNewPrefix(stack, CHECK_OK); | 3468 result = ParseNewPrefix(stack, CHECK_OK); |
| 3455 } else { | 3469 } else { |
| 3456 result = ParseMemberWithNewPrefixesExpression(stack, CHECK_OK); | 3470 result = ParseMemberWithNewPrefixesExpression(stack, CHECK_OK); |
| 3457 } | 3471 } |
| 3458 | 3472 |
| 3459 if (!stack->is_empty()) { | 3473 if (!stack->is_empty()) { |
| 3460 int last = stack->pop(); | 3474 int last = stack->pop(); |
| 3461 result = factory()->NewCallNew( | 3475 result = factory()->NewCallNew( |
| 3462 result, new(zone()) ZoneList<Expression*>(0), last); | 3476 result, new(zone()) ZoneList<Expression*>(0, zone()), last); |
| 3463 } | 3477 } |
| 3464 return result; | 3478 return result; |
| 3465 } | 3479 } |
| 3466 | 3480 |
| 3467 | 3481 |
| 3468 Expression* Parser::ParseNewExpression(bool* ok) { | 3482 Expression* Parser::ParseNewExpression(bool* ok) { |
| 3469 PositionStack stack(ok); | 3483 PositionStack stack(ok); |
| 3470 return ParseNewPrefix(&stack, ok); | 3484 return ParseNewPrefix(&stack, ok); |
| 3471 } | 3485 } |
| 3472 | 3486 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3642 | 3656 |
| 3643 case Token::IDENTIFIER: | 3657 case Token::IDENTIFIER: |
| 3644 case Token::FUTURE_STRICT_RESERVED_WORD: { | 3658 case Token::FUTURE_STRICT_RESERVED_WORD: { |
| 3645 Handle<String> name = ParseIdentifier(CHECK_OK); | 3659 Handle<String> name = ParseIdentifier(CHECK_OK); |
| 3646 if (fni_ != NULL) fni_->PushVariableName(name); | 3660 if (fni_ != NULL) fni_->PushVariableName(name); |
| 3647 // The name may refer to a module instance object, so its type is unknown. | 3661 // The name may refer to a module instance object, so its type is unknown. |
| 3648 #ifdef DEBUG | 3662 #ifdef DEBUG |
| 3649 if (FLAG_print_interface_details) | 3663 if (FLAG_print_interface_details) |
| 3650 PrintF("# Variable %s ", name->ToAsciiArray()); | 3664 PrintF("# Variable %s ", name->ToAsciiArray()); |
| 3651 #endif | 3665 #endif |
| 3652 Interface* interface = Interface::NewUnknown(); | 3666 Interface* interface = Interface::NewUnknown(zone()); |
| 3653 result = top_scope_->NewUnresolved( | 3667 result = top_scope_->NewUnresolved( |
| 3654 factory(), name, scanner().location().beg_pos, interface); | 3668 factory(), name, scanner().location().beg_pos, interface); |
| 3655 break; | 3669 break; |
| 3656 } | 3670 } |
| 3657 | 3671 |
| 3658 case Token::NUMBER: { | 3672 case Token::NUMBER: { |
| 3659 Consume(Token::NUMBER); | 3673 Consume(Token::NUMBER); |
| 3660 ASSERT(scanner().is_literal_ascii()); | 3674 ASSERT(scanner().is_literal_ascii()); |
| 3661 double value = StringToDouble(isolate()->unicode_cache(), | 3675 double value = StringToDouble(isolate()->unicode_cache(), |
| 3662 scanner().literal_ascii_string(), | 3676 scanner().literal_ascii_string(), |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3742 | 3756 |
| 3743 *is_simple = is_simple_acc; | 3757 *is_simple = is_simple_acc; |
| 3744 *depth = depth_acc; | 3758 *depth = depth_acc; |
| 3745 } | 3759 } |
| 3746 | 3760 |
| 3747 | 3761 |
| 3748 Expression* Parser::ParseArrayLiteral(bool* ok) { | 3762 Expression* Parser::ParseArrayLiteral(bool* ok) { |
| 3749 // ArrayLiteral :: | 3763 // ArrayLiteral :: |
| 3750 // '[' Expression? (',' Expression?)* ']' | 3764 // '[' Expression? (',' Expression?)* ']' |
| 3751 | 3765 |
| 3752 ZoneList<Expression*>* values = new(zone()) ZoneList<Expression*>(4); | 3766 ZoneList<Expression*>* values = new(zone()) ZoneList<Expression*>(4, zone()); |
| 3753 Expect(Token::LBRACK, CHECK_OK); | 3767 Expect(Token::LBRACK, CHECK_OK); |
| 3754 while (peek() != Token::RBRACK) { | 3768 while (peek() != Token::RBRACK) { |
| 3755 Expression* elem; | 3769 Expression* elem; |
| 3756 if (peek() == Token::COMMA) { | 3770 if (peek() == Token::COMMA) { |
| 3757 elem = GetLiteralTheHole(); | 3771 elem = GetLiteralTheHole(); |
| 3758 } else { | 3772 } else { |
| 3759 elem = ParseAssignmentExpression(true, CHECK_OK); | 3773 elem = ParseAssignmentExpression(true, CHECK_OK); |
| 3760 } | 3774 } |
| 3761 values->Add(elem); | 3775 values->Add(elem, zone()); |
| 3762 if (peek() != Token::RBRACK) { | 3776 if (peek() != Token::RBRACK) { |
| 3763 Expect(Token::COMMA, CHECK_OK); | 3777 Expect(Token::COMMA, CHECK_OK); |
| 3764 } | 3778 } |
| 3765 } | 3779 } |
| 3766 Expect(Token::RBRACK, CHECK_OK); | 3780 Expect(Token::RBRACK, CHECK_OK); |
| 3767 | 3781 |
| 3768 // Update the scope information before the pre-parsing bailout. | 3782 // Update the scope information before the pre-parsing bailout. |
| 3769 int literal_index = current_function_state_->NextMaterializedLiteralIndex(); | 3783 int literal_index = current_function_state_->NextMaterializedLiteralIndex(); |
| 3770 | 3784 |
| 3771 // Allocate a fixed array to hold all the object literals. | 3785 // Allocate a fixed array to hold all the object literals. |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4120 | 4134 |
| 4121 | 4135 |
| 4122 Expression* Parser::ParseObjectLiteral(bool* ok) { | 4136 Expression* Parser::ParseObjectLiteral(bool* ok) { |
| 4123 // ObjectLiteral :: | 4137 // ObjectLiteral :: |
| 4124 // '{' ( | 4138 // '{' ( |
| 4125 // ((IdentifierName | String | Number) ':' AssignmentExpression) | 4139 // ((IdentifierName | String | Number) ':' AssignmentExpression) |
| 4126 // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral) | 4140 // | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral) |
| 4127 // )*[','] '}' | 4141 // )*[','] '}' |
| 4128 | 4142 |
| 4129 ZoneList<ObjectLiteral::Property*>* properties = | 4143 ZoneList<ObjectLiteral::Property*>* properties = |
| 4130 new(zone()) ZoneList<ObjectLiteral::Property*>(4); | 4144 new(zone()) ZoneList<ObjectLiteral::Property*>(4, zone()); |
| 4131 int number_of_boilerplate_properties = 0; | 4145 int number_of_boilerplate_properties = 0; |
| 4132 bool has_function = false; | 4146 bool has_function = false; |
| 4133 | 4147 |
| 4134 ObjectLiteralPropertyChecker checker(this, top_scope_->language_mode()); | 4148 ObjectLiteralPropertyChecker checker(this, top_scope_->language_mode()); |
| 4135 | 4149 |
| 4136 Expect(Token::LBRACE, CHECK_OK); | 4150 Expect(Token::LBRACE, CHECK_OK); |
| 4137 | 4151 |
| 4138 while (peek() != Token::RBRACE) { | 4152 while (peek() != Token::RBRACE) { |
| 4139 if (fni_ != NULL) fni_->Enter(); | 4153 if (fni_ != NULL) fni_->Enter(); |
| 4140 | 4154 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 4157 if ((is_getter || is_setter) && peek() != Token::COLON) { | 4171 if ((is_getter || is_setter) && peek() != Token::COLON) { |
| 4158 // Update loc to point to the identifier | 4172 // Update loc to point to the identifier |
| 4159 loc = scanner().peek_location(); | 4173 loc = scanner().peek_location(); |
| 4160 ObjectLiteral::Property* property = | 4174 ObjectLiteral::Property* property = |
| 4161 ParseObjectLiteralGetSet(is_getter, CHECK_OK); | 4175 ParseObjectLiteralGetSet(is_getter, CHECK_OK); |
| 4162 if (IsBoilerplateProperty(property)) { | 4176 if (IsBoilerplateProperty(property)) { |
| 4163 number_of_boilerplate_properties++; | 4177 number_of_boilerplate_properties++; |
| 4164 } | 4178 } |
| 4165 // Validate the property. | 4179 // Validate the property. |
| 4166 checker.CheckProperty(property, loc, CHECK_OK); | 4180 checker.CheckProperty(property, loc, CHECK_OK); |
| 4167 properties->Add(property); | 4181 properties->Add(property, zone()); |
| 4168 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK); | 4182 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK); |
| 4169 | 4183 |
| 4170 if (fni_ != NULL) { | 4184 if (fni_ != NULL) { |
| 4171 fni_->Infer(); | 4185 fni_->Infer(); |
| 4172 fni_->Leave(); | 4186 fni_->Leave(); |
| 4173 } | 4187 } |
| 4174 continue; // restart the while | 4188 continue; // restart the while |
| 4175 } | 4189 } |
| 4176 // Failed to parse as get/set property, so it's just a property | 4190 // Failed to parse as get/set property, so it's just a property |
| 4177 // called "get" or "set". | 4191 // called "get" or "set". |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4225 if (top_scope_->DeclarationScope()->is_global_scope() && | 4239 if (top_scope_->DeclarationScope()->is_global_scope() && |
| 4226 value->AsFunctionLiteral() != NULL) { | 4240 value->AsFunctionLiteral() != NULL) { |
| 4227 has_function = true; | 4241 has_function = true; |
| 4228 value->AsFunctionLiteral()->set_pretenure(); | 4242 value->AsFunctionLiteral()->set_pretenure(); |
| 4229 } | 4243 } |
| 4230 | 4244 |
| 4231 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. | 4245 // Count CONSTANT or COMPUTED properties to maintain the enumeration order. |
| 4232 if (IsBoilerplateProperty(property)) number_of_boilerplate_properties++; | 4246 if (IsBoilerplateProperty(property)) number_of_boilerplate_properties++; |
| 4233 // Validate the property | 4247 // Validate the property |
| 4234 checker.CheckProperty(property, loc, CHECK_OK); | 4248 checker.CheckProperty(property, loc, CHECK_OK); |
| 4235 properties->Add(property); | 4249 properties->Add(property, zone()); |
| 4236 | 4250 |
| 4237 // TODO(1240767): Consider allowing trailing comma. | 4251 // TODO(1240767): Consider allowing trailing comma. |
| 4238 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK); | 4252 if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK); |
| 4239 | 4253 |
| 4240 if (fni_ != NULL) { | 4254 if (fni_ != NULL) { |
| 4241 fni_->Infer(); | 4255 fni_->Infer(); |
| 4242 fni_->Leave(); | 4256 fni_->Leave(); |
| 4243 } | 4257 } |
| 4244 } | 4258 } |
| 4245 Expect(Token::RBRACE, CHECK_OK); | 4259 Expect(Token::RBRACE, CHECK_OK); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4284 Next(); | 4298 Next(); |
| 4285 | 4299 |
| 4286 return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index); | 4300 return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index); |
| 4287 } | 4301 } |
| 4288 | 4302 |
| 4289 | 4303 |
| 4290 ZoneList<Expression*>* Parser::ParseArguments(bool* ok) { | 4304 ZoneList<Expression*>* Parser::ParseArguments(bool* ok) { |
| 4291 // Arguments :: | 4305 // Arguments :: |
| 4292 // '(' (AssignmentExpression)*[','] ')' | 4306 // '(' (AssignmentExpression)*[','] ')' |
| 4293 | 4307 |
| 4294 ZoneList<Expression*>* result = new(zone()) ZoneList<Expression*>(4); | 4308 ZoneList<Expression*>* result = new(zone()) ZoneList<Expression*>(4, zone()); |
| 4295 Expect(Token::LPAREN, CHECK_OK); | 4309 Expect(Token::LPAREN, CHECK_OK); |
| 4296 bool done = (peek() == Token::RPAREN); | 4310 bool done = (peek() == Token::RPAREN); |
| 4297 while (!done) { | 4311 while (!done) { |
| 4298 Expression* argument = ParseAssignmentExpression(true, CHECK_OK); | 4312 Expression* argument = ParseAssignmentExpression(true, CHECK_OK); |
| 4299 result->Add(argument); | 4313 result->Add(argument, zone()); |
| 4300 if (result->length() > kMaxNumFunctionParameters) { | 4314 if (result->length() > kMaxNumFunctionParameters) { |
| 4301 ReportMessageAt(scanner().location(), "too_many_arguments", | 4315 ReportMessageAt(scanner().location(), "too_many_arguments", |
| 4302 Vector<const char*>::empty()); | 4316 Vector<const char*>::empty()); |
| 4303 *ok = false; | 4317 *ok = false; |
| 4304 return NULL; | 4318 return NULL; |
| 4305 } | 4319 } |
| 4306 done = (peek() == Token::RPAREN); | 4320 done = (peek() == Token::RPAREN); |
| 4307 if (!done) Expect(Token::COMMA, CHECK_OK); | 4321 if (!done) Expect(Token::COMMA, CHECK_OK); |
| 4308 } | 4322 } |
| 4309 Expect(Token::RPAREN, CHECK_OK); | 4323 Expect(Token::RPAREN, CHECK_OK); |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4578 scope->end_position() - function_block_pos); | 4592 scope->end_position() - function_block_pos); |
| 4579 materialized_literal_count = logger.literals(); | 4593 materialized_literal_count = logger.literals(); |
| 4580 expected_property_count = logger.properties(); | 4594 expected_property_count = logger.properties(); |
| 4581 top_scope_->SetLanguageMode(logger.language_mode()); | 4595 top_scope_->SetLanguageMode(logger.language_mode()); |
| 4582 only_simple_this_property_assignments = false; | 4596 only_simple_this_property_assignments = false; |
| 4583 this_property_assignments = isolate()->factory()->empty_fixed_array(); | 4597 this_property_assignments = isolate()->factory()->empty_fixed_array(); |
| 4584 } | 4598 } |
| 4585 } | 4599 } |
| 4586 | 4600 |
| 4587 if (!is_lazily_compiled) { | 4601 if (!is_lazily_compiled) { |
| 4588 body = new(zone()) ZoneList<Statement*>(8); | 4602 body = new(zone()) ZoneList<Statement*>(8, zone()); |
| 4589 if (fvar != NULL) { | 4603 if (fvar != NULL) { |
| 4590 VariableProxy* fproxy = | 4604 VariableProxy* fproxy = |
| 4591 top_scope_->NewUnresolved(factory(), function_name); | 4605 top_scope_->NewUnresolved(factory(), function_name); |
| 4592 fproxy->BindTo(fvar); | 4606 fproxy->BindTo(fvar); |
| 4593 body->Add(factory()->NewExpressionStatement( | 4607 body->Add(factory()->NewExpressionStatement( |
| 4594 factory()->NewAssignment(fvar_init_op, | 4608 factory()->NewAssignment(fvar_init_op, |
| 4595 fproxy, | 4609 fproxy, |
| 4596 factory()->NewThisFunction(), | 4610 factory()->NewThisFunction(), |
| 4597 RelocInfo::kNoPosition))); | 4611 RelocInfo::kNoPosition)), |
| 4612 zone()); |
| 4598 } | 4613 } |
| 4599 ParseSourceElements(body, Token::RBRACE, false, CHECK_OK); | 4614 ParseSourceElements(body, Token::RBRACE, false, CHECK_OK); |
| 4600 | 4615 |
| 4601 materialized_literal_count = function_state.materialized_literal_count(); | 4616 materialized_literal_count = function_state.materialized_literal_count(); |
| 4602 expected_property_count = function_state.expected_property_count(); | 4617 expected_property_count = function_state.expected_property_count(); |
| 4603 handler_count = function_state.handler_count(); | 4618 handler_count = function_state.handler_count(); |
| 4604 only_simple_this_property_assignments = | 4619 only_simple_this_property_assignments = |
| 4605 function_state.only_simple_this_property_assignments(); | 4620 function_state.only_simple_this_property_assignments(); |
| 4606 this_property_assignments = function_state.this_property_assignments(); | 4621 this_property_assignments = function_state.this_property_assignments(); |
| 4607 | 4622 |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4986 return NULL; | 5001 return NULL; |
| 4987 } | 5002 } |
| 4988 | 5003 |
| 4989 | 5004 |
| 4990 void Parser::RegisterTargetUse(Label* target, Target* stop) { | 5005 void Parser::RegisterTargetUse(Label* target, Target* stop) { |
| 4991 // Register that a break target found at the given stop in the | 5006 // Register that a break target found at the given stop in the |
| 4992 // target stack has been used from the top of the target stack. Add | 5007 // target stack has been used from the top of the target stack. Add |
| 4993 // the break target to any TargetCollectors passed on the stack. | 5008 // the break target to any TargetCollectors passed on the stack. |
| 4994 for (Target* t = target_stack_; t != stop; t = t->previous()) { | 5009 for (Target* t = target_stack_; t != stop; t = t->previous()) { |
| 4995 TargetCollector* collector = t->node()->AsTargetCollector(); | 5010 TargetCollector* collector = t->node()->AsTargetCollector(); |
| 4996 if (collector != NULL) collector->AddTarget(target); | 5011 if (collector != NULL) collector->AddTarget(target, zone()); |
| 4997 } | 5012 } |
| 4998 } | 5013 } |
| 4999 | 5014 |
| 5000 | 5015 |
| 5001 Expression* Parser::NewThrowReferenceError(Handle<String> type) { | 5016 Expression* Parser::NewThrowReferenceError(Handle<String> type) { |
| 5002 return NewThrowError(isolate()->factory()->MakeReferenceError_symbol(), | 5017 return NewThrowError(isolate()->factory()->MakeReferenceError_symbol(), |
| 5003 type, HandleVector<Object>(NULL, 0)); | 5018 type, HandleVector<Object>(NULL, 0)); |
| 5004 } | 5019 } |
| 5005 | 5020 |
| 5006 | 5021 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 5033 TENURED); | 5048 TENURED); |
| 5034 for (int i = 0; i < argc; i++) { | 5049 for (int i = 0; i < argc; i++) { |
| 5035 Handle<Object> element = arguments[i]; | 5050 Handle<Object> element = arguments[i]; |
| 5036 if (!element.is_null()) { | 5051 if (!element.is_null()) { |
| 5037 elements->set(i, *element); | 5052 elements->set(i, *element); |
| 5038 } | 5053 } |
| 5039 } | 5054 } |
| 5040 Handle<JSArray> array = isolate()->factory()->NewJSArrayWithElements( | 5055 Handle<JSArray> array = isolate()->factory()->NewJSArrayWithElements( |
| 5041 elements, FAST_ELEMENTS, TENURED); | 5056 elements, FAST_ELEMENTS, TENURED); |
| 5042 | 5057 |
| 5043 ZoneList<Expression*>* args = new(zone()) ZoneList<Expression*>(2); | 5058 ZoneList<Expression*>* args = new(zone()) ZoneList<Expression*>(2, zone()); |
| 5044 args->Add(factory()->NewLiteral(type)); | 5059 args->Add(factory()->NewLiteral(type), zone()); |
| 5045 args->Add(factory()->NewLiteral(array)); | 5060 args->Add(factory()->NewLiteral(array), zone()); |
| 5046 CallRuntime* call_constructor = | 5061 CallRuntime* call_constructor = |
| 5047 factory()->NewCallRuntime(constructor, NULL, args); | 5062 factory()->NewCallRuntime(constructor, NULL, args); |
| 5048 return factory()->NewThrow(call_constructor, scanner().location().beg_pos); | 5063 return factory()->NewThrow(call_constructor, scanner().location().beg_pos); |
| 5049 } | 5064 } |
| 5050 | 5065 |
| 5051 // ---------------------------------------------------------------------------- | 5066 // ---------------------------------------------------------------------------- |
| 5052 // Regular expressions | 5067 // Regular expressions |
| 5053 | 5068 |
| 5054 | 5069 |
| 5055 RegExpParser::RegExpParser(FlatStringReader* in, | 5070 RegExpParser::RegExpParser(FlatStringReader* in, |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5229 RegExpAssertion::Type type = | 5244 RegExpAssertion::Type type = |
| 5230 multiline_ ? RegExpAssertion::END_OF_LINE : | 5245 multiline_ ? RegExpAssertion::END_OF_LINE : |
| 5231 RegExpAssertion::END_OF_INPUT; | 5246 RegExpAssertion::END_OF_INPUT; |
| 5232 builder->AddAssertion(new(zone()) RegExpAssertion(type)); | 5247 builder->AddAssertion(new(zone()) RegExpAssertion(type)); |
| 5233 continue; | 5248 continue; |
| 5234 } | 5249 } |
| 5235 case '.': { | 5250 case '.': { |
| 5236 Advance(); | 5251 Advance(); |
| 5237 // everything except \x0a, \x0d, \u2028 and \u2029 | 5252 // everything except \x0a, \x0d, \u2028 and \u2029 |
| 5238 ZoneList<CharacterRange>* ranges = | 5253 ZoneList<CharacterRange>* ranges = |
| 5239 new(zone()) ZoneList<CharacterRange>(2); | 5254 new(zone()) ZoneList<CharacterRange>(2, zone()); |
| 5240 CharacterRange::AddClassEscape('.', ranges); | 5255 CharacterRange::AddClassEscape('.', ranges, zone()); |
| 5241 RegExpTree* atom = new(zone()) RegExpCharacterClass(ranges, false); | 5256 RegExpTree* atom = new(zone()) RegExpCharacterClass(ranges, false); |
| 5242 builder->AddAtom(atom); | 5257 builder->AddAtom(atom); |
| 5243 break; | 5258 break; |
| 5244 } | 5259 } |
| 5245 case '(': { | 5260 case '(': { |
| 5246 SubexpressionType type = CAPTURE; | 5261 SubexpressionType type = CAPTURE; |
| 5247 Advance(); | 5262 Advance(); |
| 5248 if (current() == '?') { | 5263 if (current() == '?') { |
| 5249 switch (Next()) { | 5264 switch (Next()) { |
| 5250 case ':': | 5265 case ':': |
| 5251 type = GROUPING; | 5266 type = GROUPING; |
| 5252 break; | 5267 break; |
| 5253 case '=': | 5268 case '=': |
| 5254 type = POSITIVE_LOOKAHEAD; | 5269 type = POSITIVE_LOOKAHEAD; |
| 5255 break; | 5270 break; |
| 5256 case '!': | 5271 case '!': |
| 5257 type = NEGATIVE_LOOKAHEAD; | 5272 type = NEGATIVE_LOOKAHEAD; |
| 5258 break; | 5273 break; |
| 5259 default: | 5274 default: |
| 5260 ReportError(CStrVector("Invalid group") CHECK_FAILED); | 5275 ReportError(CStrVector("Invalid group") CHECK_FAILED); |
| 5261 break; | 5276 break; |
| 5262 } | 5277 } |
| 5263 Advance(2); | 5278 Advance(2); |
| 5264 } else { | 5279 } else { |
| 5265 if (captures_ == NULL) { | 5280 if (captures_ == NULL) { |
| 5266 captures_ = new(zone()) ZoneList<RegExpCapture*>(2); | 5281 captures_ = new(zone()) ZoneList<RegExpCapture*>(2, zone()); |
| 5267 } | 5282 } |
| 5268 if (captures_started() >= kMaxCaptures) { | 5283 if (captures_started() >= kMaxCaptures) { |
| 5269 ReportError(CStrVector("Too many captures") CHECK_FAILED); | 5284 ReportError(CStrVector("Too many captures") CHECK_FAILED); |
| 5270 } | 5285 } |
| 5271 captures_->Add(NULL); | 5286 captures_->Add(NULL, zone()); |
| 5272 } | 5287 } |
| 5273 // Store current state and begin new disjunction parsing. | 5288 // Store current state and begin new disjunction parsing. |
| 5274 stored_state = new(zone()) RegExpParserState(stored_state, type, | 5289 stored_state = new(zone()) RegExpParserState(stored_state, type, |
| 5275 captures_started(), zone()); | 5290 captures_started(), zone()); |
| 5276 builder = stored_state->builder(); | 5291 builder = stored_state->builder(); |
| 5277 continue; | 5292 continue; |
| 5278 } | 5293 } |
| 5279 case '[': { | 5294 case '[': { |
| 5280 RegExpTree* atom = ParseCharacterClass(CHECK_FAILED); | 5295 RegExpTree* atom = ParseCharacterClass(CHECK_FAILED); |
| 5281 builder->AddAtom(atom); | 5296 builder->AddAtom(atom); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 5299 continue; | 5314 continue; |
| 5300 // AtomEscape :: | 5315 // AtomEscape :: |
| 5301 // CharacterClassEscape | 5316 // CharacterClassEscape |
| 5302 // | 5317 // |
| 5303 // CharacterClassEscape :: one of | 5318 // CharacterClassEscape :: one of |
| 5304 // d D s S w W | 5319 // d D s S w W |
| 5305 case 'd': case 'D': case 's': case 'S': case 'w': case 'W': { | 5320 case 'd': case 'D': case 's': case 'S': case 'w': case 'W': { |
| 5306 uc32 c = Next(); | 5321 uc32 c = Next(); |
| 5307 Advance(2); | 5322 Advance(2); |
| 5308 ZoneList<CharacterRange>* ranges = | 5323 ZoneList<CharacterRange>* ranges = |
| 5309 new(zone()) ZoneList<CharacterRange>(2); | 5324 new(zone()) ZoneList<CharacterRange>(2, zone()); |
| 5310 CharacterRange::AddClassEscape(c, ranges); | 5325 CharacterRange::AddClassEscape(c, ranges, zone()); |
| 5311 RegExpTree* atom = new(zone()) RegExpCharacterClass(ranges, false); | 5326 RegExpTree* atom = new(zone()) RegExpCharacterClass(ranges, false); |
| 5312 builder->AddAtom(atom); | 5327 builder->AddAtom(atom); |
| 5313 break; | 5328 break; |
| 5314 } | 5329 } |
| 5315 case '1': case '2': case '3': case '4': case '5': case '6': | 5330 case '1': case '2': case '3': case '4': case '5': case '6': |
| 5316 case '7': case '8': case '9': { | 5331 case '7': case '8': case '9': { |
| 5317 int index = 0; | 5332 int index = 0; |
| 5318 if (ParseBackReferenceIndex(&index)) { | 5333 if (ParseBackReferenceIndex(&index)) { |
| 5319 RegExpCapture* capture = NULL; | 5334 RegExpCapture* capture = NULL; |
| 5320 if (captures_ != NULL && index <= captures_->length()) { | 5335 if (captures_ != NULL && index <= captures_->length()) { |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5775 } | 5790 } |
| 5776 | 5791 |
| 5777 | 5792 |
| 5778 static const uc16 kNoCharClass = 0; | 5793 static const uc16 kNoCharClass = 0; |
| 5779 | 5794 |
| 5780 // Adds range or pre-defined character class to character ranges. | 5795 // Adds range or pre-defined character class to character ranges. |
| 5781 // If char_class is not kInvalidClass, it's interpreted as a class | 5796 // If char_class is not kInvalidClass, it's interpreted as a class |
| 5782 // escape (i.e., 's' means whitespace, from '\s'). | 5797 // escape (i.e., 's' means whitespace, from '\s'). |
| 5783 static inline void AddRangeOrEscape(ZoneList<CharacterRange>* ranges, | 5798 static inline void AddRangeOrEscape(ZoneList<CharacterRange>* ranges, |
| 5784 uc16 char_class, | 5799 uc16 char_class, |
| 5785 CharacterRange range) { | 5800 CharacterRange range, |
| 5801 Zone* zone) { |
| 5786 if (char_class != kNoCharClass) { | 5802 if (char_class != kNoCharClass) { |
| 5787 CharacterRange::AddClassEscape(char_class, ranges); | 5803 CharacterRange::AddClassEscape(char_class, ranges, zone); |
| 5788 } else { | 5804 } else { |
| 5789 ranges->Add(range); | 5805 ranges->Add(range, zone); |
| 5790 } | 5806 } |
| 5791 } | 5807 } |
| 5792 | 5808 |
| 5793 | 5809 |
| 5794 RegExpTree* RegExpParser::ParseCharacterClass() { | 5810 RegExpTree* RegExpParser::ParseCharacterClass() { |
| 5795 static const char* kUnterminated = "Unterminated character class"; | 5811 static const char* kUnterminated = "Unterminated character class"; |
| 5796 static const char* kRangeOutOfOrder = "Range out of order in character class"; | 5812 static const char* kRangeOutOfOrder = "Range out of order in character class"; |
| 5797 | 5813 |
| 5798 ASSERT_EQ(current(), '['); | 5814 ASSERT_EQ(current(), '['); |
| 5799 Advance(); | 5815 Advance(); |
| 5800 bool is_negated = false; | 5816 bool is_negated = false; |
| 5801 if (current() == '^') { | 5817 if (current() == '^') { |
| 5802 is_negated = true; | 5818 is_negated = true; |
| 5803 Advance(); | 5819 Advance(); |
| 5804 } | 5820 } |
| 5805 ZoneList<CharacterRange>* ranges = new(zone()) ZoneList<CharacterRange>(2); | 5821 ZoneList<CharacterRange>* ranges = |
| 5822 new(zone()) ZoneList<CharacterRange>(2, zone()); |
| 5806 while (has_more() && current() != ']') { | 5823 while (has_more() && current() != ']') { |
| 5807 uc16 char_class = kNoCharClass; | 5824 uc16 char_class = kNoCharClass; |
| 5808 CharacterRange first = ParseClassAtom(&char_class CHECK_FAILED); | 5825 CharacterRange first = ParseClassAtom(&char_class CHECK_FAILED); |
| 5809 if (current() == '-') { | 5826 if (current() == '-') { |
| 5810 Advance(); | 5827 Advance(); |
| 5811 if (current() == kEndMarker) { | 5828 if (current() == kEndMarker) { |
| 5812 // If we reach the end we break out of the loop and let the | 5829 // If we reach the end we break out of the loop and let the |
| 5813 // following code report an error. | 5830 // following code report an error. |
| 5814 break; | 5831 break; |
| 5815 } else if (current() == ']') { | 5832 } else if (current() == ']') { |
| 5816 AddRangeOrEscape(ranges, char_class, first); | 5833 AddRangeOrEscape(ranges, char_class, first, zone()); |
| 5817 ranges->Add(CharacterRange::Singleton('-')); | 5834 ranges->Add(CharacterRange::Singleton('-'), zone()); |
| 5818 break; | 5835 break; |
| 5819 } | 5836 } |
| 5820 uc16 char_class_2 = kNoCharClass; | 5837 uc16 char_class_2 = kNoCharClass; |
| 5821 CharacterRange next = ParseClassAtom(&char_class_2 CHECK_FAILED); | 5838 CharacterRange next = ParseClassAtom(&char_class_2 CHECK_FAILED); |
| 5822 if (char_class != kNoCharClass || char_class_2 != kNoCharClass) { | 5839 if (char_class != kNoCharClass || char_class_2 != kNoCharClass) { |
| 5823 // Either end is an escaped character class. Treat the '-' verbatim. | 5840 // Either end is an escaped character class. Treat the '-' verbatim. |
| 5824 AddRangeOrEscape(ranges, char_class, first); | 5841 AddRangeOrEscape(ranges, char_class, first, zone()); |
| 5825 ranges->Add(CharacterRange::Singleton('-')); | 5842 ranges->Add(CharacterRange::Singleton('-'), zone()); |
| 5826 AddRangeOrEscape(ranges, char_class_2, next); | 5843 AddRangeOrEscape(ranges, char_class_2, next, zone()); |
| 5827 continue; | 5844 continue; |
| 5828 } | 5845 } |
| 5829 if (first.from() > next.to()) { | 5846 if (first.from() > next.to()) { |
| 5830 return ReportError(CStrVector(kRangeOutOfOrder) CHECK_FAILED); | 5847 return ReportError(CStrVector(kRangeOutOfOrder) CHECK_FAILED); |
| 5831 } | 5848 } |
| 5832 ranges->Add(CharacterRange::Range(first.from(), next.to())); | 5849 ranges->Add(CharacterRange::Range(first.from(), next.to()), zone()); |
| 5833 } else { | 5850 } else { |
| 5834 AddRangeOrEscape(ranges, char_class, first); | 5851 AddRangeOrEscape(ranges, char_class, first, zone()); |
| 5835 } | 5852 } |
| 5836 } | 5853 } |
| 5837 if (!has_more()) { | 5854 if (!has_more()) { |
| 5838 return ReportError(CStrVector(kUnterminated) CHECK_FAILED); | 5855 return ReportError(CStrVector(kUnterminated) CHECK_FAILED); |
| 5839 } | 5856 } |
| 5840 Advance(); | 5857 Advance(); |
| 5841 if (ranges->length() == 0) { | 5858 if (ranges->length() == 0) { |
| 5842 ranges->Add(CharacterRange::Everything()); | 5859 ranges->Add(CharacterRange::Everything(), zone()); |
| 5843 is_negated = !is_negated; | 5860 is_negated = !is_negated; |
| 5844 } | 5861 } |
| 5845 return new(zone()) RegExpCharacterClass(ranges, is_negated); | 5862 return new(zone()) RegExpCharacterClass(ranges, is_negated); |
| 5846 } | 5863 } |
| 5847 | 5864 |
| 5848 | 5865 |
| 5849 // ---------------------------------------------------------------------------- | 5866 // ---------------------------------------------------------------------------- |
| 5850 // The Parser interface. | 5867 // The Parser interface. |
| 5851 | 5868 |
| 5852 ParserMessage::~ParserMessage() { | 5869 ParserMessage::~ParserMessage() { |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6047 ASSERT(info->isolate()->has_pending_exception()); | 6064 ASSERT(info->isolate()->has_pending_exception()); |
| 6048 } else { | 6065 } else { |
| 6049 result = parser.ParseProgram(info); | 6066 result = parser.ParseProgram(info); |
| 6050 } | 6067 } |
| 6051 } | 6068 } |
| 6052 info->SetFunction(result); | 6069 info->SetFunction(result); |
| 6053 return (result != NULL); | 6070 return (result != NULL); |
| 6054 } | 6071 } |
| 6055 | 6072 |
| 6056 } } // namespace v8::internal | 6073 } } // namespace v8::internal |
| OLD | NEW |