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

Side by Side Diff: src/scopes.cc

Issue 13179002: Add parser support for generators. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: added additional syntax tests Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/scopes.h ('k') | src/token.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 outer_scope_ = outer_scope; 183 outer_scope_ = outer_scope;
184 type_ = type; 184 type_ = type;
185 scope_name_ = isolate_->factory()->empty_string(); 185 scope_name_ = isolate_->factory()->empty_string();
186 dynamics_ = NULL; 186 dynamics_ = NULL;
187 receiver_ = NULL; 187 receiver_ = NULL;
188 function_ = NULL; 188 function_ = NULL;
189 arguments_ = NULL; 189 arguments_ = NULL;
190 illegal_redecl_ = NULL; 190 illegal_redecl_ = NULL;
191 scope_inside_with_ = false; 191 scope_inside_with_ = false;
192 scope_contains_with_ = false; 192 scope_contains_with_ = false;
193 scope_inside_generator_ = false;
193 scope_calls_eval_ = false; 194 scope_calls_eval_ = false;
194 // Inherit the strict mode from the parent scope. 195 // Inherit the strict mode from the parent scope.
195 language_mode_ = (outer_scope != NULL) 196 language_mode_ = (outer_scope != NULL)
196 ? outer_scope->language_mode_ : CLASSIC_MODE; 197 ? outer_scope->language_mode_ : CLASSIC_MODE;
197 outer_scope_calls_non_strict_eval_ = false; 198 outer_scope_calls_non_strict_eval_ = false;
198 inner_scope_calls_eval_ = false; 199 inner_scope_calls_eval_ = false;
199 force_eager_compilation_ = false; 200 force_eager_compilation_ = false;
200 num_var_or_const_ = 0; 201 num_var_or_const_ = 0;
201 num_stack_slots_ = 0; 202 num_stack_slots_ = 0;
202 num_heap_slots_ = 0; 203 num_heap_slots_ = 0;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 current_scope = new(zone) Scope(current_scope, 242 current_scope = new(zone) Scope(current_scope,
242 MODULE_SCOPE, 243 MODULE_SCOPE,
243 Handle<ScopeInfo>(scope_info), 244 Handle<ScopeInfo>(scope_info),
244 zone); 245 zone);
245 } else if (context->IsFunctionContext()) { 246 } else if (context->IsFunctionContext()) {
246 ScopeInfo* scope_info = context->closure()->shared()->scope_info(); 247 ScopeInfo* scope_info = context->closure()->shared()->scope_info();
247 current_scope = new(zone) Scope(current_scope, 248 current_scope = new(zone) Scope(current_scope,
248 FUNCTION_SCOPE, 249 FUNCTION_SCOPE,
249 Handle<ScopeInfo>(scope_info), 250 Handle<ScopeInfo>(scope_info),
250 zone); 251 zone);
252 if (context->closure()->shared()->is_generator()) {
253 if (innermost_scope) {
254 // Find the deepest scope that's still in this function.
255 Scope *inner_scope = innermost_scope;
256 for (Scope *s = innermost_scope;
257 s != current_scope;
258 s = s->outer_scope()) {
259 inner_scope = s;
260 while (!s->is_function_scope())
261 s = s->outer_scope();
262 }
263 // Mark intervening scopes (inclusive) as being inside a generator.
264 while (inner_scope != current_scope) {
265 inner_scope->scope_inside_generator_ = true;
266 inner_scope = inner_scope->outer_scope();
267 }
268 }
269 current_scope->scope_inside_generator_ = true;
270 }
251 } else if (context->IsBlockContext()) { 271 } else if (context->IsBlockContext()) {
252 ScopeInfo* scope_info = ScopeInfo::cast(context->extension()); 272 ScopeInfo* scope_info = ScopeInfo::cast(context->extension());
253 current_scope = new(zone) Scope(current_scope, 273 current_scope = new(zone) Scope(current_scope,
254 BLOCK_SCOPE, 274 BLOCK_SCOPE,
255 Handle<ScopeInfo>(scope_info), 275 Handle<ScopeInfo>(scope_info),
256 zone); 276 zone);
257 } else { 277 } else {
258 ASSERT(context->IsCatchContext()); 278 ASSERT(context->IsCatchContext());
259 String* name = String::cast(context->extension()); 279 String* name = String::cast(context->extension());
260 current_scope = new(zone) Scope( 280 current_scope = new(zone) Scope(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 } 333 }
314 334
315 335
316 void Scope::Initialize() { 336 void Scope::Initialize() {
317 ASSERT(!already_resolved()); 337 ASSERT(!already_resolved());
318 338
319 // Add this scope as a new inner scope of the outer scope. 339 // Add this scope as a new inner scope of the outer scope.
320 if (outer_scope_ != NULL) { 340 if (outer_scope_ != NULL) {
321 outer_scope_->inner_scopes_.Add(this, zone()); 341 outer_scope_->inner_scopes_.Add(this, zone());
322 scope_inside_with_ = outer_scope_->scope_inside_with_ || is_with_scope(); 342 scope_inside_with_ = outer_scope_->scope_inside_with_ || is_with_scope();
343 scope_inside_generator_ = outer_scope_->inside_generator();
323 } else { 344 } else {
324 scope_inside_with_ = is_with_scope(); 345 scope_inside_with_ = is_with_scope();
325 } 346 }
326 347
327 // Declare convenience variables. 348 // Declare convenience variables.
328 // Declare and allocate receiver (even for the global scope, and even 349 // Declare and allocate receiver (even for the global scope, and even
329 // if naccesses_ == 0). 350 // if naccesses_ == 0).
330 // NOTE: When loading parameters in the global scope, we must take 351 // NOTE: When loading parameters in the global scope, we must take
331 // care not to access them as properties of the global object, but 352 // care not to access them as properties of the global object, but
332 // instead load them directly from the stack. Currently, the only 353 // instead load them directly from the stack. Currently, the only
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 } 1400 }
1380 1401
1381 1402
1382 int Scope::ContextLocalCount() const { 1403 int Scope::ContextLocalCount() const {
1383 if (num_heap_slots() == 0) return 0; 1404 if (num_heap_slots() == 0) return 0;
1384 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1405 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1385 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); 1406 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0);
1386 } 1407 }
1387 1408
1388 } } // namespace v8::internal 1409 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/scopes.h ('k') | src/token.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698