| 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 1687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1698 } | 1698 } |
| 1699 if (result->type() == CALLBACKS) { | 1699 if (result->type() == CALLBACKS) { |
| 1700 return; | 1700 return; |
| 1701 } | 1701 } |
| 1702 } | 1702 } |
| 1703 } | 1703 } |
| 1704 result->NotFound(); | 1704 result->NotFound(); |
| 1705 } | 1705 } |
| 1706 | 1706 |
| 1707 | 1707 |
| 1708 bool JSObject::SetElementWithCallbackSetterInPrototypes(uint32_t index, | 1708 MaybeObject* JSObject::SetElementWithCallbackSetterInPrototypes(uint32_t index, |
| 1709 Object* value) { | 1709 Object* value, |
| 1710 bool* found) { |
| 1710 for (Object* pt = GetPrototype(); | 1711 for (Object* pt = GetPrototype(); |
| 1711 pt != Heap::null_value(); | 1712 pt != Heap::null_value(); |
| 1712 pt = pt->GetPrototype()) { | 1713 pt = pt->GetPrototype()) { |
| 1713 if (!JSObject::cast(pt)->HasDictionaryElements()) { | 1714 if (!JSObject::cast(pt)->HasDictionaryElements()) { |
| 1714 continue; | 1715 continue; |
| 1715 } | 1716 } |
| 1716 NumberDictionary* dictionary = JSObject::cast(pt)->element_dictionary(); | 1717 NumberDictionary* dictionary = JSObject::cast(pt)->element_dictionary(); |
| 1717 int entry = dictionary->FindEntry(index); | 1718 int entry = dictionary->FindEntry(index); |
| 1718 if (entry != NumberDictionary::kNotFound) { | 1719 if (entry != NumberDictionary::kNotFound) { |
| 1719 Object* element = dictionary->ValueAt(entry); | |
| 1720 PropertyDetails details = dictionary->DetailsAt(entry); | 1720 PropertyDetails details = dictionary->DetailsAt(entry); |
| 1721 if (details.type() == CALLBACKS) { | 1721 if (details.type() == CALLBACKS) { |
| 1722 SetElementWithCallback(element, index, value, JSObject::cast(pt)); | 1722 *found = true; |
| 1723 return true; | 1723 return SetElementWithCallback( |
| 1724 dictionary->ValueAt(entry), index, value, JSObject::cast(pt)); |
| 1724 } | 1725 } |
| 1725 } | 1726 } |
| 1726 } | 1727 } |
| 1727 return false; | 1728 *found = false; |
| 1729 return Heap::the_hole_value(); |
| 1728 } | 1730 } |
| 1729 | 1731 |
| 1730 | 1732 |
| 1731 void JSObject::LookupInDescriptor(String* name, LookupResult* result) { | 1733 void JSObject::LookupInDescriptor(String* name, LookupResult* result) { |
| 1732 DescriptorArray* descriptors = map()->instance_descriptors(); | 1734 DescriptorArray* descriptors = map()->instance_descriptors(); |
| 1733 int number = descriptors->SearchWithCache(name); | 1735 int number = descriptors->SearchWithCache(name); |
| 1734 if (number != DescriptorArray::kNotFound) { | 1736 if (number != DescriptorArray::kNotFound) { |
| 1735 result->DescriptorResult(this, descriptors->GetDetails(number), number); | 1737 result->DescriptorResult(this, descriptors->GetDetails(number), number); |
| 1736 } else { | 1738 } else { |
| 1737 result->NotFound(); | 1739 result->NotFound(); |
| (...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2767 return context->extension()->ReferencesObject(obj); | 2769 return context->extension()->ReferencesObject(obj); |
| 2768 } | 2770 } |
| 2769 } | 2771 } |
| 2770 | 2772 |
| 2771 // No references to object. | 2773 // No references to object. |
| 2772 return false; | 2774 return false; |
| 2773 } | 2775 } |
| 2774 | 2776 |
| 2775 | 2777 |
| 2776 MaybeObject* JSObject::PreventExtensions() { | 2778 MaybeObject* JSObject::PreventExtensions() { |
| 2779 if (IsJSGlobalProxy()) { |
| 2780 Object* proto = GetPrototype(); |
| 2781 if (proto->IsNull()) return this; |
| 2782 ASSERT(proto->IsJSGlobalObject()); |
| 2783 return JSObject::cast(proto)->PreventExtensions(); |
| 2784 } |
| 2785 |
| 2777 // If there are fast elements we normalize. | 2786 // If there are fast elements we normalize. |
| 2778 if (HasFastElements()) { | 2787 if (HasFastElements()) { |
| 2779 Object* ok; | 2788 Object* ok; |
| 2780 { MaybeObject* maybe_ok = NormalizeElements(); | 2789 { MaybeObject* maybe_ok = NormalizeElements(); |
| 2781 if (!maybe_ok->ToObject(&ok)) return maybe_ok; | 2790 if (!maybe_ok->ToObject(&ok)) return maybe_ok; |
| 2782 } | 2791 } |
| 2783 } | 2792 } |
| 2784 // Make sure that we never go back to fast case. | 2793 // Make sure that we never go back to fast case. |
| 2785 element_dictionary()->set_requires_slow_elements(); | 2794 element_dictionary()->set_requires_slow_elements(); |
| 2786 | 2795 |
| (...skipping 4163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6950 ASSERT(HasFastElements()); | 6959 ASSERT(HasFastElements()); |
| 6951 | 6960 |
| 6952 Object* elms_obj; | 6961 Object* elms_obj; |
| 6953 { MaybeObject* maybe_elms_obj = EnsureWritableFastElements(); | 6962 { MaybeObject* maybe_elms_obj = EnsureWritableFastElements(); |
| 6954 if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj; | 6963 if (!maybe_elms_obj->ToObject(&elms_obj)) return maybe_elms_obj; |
| 6955 } | 6964 } |
| 6956 FixedArray* elms = FixedArray::cast(elms_obj); | 6965 FixedArray* elms = FixedArray::cast(elms_obj); |
| 6957 uint32_t elms_length = static_cast<uint32_t>(elms->length()); | 6966 uint32_t elms_length = static_cast<uint32_t>(elms->length()); |
| 6958 | 6967 |
| 6959 if (check_prototype && | 6968 if (check_prototype && |
| 6960 (index >= elms_length || elms->get(index)->IsTheHole()) && | 6969 (index >= elms_length || elms->get(index)->IsTheHole())) { |
| 6961 SetElementWithCallbackSetterInPrototypes(index, value)) { | 6970 bool found; |
| 6962 return value; | 6971 MaybeObject* result = |
| 6972 SetElementWithCallbackSetterInPrototypes(index, value, &found); |
| 6973 if (found) return result; |
| 6963 } | 6974 } |
| 6964 | 6975 |
| 6965 | 6976 |
| 6966 // Check whether there is extra space in fixed array.. | 6977 // Check whether there is extra space in fixed array.. |
| 6967 if (index < elms_length) { | 6978 if (index < elms_length) { |
| 6968 elms->set(index, value); | 6979 elms->set(index, value); |
| 6969 if (IsJSArray()) { | 6980 if (IsJSArray()) { |
| 6970 // Update the length of the array if needed. | 6981 // Update the length of the array if needed. |
| 6971 uint32_t array_length = 0; | 6982 uint32_t array_length = 0; |
| 6972 CHECK(JSArray::cast(this)->length()->ToArrayIndex(&array_length)); | 6983 CHECK(JSArray::cast(this)->length()->ToArrayIndex(&array_length)); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7084 Object* element = dictionary->ValueAt(entry); | 7095 Object* element = dictionary->ValueAt(entry); |
| 7085 PropertyDetails details = dictionary->DetailsAt(entry); | 7096 PropertyDetails details = dictionary->DetailsAt(entry); |
| 7086 if (details.type() == CALLBACKS) { | 7097 if (details.type() == CALLBACKS) { |
| 7087 return SetElementWithCallback(element, index, value, this); | 7098 return SetElementWithCallback(element, index, value, this); |
| 7088 } else { | 7099 } else { |
| 7089 dictionary->UpdateMaxNumberKey(index); | 7100 dictionary->UpdateMaxNumberKey(index); |
| 7090 dictionary->ValueAtPut(entry, value); | 7101 dictionary->ValueAtPut(entry, value); |
| 7091 } | 7102 } |
| 7092 } else { | 7103 } else { |
| 7093 // Index not already used. Look for an accessor in the prototype chain. | 7104 // Index not already used. Look for an accessor in the prototype chain. |
| 7094 if (check_prototype && | 7105 if (check_prototype) { |
| 7095 SetElementWithCallbackSetterInPrototypes(index, value)) { | 7106 bool found; |
| 7096 return value; | 7107 MaybeObject* result = |
| 7108 SetElementWithCallbackSetterInPrototypes(index, value, &found); |
| 7109 if (found) return result; |
| 7097 } | 7110 } |
| 7098 // When we set the is_extensible flag to false we always force | 7111 // When we set the is_extensible flag to false we always force |
| 7099 // the element into dictionary mode (and force them to stay there). | 7112 // the element into dictionary mode (and force them to stay there). |
| 7100 if (!map()->is_extensible()) { | 7113 if (!map()->is_extensible()) { |
| 7101 Handle<Object> number(Factory::NewNumberFromUint(index)); | 7114 Handle<Object> number(Factory::NewNumberFromUint(index)); |
| 7102 Handle<String> index_string(Factory::NumberToString(number)); | 7115 Handle<String> index_string(Factory::NumberToString(number)); |
| 7103 Handle<Object> args[1] = { index_string }; | 7116 Handle<Object> args[1] = { index_string }; |
| 7104 return Top::Throw(*Factory::NewTypeError("object_not_extensible", | 7117 return Top::Throw(*Factory::NewTypeError("object_not_extensible", |
| 7105 HandleVector(args, 1))); | 7118 HandleVector(args, 1))); |
| 7106 } | 7119 } |
| (...skipping 2771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9878 if (break_point_objects()->IsUndefined()) return 0; | 9891 if (break_point_objects()->IsUndefined()) return 0; |
| 9879 // Single beak point. | 9892 // Single beak point. |
| 9880 if (!break_point_objects()->IsFixedArray()) return 1; | 9893 if (!break_point_objects()->IsFixedArray()) return 1; |
| 9881 // Multiple break points. | 9894 // Multiple break points. |
| 9882 return FixedArray::cast(break_point_objects())->length(); | 9895 return FixedArray::cast(break_point_objects())->length(); |
| 9883 } | 9896 } |
| 9884 #endif | 9897 #endif |
| 9885 | 9898 |
| 9886 | 9899 |
| 9887 } } // namespace v8::internal | 9900 } } // namespace v8::internal |
| OLD | NEW |