OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/ic/ic.h" | 5 #include "src/ic/ic.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api-arguments-inl.h" | 8 #include "src/api-arguments-inl.h" |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/arguments.h" | 10 #include "src/arguments.h" |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 } | 604 } |
605 | 605 |
606 | 606 |
607 MaybeHandle<Object> LoadIC::Load(Handle<Object> object, Handle<Name> name) { | 607 MaybeHandle<Object> LoadIC::Load(Handle<Object> object, Handle<Name> name) { |
608 // If the object is undefined or null it's illegal to try to get any | 608 // If the object is undefined or null it's illegal to try to get any |
609 // of its properties; throw a TypeError in that case. | 609 // of its properties; throw a TypeError in that case. |
610 if (object->IsUndefined(isolate()) || object->IsNull(isolate())) { | 610 if (object->IsUndefined(isolate()) || object->IsNull(isolate())) { |
611 return TypeError(MessageTemplate::kNonObjectPropertyLoad, object, name); | 611 return TypeError(MessageTemplate::kNonObjectPropertyLoad, object, name); |
612 } | 612 } |
613 | 613 |
614 // Check if the name is trivially convertible to an index and get | |
615 // the element or char if so. | |
616 uint32_t index; | |
617 if (kind() == Code::KEYED_LOAD_IC && name->AsArrayIndex(&index)) { | |
618 // Rewrite to the generic keyed load stub. | |
619 if (FLAG_use_ic) { | |
620 DCHECK(UseVector()); | |
621 ConfigureVectorState(MEGAMORPHIC, name); | |
622 TRACE_GENERIC_IC(isolate(), "LoadIC", "name as array index"); | |
623 TRACE_IC("LoadIC", name); | |
624 } | |
625 Handle<Object> result; | |
626 ASSIGN_RETURN_ON_EXCEPTION(isolate(), result, | |
627 Object::GetElement(isolate(), object, index), | |
628 Object); | |
629 return result; | |
630 } | |
631 | |
632 bool use_ic = MigrateDeprecated(object) ? false : FLAG_use_ic; | 614 bool use_ic = MigrateDeprecated(object) ? false : FLAG_use_ic; |
633 | 615 |
634 if (state() != UNINITIALIZED) { | 616 if (state() != UNINITIALIZED) { |
635 JSObject::MakePrototypesFast(object, kStartAtReceiver, isolate()); | 617 JSObject::MakePrototypesFast(object, kStartAtReceiver, isolate()); |
636 update_receiver_map(object); | 618 update_receiver_map(object); |
637 } | 619 } |
638 // Named lookup in the object. | 620 // Named lookup in the object. |
639 LookupIterator it(object, name); | 621 LookupIterator it(object, name); |
640 LookupForRead(&it); | 622 LookupForRead(&it); |
641 | 623 |
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1400 Object); | 1382 Object); |
1401 return result; | 1383 return result; |
1402 } | 1384 } |
1403 | 1385 |
1404 Handle<Object> load_handle; | 1386 Handle<Object> load_handle; |
1405 | 1387 |
1406 // Check for non-string values that can be converted into an | 1388 // Check for non-string values that can be converted into an |
1407 // internalized string directly or is representable as a smi. | 1389 // internalized string directly or is representable as a smi. |
1408 key = TryConvertKey(key, isolate()); | 1390 key = TryConvertKey(key, isolate()); |
1409 | 1391 |
1410 if (key->IsInternalizedString() || key->IsSymbol()) { | 1392 uint32_t index; |
| 1393 if ((key->IsInternalizedString() && |
| 1394 !String::cast(*key)->AsArrayIndex(&index)) || |
| 1395 key->IsSymbol()) { |
1411 ASSIGN_RETURN_ON_EXCEPTION(isolate(), load_handle, | 1396 ASSIGN_RETURN_ON_EXCEPTION(isolate(), load_handle, |
1412 LoadIC::Load(object, Handle<Name>::cast(key)), | 1397 LoadIC::Load(object, Handle<Name>::cast(key)), |
1413 Object); | 1398 Object); |
1414 } else if (FLAG_use_ic && !object->IsAccessCheckNeeded() && | 1399 } else if (FLAG_use_ic && !object->IsAccessCheckNeeded() && |
1415 !object->IsJSValue()) { | 1400 !object->IsJSValue()) { |
1416 if (object->IsJSObject() || (object->IsString() && key->IsNumber())) { | 1401 if (object->IsJSObject() || (object->IsString() && key->IsNumber())) { |
1417 Handle<HeapObject> receiver = Handle<HeapObject>::cast(object); | 1402 Handle<HeapObject> receiver = Handle<HeapObject>::cast(object); |
1418 if (object->IsString() || key->IsSmi()) UpdateLoadElement(receiver); | 1403 if (object->IsString() || key->IsSmi()) UpdateLoadElement(receiver); |
1419 } | 1404 } |
1420 } | 1405 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1499 receiver = it->GetStoreTarget(); | 1484 receiver = it->GetStoreTarget(); |
1500 if (it->ExtendingNonExtensible(receiver)) return false; | 1485 if (it->ExtendingNonExtensible(receiver)) return false; |
1501 it->PrepareTransitionToDataProperty(receiver, value, NONE, store_mode); | 1486 it->PrepareTransitionToDataProperty(receiver, value, NONE, store_mode); |
1502 return it->IsCacheableTransition(); | 1487 return it->IsCacheableTransition(); |
1503 } | 1488 } |
1504 | 1489 |
1505 | 1490 |
1506 MaybeHandle<Object> StoreIC::Store(Handle<Object> object, Handle<Name> name, | 1491 MaybeHandle<Object> StoreIC::Store(Handle<Object> object, Handle<Name> name, |
1507 Handle<Object> value, | 1492 Handle<Object> value, |
1508 JSReceiver::StoreFromKeyed store_mode) { | 1493 JSReceiver::StoreFromKeyed store_mode) { |
1509 // Check if the name is trivially convertible to an index and set the element. | |
1510 uint32_t index; | |
1511 if (kind() == Code::KEYED_STORE_IC && name->AsArrayIndex(&index)) { | |
1512 // Rewrite to the generic keyed store stub. | |
1513 if (FLAG_use_ic) { | |
1514 DCHECK(UseVector()); | |
1515 ConfigureVectorState(MEGAMORPHIC, name); | |
1516 TRACE_IC("StoreIC", name); | |
1517 TRACE_GENERIC_IC(isolate(), "StoreIC", "name as array index"); | |
1518 } | |
1519 Handle<Object> result; | |
1520 ASSIGN_RETURN_ON_EXCEPTION( | |
1521 isolate(), result, | |
1522 Object::SetElement(isolate(), object, index, value, language_mode()), | |
1523 Object); | |
1524 return result; | |
1525 } | |
1526 | |
1527 if (object->IsJSGlobalObject() && name->IsString()) { | 1494 if (object->IsJSGlobalObject() && name->IsString()) { |
1528 // Look up in script context table. | 1495 // Look up in script context table. |
1529 Handle<String> str_name = Handle<String>::cast(name); | 1496 Handle<String> str_name = Handle<String>::cast(name); |
1530 Handle<JSGlobalObject> global = Handle<JSGlobalObject>::cast(object); | 1497 Handle<JSGlobalObject> global = Handle<JSGlobalObject>::cast(object); |
1531 Handle<ScriptContextTable> script_contexts( | 1498 Handle<ScriptContextTable> script_contexts( |
1532 global->native_context()->script_context_table()); | 1499 global->native_context()->script_context_table()); |
1533 | 1500 |
1534 ScriptContextTable::LookupResult lookup_result; | 1501 ScriptContextTable::LookupResult lookup_result; |
1535 if (ScriptContextTable::Lookup(script_contexts, str_name, &lookup_result)) { | 1502 if (ScriptContextTable::Lookup(script_contexts, str_name, &lookup_result)) { |
1536 Handle<Context> script_context = ScriptContextTable::GetContext( | 1503 Handle<Context> script_context = ScriptContextTable::GetContext( |
(...skipping 1480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3017 DCHECK_EQ(FeedbackVectorSlotKind::KEYED_LOAD_IC, | 2984 DCHECK_EQ(FeedbackVectorSlotKind::KEYED_LOAD_IC, |
3018 vector->GetKind(vector_slot)); | 2985 vector->GetKind(vector_slot)); |
3019 KeyedLoadICNexus nexus(vector, vector_slot); | 2986 KeyedLoadICNexus nexus(vector, vector_slot); |
3020 KeyedLoadIC ic(IC::EXTRA_CALL_FRAME, isolate, &nexus); | 2987 KeyedLoadIC ic(IC::EXTRA_CALL_FRAME, isolate, &nexus); |
3021 ic.UpdateState(receiver, key); | 2988 ic.UpdateState(receiver, key); |
3022 RETURN_RESULT_OR_FAILURE(isolate, ic.Load(receiver, key)); | 2989 RETURN_RESULT_OR_FAILURE(isolate, ic.Load(receiver, key)); |
3023 } | 2990 } |
3024 } | 2991 } |
3025 } // namespace internal | 2992 } // namespace internal |
3026 } // namespace v8 | 2993 } // namespace v8 |
OLD | NEW |