OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 1689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1700 } | 1700 } |
1701 if (result->type() == CALLBACKS) { | 1701 if (result->type() == CALLBACKS) { |
1702 return; | 1702 return; |
1703 } | 1703 } |
1704 } | 1704 } |
1705 } | 1705 } |
1706 result->NotFound(); | 1706 result->NotFound(); |
1707 } | 1707 } |
1708 | 1708 |
1709 | 1709 |
1710 bool JSObject::SetElementWithCallbackSetterInPrototypes(uint32_t index, | 1710 MaybeObject* JSObject::SetElementWithCallbackSetterInPrototypes(uint32_t index, |
1711 Object* value) { | 1711 Object* value, |
| 1712 bool* found) { |
1712 for (Object* pt = GetPrototype(); | 1713 for (Object* pt = GetPrototype(); |
1713 pt != Heap::null_value(); | 1714 pt != Heap::null_value(); |
1714 pt = pt->GetPrototype()) { | 1715 pt = pt->GetPrototype()) { |
1715 if (!JSObject::cast(pt)->HasDictionaryElements()) { | 1716 if (!JSObject::cast(pt)->HasDictionaryElements()) { |
1716 continue; | 1717 continue; |
1717 } | 1718 } |
1718 NumberDictionary* dictionary = JSObject::cast(pt)->element_dictionary(); | 1719 NumberDictionary* dictionary = JSObject::cast(pt)->element_dictionary(); |
1719 int entry = dictionary->FindEntry(index); | 1720 int entry = dictionary->FindEntry(index); |
1720 if (entry != NumberDictionary::kNotFound) { | 1721 if (entry != NumberDictionary::kNotFound) { |
1721 Object* element = dictionary->ValueAt(entry); | |
1722 PropertyDetails details = dictionary->DetailsAt(entry); | 1722 PropertyDetails details = dictionary->DetailsAt(entry); |
1723 if (details.type() == CALLBACKS) { | 1723 if (details.type() == CALLBACKS) { |
1724 SetElementWithCallback(element, index, value, JSObject::cast(pt)); | 1724 *found = true; |
1725 return true; | 1725 return SetElementWithCallback( |
| 1726 dictionary->ValueAt(entry), index, value, JSObject::cast(pt)); |
1726 } | 1727 } |
1727 } | 1728 } |
1728 } | 1729 } |
1729 return false; | 1730 *found = false; |
| 1731 return Heap::the_hole_value(); |
1730 } | 1732 } |
1731 | 1733 |
1732 | 1734 |
1733 void JSObject::LookupInDescriptor(String* name, LookupResult* result) { | 1735 void JSObject::LookupInDescriptor(String* name, LookupResult* result) { |
1734 DescriptorArray* descriptors = map()->instance_descriptors(); | 1736 DescriptorArray* descriptors = map()->instance_descriptors(); |
1735 int number = descriptors->SearchWithCache(name); | 1737 int number = descriptors->SearchWithCache(name); |
1736 if (number != DescriptorArray::kNotFound) { | 1738 if (number != DescriptorArray::kNotFound) { |
1737 result->DescriptorResult(this, descriptors->GetDetails(number), number); | 1739 result->DescriptorResult(this, descriptors->GetDetails(number), number); |
1738 } else { | 1740 } else { |
1739 result->NotFound(); | 1741 result->NotFound(); |
(...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2772 return context->extension()->ReferencesObject(obj); | 2774 return context->extension()->ReferencesObject(obj); |
2773 } | 2775 } |
2774 } | 2776 } |
2775 | 2777 |
2776 // No references to object. | 2778 // No references to object. |
2777 return false; | 2779 return false; |
2778 } | 2780 } |
2779 | 2781 |
2780 | 2782 |
2781 MaybeObject* JSObject::PreventExtensions() { | 2783 MaybeObject* JSObject::PreventExtensions() { |
| 2784 if (IsJSGlobalProxy()) { |
| 2785 Object* proto = GetPrototype(); |
| 2786 if (proto->IsNull()) return this; |
| 2787 ASSERT(proto->IsJSGlobalObject()); |
| 2788 return JSObject::cast(proto)->PreventExtensions(); |
| 2789 } |
| 2790 |
2782 // If there are fast elements we normalize. | 2791 // If there are fast elements we normalize. |
2783 if (HasFastElements()) { | 2792 if (HasFastElements()) { |
2784 Object* ok; | 2793 Object* ok; |
2785 { MaybeObject* maybe_ok = NormalizeElements(); | 2794 { MaybeObject* maybe_ok = NormalizeElements(); |
2786 if (!maybe_ok->ToObject(&ok)) return maybe_ok; | 2795 if (!maybe_ok->ToObject(&ok)) return maybe_ok; |
2787 } | 2796 } |
2788 } | 2797 } |
2789 // Make sure that we never go back to fast case. | 2798 // Make sure that we never go back to fast case. |
2790 element_dictionary()->set_requires_slow_elements(); | 2799 element_dictionary()->set_requires_slow_elements(); |
2791 | 2800 |
(...skipping 4163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6955 ASSERT(HasFastElements()); | 6964 ASSERT(HasFastElements()); |
6956 | 6965 |
6957 Object* elms_obj; | 6966 Object* elms_obj; |
6958 { MaybeObject* maybe_elms_obj = EnsureWritableFastElements(); | 6967 { MaybeObject* maybe_elms_obj = EnsureWritableFastElements(); |
6959 if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj; | 6968 if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj; |
6960 } | 6969 } |
6961 FixedArray* elms = FixedArray::cast(elms_obj); | 6970 FixedArray* elms = FixedArray::cast(elms_obj); |
6962 uint32_t elms_length = static_cast<uint32_t>(elms->length()); | 6971 uint32_t elms_length = static_cast<uint32_t>(elms->length()); |
6963 | 6972 |
6964 if (check_prototype && | 6973 if (check_prototype && |
6965 (index >= elms_length || elms->get(index)->IsTheHole()) && | 6974 (index >= elms_length || elms->get(index)->IsTheHole())) { |
6966 SetElementWithCallbackSetterInPrototypes(index, value)) { | 6975 bool found; |
6967 return value; | 6976 MaybeObject* result = |
| 6977 SetElementWithCallbackSetterInPrototypes(index, value, &found); |
| 6978 if (found) return result; |
6968 } | 6979 } |
6969 | 6980 |
6970 | 6981 |
6971 // Check whether there is extra space in fixed array.. | 6982 // Check whether there is extra space in fixed array.. |
6972 if (index < elms_length) { | 6983 if (index < elms_length) { |
6973 elms->set(index, value); | 6984 elms->set(index, value); |
6974 if (IsJSArray()) { | 6985 if (IsJSArray()) { |
6975 // Update the length of the array if needed. | 6986 // Update the length of the array if needed. |
6976 uint32_t array_length = 0; | 6987 uint32_t array_length = 0; |
6977 CHECK(JSArray::cast(this)->length()->ToArrayIndex(&array_length)); | 6988 CHECK(JSArray::cast(this)->length()->ToArrayIndex(&array_length)); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7089 Object* element = dictionary->ValueAt(entry); | 7100 Object* element = dictionary->ValueAt(entry); |
7090 PropertyDetails details = dictionary->DetailsAt(entry); | 7101 PropertyDetails details = dictionary->DetailsAt(entry); |
7091 if (details.type() == CALLBACKS) { | 7102 if (details.type() == CALLBACKS) { |
7092 return SetElementWithCallback(element, index, value, this); | 7103 return SetElementWithCallback(element, index, value, this); |
7093 } else { | 7104 } else { |
7094 dictionary->UpdateMaxNumberKey(index); | 7105 dictionary->UpdateMaxNumberKey(index); |
7095 dictionary->ValueAtPut(entry, value); | 7106 dictionary->ValueAtPut(entry, value); |
7096 } | 7107 } |
7097 } else { | 7108 } else { |
7098 // Index not already used. Look for an accessor in the prototype chain. | 7109 // Index not already used. Look for an accessor in the prototype chain. |
7099 if (check_prototype && | 7110 if (check_prototype) { |
7100 SetElementWithCallbackSetterInPrototypes(index, value)) { | 7111 bool found; |
7101 return value; | 7112 MaybeObject* result = |
| 7113 SetElementWithCallbackSetterInPrototypes(index, value, &found); |
| 7114 if (found) return result; |
7102 } | 7115 } |
7103 // When we set the is_extensible flag to false we always force | 7116 // When we set the is_extensible flag to false we always force |
7104 // the element into dictionary mode (and force them to stay there). | 7117 // the element into dictionary mode (and force them to stay there). |
7105 if (!map()->is_extensible()) { | 7118 if (!map()->is_extensible()) { |
7106 Handle<Object> number(Factory::NewNumberFromUint(index)); | 7119 Handle<Object> number(Factory::NewNumberFromUint(index)); |
7107 Handle<String> index_string(Factory::NumberToString(number)); | 7120 Handle<String> index_string(Factory::NumberToString(number)); |
7108 Handle<Object> args[1] = { index_string }; | 7121 Handle<Object> args[1] = { index_string }; |
7109 return Top::Throw(*Factory::NewTypeError("object_not_extensible", | 7122 return Top::Throw(*Factory::NewTypeError("object_not_extensible", |
7110 HandleVector(args, 1))); | 7123 HandleVector(args, 1))); |
7111 } | 7124 } |
(...skipping 2788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9900 if (break_point_objects()->IsUndefined()) return 0; | 9913 if (break_point_objects()->IsUndefined()) return 0; |
9901 // Single beak point. | 9914 // Single beak point. |
9902 if (!break_point_objects()->IsFixedArray()) return 1; | 9915 if (!break_point_objects()->IsFixedArray()) return 1; |
9903 // Multiple break points. | 9916 // Multiple break points. |
9904 return FixedArray::cast(break_point_objects())->length(); | 9917 return FixedArray::cast(break_point_objects())->length(); |
9905 } | 9918 } |
9906 #endif | 9919 #endif |
9907 | 9920 |
9908 | 9921 |
9909 } } // namespace v8::internal | 9922 } } // namespace v8::internal |
OLD | NEW |