| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 271 |
| 272 | 272 |
| 273 InitializationFlag ScopeInfo::ContextLocalInitFlag(int var) { | 273 InitializationFlag ScopeInfo::ContextLocalInitFlag(int var) { |
| 274 ASSERT(0 <= var && var < ContextLocalCount()); | 274 ASSERT(0 <= var && var < ContextLocalCount()); |
| 275 int info_index = ContextLocalInfoEntriesIndex() + var; | 275 int info_index = ContextLocalInfoEntriesIndex() + var; |
| 276 int value = Smi::cast(get(info_index))->value(); | 276 int value = Smi::cast(get(info_index))->value(); |
| 277 return ContextLocalInitFlag::decode(value); | 277 return ContextLocalInitFlag::decode(value); |
| 278 } | 278 } |
| 279 | 279 |
| 280 | 280 |
| 281 bool ScopeInfo::LocalIsSynthetic(int var) { |
| 282 ASSERT(0 <= var && var < LocalCount()); |
| 283 // There's currently no flag stored on the ScopeInfo to indicate that a |
| 284 // variable is a compiler-introduced temporary. However, to avoid conflict |
| 285 // with user declarations, the current temporaries like .generator_object and |
| 286 // .result start with a dot, so we can use that as a flag. It's a hack! |
| 287 Handle<String> name(LocalName(var)); |
| 288 return name->length() > 0 && name->Get(0) == '.'; |
| 289 } |
| 290 |
| 291 |
| 281 int ScopeInfo::StackSlotIndex(String* name) { | 292 int ScopeInfo::StackSlotIndex(String* name) { |
| 282 ASSERT(name->IsInternalizedString()); | 293 ASSERT(name->IsInternalizedString()); |
| 283 if (length() > 0) { | 294 if (length() > 0) { |
| 284 int start = StackLocalEntriesIndex(); | 295 int start = StackLocalEntriesIndex(); |
| 285 int end = StackLocalEntriesIndex() + StackLocalCount(); | 296 int end = StackLocalEntriesIndex() + StackLocalCount(); |
| 286 for (int i = start; i < end; ++i) { | 297 for (int i = start; i < end; ++i) { |
| 287 if (name == get(i)) { | 298 if (name == get(i)) { |
| 288 return i - start; | 299 return i - start; |
| 289 } | 300 } |
| 290 } | 301 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 } | 372 } |
| 362 | 373 |
| 363 | 374 |
| 364 bool ScopeInfo::CopyContextLocalsToScopeObject(Handle<ScopeInfo> scope_info, | 375 bool ScopeInfo::CopyContextLocalsToScopeObject(Handle<ScopeInfo> scope_info, |
| 365 Handle<Context> context, | 376 Handle<Context> context, |
| 366 Handle<JSObject> scope_object) { | 377 Handle<JSObject> scope_object) { |
| 367 Isolate* isolate = scope_info->GetIsolate(); | 378 Isolate* isolate = scope_info->GetIsolate(); |
| 368 int local_count = scope_info->ContextLocalCount(); | 379 int local_count = scope_info->ContextLocalCount(); |
| 369 if (local_count == 0) return true; | 380 if (local_count == 0) return true; |
| 370 // Fill all context locals to the context extension. | 381 // Fill all context locals to the context extension. |
| 382 int first_context_var = scope_info->StackLocalCount(); |
| 371 int start = scope_info->ContextLocalNameEntriesIndex(); | 383 int start = scope_info->ContextLocalNameEntriesIndex(); |
| 372 int end = start + local_count; | 384 for (int i = 0; i < local_count; ++i) { |
| 373 for (int i = start; i < end; ++i) { | 385 if (scope_info->LocalIsSynthetic(first_context_var + i)) continue; |
| 374 int context_index = Context::MIN_CONTEXT_SLOTS + i - start; | 386 int context_index = Context::MIN_CONTEXT_SLOTS + i; |
| 375 RETURN_ON_EXCEPTION_VALUE( | 387 RETURN_ON_EXCEPTION_VALUE( |
| 376 isolate, | 388 isolate, |
| 377 Runtime::SetObjectProperty( | 389 Runtime::SetObjectProperty( |
| 378 isolate, | 390 isolate, |
| 379 scope_object, | 391 scope_object, |
| 380 Handle<String>(String::cast(scope_info->get(i))), | 392 Handle<String>(String::cast(scope_info->get(i + start))), |
| 381 Handle<Object>(context->get(context_index), isolate), | 393 Handle<Object>(context->get(context_index), isolate), |
| 382 ::NONE, | 394 ::NONE, |
| 383 SLOPPY), | 395 SLOPPY), |
| 384 false); | 396 false); |
| 385 } | 397 } |
| 386 return true; | 398 return true; |
| 387 } | 399 } |
| 388 | 400 |
| 389 | 401 |
| 390 int ScopeInfo::ParameterEntriesIndex() { | 402 int ScopeInfo::ParameterEntriesIndex() { |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 } else { | 566 } else { |
| 555 ASSERT(var->index() >= 0); | 567 ASSERT(var->index() >= 0); |
| 556 info->set_index(i, var->index()); | 568 info->set_index(i, var->index()); |
| 557 } | 569 } |
| 558 } | 570 } |
| 559 ASSERT(i == info->length()); | 571 ASSERT(i == info->length()); |
| 560 return info; | 572 return info; |
| 561 } | 573 } |
| 562 | 574 |
| 563 } } // namespace v8::internal | 575 } } // namespace v8::internal |
| OLD | NEW |