| 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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 273 |
| 274 InitializationFlag ScopeInfo::ContextLocalInitFlag(int var) { | 274 InitializationFlag ScopeInfo::ContextLocalInitFlag(int var) { |
| 275 ASSERT(0 <= var && var < ContextLocalCount()); | 275 ASSERT(0 <= var && var < ContextLocalCount()); |
| 276 int info_index = ContextLocalInfoEntriesIndex() + var; | 276 int info_index = ContextLocalInfoEntriesIndex() + var; |
| 277 int value = Smi::cast(get(info_index))->value(); | 277 int value = Smi::cast(get(info_index))->value(); |
| 278 return ContextLocalInitFlag::decode(value); | 278 return ContextLocalInitFlag::decode(value); |
| 279 } | 279 } |
| 280 | 280 |
| 281 | 281 |
| 282 int ScopeInfo::StackSlotIndex(String* name) { | 282 int ScopeInfo::StackSlotIndex(String* name) { |
| 283 ASSERT(name->IsSymbol()); | 283 ASSERT(name->IsInternalizedString()); |
| 284 if (length() > 0) { | 284 if (length() > 0) { |
| 285 int start = StackLocalEntriesIndex(); | 285 int start = StackLocalEntriesIndex(); |
| 286 int end = StackLocalEntriesIndex() + StackLocalCount(); | 286 int end = StackLocalEntriesIndex() + StackLocalCount(); |
| 287 for (int i = start; i < end; ++i) { | 287 for (int i = start; i < end; ++i) { |
| 288 if (name == get(i)) { | 288 if (name == get(i)) { |
| 289 return i - start; | 289 return i - start; |
| 290 } | 290 } |
| 291 } | 291 } |
| 292 } | 292 } |
| 293 return -1; | 293 return -1; |
| 294 } | 294 } |
| 295 | 295 |
| 296 | 296 |
| 297 int ScopeInfo::ContextSlotIndex(String* name, | 297 int ScopeInfo::ContextSlotIndex(String* name, |
| 298 VariableMode* mode, | 298 VariableMode* mode, |
| 299 InitializationFlag* init_flag) { | 299 InitializationFlag* init_flag) { |
| 300 ASSERT(name->IsSymbol()); | 300 ASSERT(name->IsInternalizedString()); |
| 301 ASSERT(mode != NULL); | 301 ASSERT(mode != NULL); |
| 302 ASSERT(init_flag != NULL); | 302 ASSERT(init_flag != NULL); |
| 303 if (length() > 0) { | 303 if (length() > 0) { |
| 304 ContextSlotCache* context_slot_cache = GetIsolate()->context_slot_cache(); | 304 ContextSlotCache* context_slot_cache = GetIsolate()->context_slot_cache(); |
| 305 int result = context_slot_cache->Lookup(this, name, mode, init_flag); | 305 int result = context_slot_cache->Lookup(this, name, mode, init_flag); |
| 306 if (result != ContextSlotCache::kNotFound) { | 306 if (result != ContextSlotCache::kNotFound) { |
| 307 ASSERT(result < ContextLength()); | 307 ASSERT(result < ContextLength()); |
| 308 return result; | 308 return result; |
| 309 } | 309 } |
| 310 | 310 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 322 } | 322 } |
| 323 } | 323 } |
| 324 // Cache as not found. Mode and init flag don't matter. | 324 // Cache as not found. Mode and init flag don't matter. |
| 325 context_slot_cache->Update(this, name, INTERNAL, kNeedsInitialization, -1); | 325 context_slot_cache->Update(this, name, INTERNAL, kNeedsInitialization, -1); |
| 326 } | 326 } |
| 327 return -1; | 327 return -1; |
| 328 } | 328 } |
| 329 | 329 |
| 330 | 330 |
| 331 int ScopeInfo::ParameterIndex(String* name) { | 331 int ScopeInfo::ParameterIndex(String* name) { |
| 332 ASSERT(name->IsSymbol()); | 332 ASSERT(name->IsInternalizedString()); |
| 333 if (length() > 0) { | 333 if (length() > 0) { |
| 334 // We must read parameters from the end since for | 334 // We must read parameters from the end since for |
| 335 // multiply declared parameters the value of the | 335 // multiply declared parameters the value of the |
| 336 // last declaration of that parameter is used | 336 // last declaration of that parameter is used |
| 337 // inside a function (and thus we need to look | 337 // inside a function (and thus we need to look |
| 338 // at the last index). Was bug# 1110337. | 338 // at the last index). Was bug# 1110337. |
| 339 int start = ParameterEntriesIndex(); | 339 int start = ParameterEntriesIndex(); |
| 340 int end = ParameterEntriesIndex() + ParameterCount(); | 340 int end = ParameterEntriesIndex() + ParameterCount(); |
| 341 for (int i = end - 1; i >= start; --i) { | 341 for (int i = end - 1; i >= start; --i) { |
| 342 if (name == get(i)) { | 342 if (name == get(i)) { |
| 343 return i - start; | 343 return i - start; |
| 344 } | 344 } |
| 345 } | 345 } |
| 346 } | 346 } |
| 347 return -1; | 347 return -1; |
| 348 } | 348 } |
| 349 | 349 |
| 350 | 350 |
| 351 int ScopeInfo::FunctionContextSlotIndex(String* name, VariableMode* mode) { | 351 int ScopeInfo::FunctionContextSlotIndex(String* name, VariableMode* mode) { |
| 352 ASSERT(name->IsSymbol()); | 352 ASSERT(name->IsInternalizedString()); |
| 353 ASSERT(mode != NULL); | 353 ASSERT(mode != NULL); |
| 354 if (length() > 0) { | 354 if (length() > 0) { |
| 355 if (FunctionVariableField::decode(Flags()) == CONTEXT && | 355 if (FunctionVariableField::decode(Flags()) == CONTEXT && |
| 356 FunctionName() == name) { | 356 FunctionName() == name) { |
| 357 *mode = FunctionVariableMode::decode(Flags()); | 357 *mode = FunctionVariableMode::decode(Flags()); |
| 358 return Smi::cast(get(FunctionNameEntryIndex() + 1))->value(); | 358 return Smi::cast(get(FunctionNameEntryIndex() + 1))->value(); |
| 359 } | 359 } |
| 360 } | 360 } |
| 361 return -1; | 361 return -1; |
| 362 } | 362 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 } | 410 } |
| 411 return kNotFound; | 411 return kNotFound; |
| 412 } | 412 } |
| 413 | 413 |
| 414 | 414 |
| 415 void ContextSlotCache::Update(Object* data, | 415 void ContextSlotCache::Update(Object* data, |
| 416 String* name, | 416 String* name, |
| 417 VariableMode mode, | 417 VariableMode mode, |
| 418 InitializationFlag init_flag, | 418 InitializationFlag init_flag, |
| 419 int slot_index) { | 419 int slot_index) { |
| 420 String* symbol; | 420 String* internalized_name; |
| 421 ASSERT(slot_index > kNotFound); | 421 ASSERT(slot_index > kNotFound); |
| 422 if (HEAP->LookupSymbolIfExists(name, &symbol)) { | 422 if (HEAP->InternalizeStringIfExists(name, &internalized_name)) { |
| 423 int index = Hash(data, symbol); | 423 int index = Hash(data, internalized_name); |
| 424 Key& key = keys_[index]; | 424 Key& key = keys_[index]; |
| 425 key.data = data; | 425 key.data = data; |
| 426 key.name = symbol; | 426 key.name = internalized_name; |
| 427 // Please note value only takes a uint as index. | 427 // Please note value only takes a uint as index. |
| 428 values_[index] = Value(mode, init_flag, slot_index - kNotFound).raw(); | 428 values_[index] = Value(mode, init_flag, slot_index - kNotFound).raw(); |
| 429 #ifdef DEBUG | 429 #ifdef DEBUG |
| 430 ValidateEntry(data, name, mode, init_flag, slot_index); | 430 ValidateEntry(data, name, mode, init_flag, slot_index); |
| 431 #endif | 431 #endif |
| 432 } | 432 } |
| 433 } | 433 } |
| 434 | 434 |
| 435 | 435 |
| 436 void ContextSlotCache::Clear() { | 436 void ContextSlotCache::Clear() { |
| 437 for (int index = 0; index < kLength; index++) keys_[index].data = NULL; | 437 for (int index = 0; index < kLength; index++) keys_[index].data = NULL; |
| 438 } | 438 } |
| 439 | 439 |
| 440 | 440 |
| 441 #ifdef DEBUG | 441 #ifdef DEBUG |
| 442 | 442 |
| 443 void ContextSlotCache::ValidateEntry(Object* data, | 443 void ContextSlotCache::ValidateEntry(Object* data, |
| 444 String* name, | 444 String* name, |
| 445 VariableMode mode, | 445 VariableMode mode, |
| 446 InitializationFlag init_flag, | 446 InitializationFlag init_flag, |
| 447 int slot_index) { | 447 int slot_index) { |
| 448 String* symbol; | 448 String* internalized_name; |
| 449 if (HEAP->LookupSymbolIfExists(name, &symbol)) { | 449 if (HEAP->InternalizeStringIfExists(name, &internalized_name)) { |
| 450 int index = Hash(data, name); | 450 int index = Hash(data, name); |
| 451 Key& key = keys_[index]; | 451 Key& key = keys_[index]; |
| 452 ASSERT(key.data == data); | 452 ASSERT(key.data == data); |
| 453 ASSERT(key.name->Equals(name)); | 453 ASSERT(key.name->Equals(name)); |
| 454 Value result(values_[index]); | 454 Value result(values_[index]); |
| 455 ASSERT(result.mode() == mode); | 455 ASSERT(result.mode() == mode); |
| 456 ASSERT(result.initialization_flag() == init_flag); | 456 ASSERT(result.initialization_flag() == init_flag); |
| 457 ASSERT(result.index() + kNotFound == slot_index); | 457 ASSERT(result.index() + kNotFound == slot_index); |
| 458 } | 458 } |
| 459 } | 459 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 } else { | 527 } else { |
| 528 ASSERT(var->index() >= 0); | 528 ASSERT(var->index() >= 0); |
| 529 info->set_index(i, var->index()); | 529 info->set_index(i, var->index()); |
| 530 } | 530 } |
| 531 } | 531 } |
| 532 ASSERT(i == info->length()); | 532 ASSERT(i == info->length()); |
| 533 return info; | 533 return info; |
| 534 } | 534 } |
| 535 | 535 |
| 536 } } // namespace v8::internal | 536 } } // namespace v8::internal |
| OLD | NEW |