OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1713 } | 1713 } |
1714 if (dict != result) set_properties(StringDictionary::cast(result)); | 1714 if (dict != result) set_properties(StringDictionary::cast(result)); |
1715 return value; | 1715 return value; |
1716 } | 1716 } |
1717 | 1717 |
1718 | 1718 |
1719 MaybeObject* JSObject::AddProperty(String* name, | 1719 MaybeObject* JSObject::AddProperty(String* name, |
1720 Object* value, | 1720 Object* value, |
1721 PropertyAttributes attributes, | 1721 PropertyAttributes attributes, |
1722 StrictModeFlag strict_mode, | 1722 StrictModeFlag strict_mode, |
1723 JSReceiver::StoreFromKeyed store_mode) { | 1723 JSReceiver::StoreFromKeyed store_mode, |
| 1724 ExtensibilityCheck extensibility_check) { |
1724 ASSERT(!IsJSGlobalProxy()); | 1725 ASSERT(!IsJSGlobalProxy()); |
1725 Map* map_of_this = map(); | 1726 Map* map_of_this = map(); |
1726 Heap* heap = GetHeap(); | 1727 Heap* heap = GetHeap(); |
1727 if (!map_of_this->is_extensible()) { | 1728 if (extensibility_check == PERFORM_EXTENSIBILITY_CHECK && |
| 1729 !map_of_this->is_extensible()) { |
1728 if (strict_mode == kNonStrictMode) { | 1730 if (strict_mode == kNonStrictMode) { |
1729 return value; | 1731 return value; |
1730 } else { | 1732 } else { |
1731 Handle<Object> args[1] = {Handle<String>(name)}; | 1733 Handle<Object> args[1] = {Handle<String>(name)}; |
1732 return heap->isolate()->Throw( | 1734 return heap->isolate()->Throw( |
1733 *FACTORY->NewTypeError("object_not_extensible", | 1735 *FACTORY->NewTypeError("object_not_extensible", |
1734 HandleVector(args, 1))); | 1736 HandleVector(args, 1))); |
1735 } | 1737 } |
1736 } | 1738 } |
1737 if (HasFastProperties()) { | 1739 if (HasFastProperties()) { |
(...skipping 18 matching lines...) Expand all Loading... |
1756 } | 1758 } |
1757 } | 1759 } |
1758 return AddSlowProperty(name, value, attributes); | 1760 return AddSlowProperty(name, value, attributes); |
1759 } | 1761 } |
1760 | 1762 |
1761 | 1763 |
1762 MaybeObject* JSObject::SetPropertyPostInterceptor( | 1764 MaybeObject* JSObject::SetPropertyPostInterceptor( |
1763 String* name, | 1765 String* name, |
1764 Object* value, | 1766 Object* value, |
1765 PropertyAttributes attributes, | 1767 PropertyAttributes attributes, |
1766 StrictModeFlag strict_mode) { | 1768 StrictModeFlag strict_mode, |
| 1769 ExtensibilityCheck extensibility_check) { |
1767 // Check local property, ignore interceptor. | 1770 // Check local property, ignore interceptor. |
1768 LookupResult result(GetIsolate()); | 1771 LookupResult result(GetIsolate()); |
1769 LocalLookupRealNamedProperty(name, &result); | 1772 LocalLookupRealNamedProperty(name, &result); |
1770 if (result.IsFound()) { | 1773 if (result.IsFound()) { |
1771 // An existing property, a map transition or a null descriptor was | 1774 // An existing property, a map transition or a null descriptor was |
1772 // found. Use set property to handle all these cases. | 1775 // found. Use set property to handle all these cases. |
1773 return SetProperty(&result, name, value, attributes, strict_mode); | 1776 return SetProperty(&result, name, value, attributes, strict_mode); |
1774 } | 1777 } |
1775 bool done = false; | 1778 bool done = false; |
1776 MaybeObject* result_object; | 1779 MaybeObject* result_object; |
1777 result_object = | 1780 result_object = |
1778 SetPropertyViaPrototypes(name, value, attributes, strict_mode, &done); | 1781 SetPropertyViaPrototypes(name, value, attributes, strict_mode, &done); |
1779 if (done) return result_object; | 1782 if (done) return result_object; |
1780 // Add a new real property. | 1783 // Add a new real property. |
1781 return AddProperty(name, value, attributes, strict_mode); | 1784 return AddProperty(name, value, attributes, strict_mode, |
| 1785 MAY_BE_STORE_FROM_KEYED, extensibility_check); |
1782 } | 1786 } |
1783 | 1787 |
1784 | 1788 |
1785 MaybeObject* JSObject::ReplaceSlowProperty(String* name, | 1789 MaybeObject* JSObject::ReplaceSlowProperty(String* name, |
1786 Object* value, | 1790 Object* value, |
1787 PropertyAttributes attributes) { | 1791 PropertyAttributes attributes) { |
1788 StringDictionary* dictionary = property_dictionary(); | 1792 StringDictionary* dictionary = property_dictionary(); |
1789 int old_index = dictionary->FindEntry(name); | 1793 int old_index = dictionary->FindEntry(name); |
1790 int new_enumeration_index = 0; // 0 means "Use the next available index." | 1794 int new_enumeration_index = 0; // 0 means "Use the next available index." |
1791 if (old_index != -1) { | 1795 if (old_index != -1) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1928 v8::Utils::ToLocal(value_unhole), | 1932 v8::Utils::ToLocal(value_unhole), |
1929 info); | 1933 info); |
1930 } | 1934 } |
1931 RETURN_IF_SCHEDULED_EXCEPTION(isolate); | 1935 RETURN_IF_SCHEDULED_EXCEPTION(isolate); |
1932 if (!result.IsEmpty()) return *value_handle; | 1936 if (!result.IsEmpty()) return *value_handle; |
1933 } | 1937 } |
1934 MaybeObject* raw_result = | 1938 MaybeObject* raw_result = |
1935 this_handle->SetPropertyPostInterceptor(*name_handle, | 1939 this_handle->SetPropertyPostInterceptor(*name_handle, |
1936 *value_handle, | 1940 *value_handle, |
1937 attributes, | 1941 attributes, |
1938 strict_mode); | 1942 strict_mode, |
| 1943 PERFORM_EXTENSIBILITY_CHECK); |
1939 RETURN_IF_SCHEDULED_EXCEPTION(isolate); | 1944 RETURN_IF_SCHEDULED_EXCEPTION(isolate); |
1940 return raw_result; | 1945 return raw_result; |
1941 } | 1946 } |
1942 | 1947 |
1943 | 1948 |
1944 Handle<Object> JSReceiver::SetProperty(Handle<JSReceiver> object, | 1949 Handle<Object> JSReceiver::SetProperty(Handle<JSReceiver> object, |
1945 Handle<String> key, | 1950 Handle<String> key, |
1946 Handle<Object> value, | 1951 Handle<Object> value, |
1947 PropertyAttributes attributes, | 1952 PropertyAttributes attributes, |
1948 StrictModeFlag strict_mode) { | 1953 StrictModeFlag strict_mode) { |
(...skipping 1708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3657 &attributes)->ToObjectUnchecked(); | 3662 &attributes)->ToObjectUnchecked(); |
3658 if (!lookup->IsUndefined()) { | 3663 if (!lookup->IsUndefined()) { |
3659 return StringDictionary::cast(lookup); | 3664 return StringDictionary::cast(lookup); |
3660 } | 3665 } |
3661 } | 3666 } |
3662 if (!create_if_absent) return GetHeap()->undefined_value(); | 3667 if (!create_if_absent) return GetHeap()->undefined_value(); |
3663 const int kInitialSize = 5; | 3668 const int kInitialSize = 5; |
3664 MaybeObject* dict_alloc = StringDictionary::Allocate(kInitialSize); | 3669 MaybeObject* dict_alloc = StringDictionary::Allocate(kInitialSize); |
3665 StringDictionary* dictionary; | 3670 StringDictionary* dictionary; |
3666 if (!dict_alloc->To<StringDictionary>(&dictionary)) return dict_alloc; | 3671 if (!dict_alloc->To<StringDictionary>(&dictionary)) return dict_alloc; |
3667 // Using AddProperty or SetPropertyPostInterceptor here could fail, because | 3672 MaybeObject* store_result = |
3668 // object might be non-extensible. | 3673 SetPropertyPostInterceptor(GetHeap()->hidden_symbol(), |
3669 return HasFastProperties() | 3674 dictionary, |
3670 ? AddFastProperty(GetHeap()->hidden_symbol(), dictionary, DONT_ENUM) | 3675 DONT_ENUM, |
3671 : AddSlowProperty(GetHeap()->hidden_symbol(), dictionary, DONT_ENUM); | 3676 kNonStrictMode, |
| 3677 OMIT_EXTENSIBILITY_CHECK); |
| 3678 if (store_result->IsFailure()) return store_result; |
| 3679 return dictionary; |
3672 } | 3680 } |
3673 | 3681 |
3674 | 3682 |
3675 MaybeObject* JSObject::SetHiddenPropertiesDictionary( | 3683 MaybeObject* JSObject::SetHiddenPropertiesDictionary( |
3676 StringDictionary* dictionary) { | 3684 StringDictionary* dictionary) { |
3677 ASSERT(!IsJSGlobalProxy()); | 3685 ASSERT(!IsJSGlobalProxy()); |
3678 ASSERT(HasHiddenProperties()); | 3686 ASSERT(HasHiddenProperties()); |
3679 if (HasFastProperties()) { | 3687 if (HasFastProperties()) { |
3680 // If the object has fast properties, check whether the first slot | 3688 // If the object has fast properties, check whether the first slot |
3681 // in the descriptor array matches the hidden symbol. Since the | 3689 // in the descriptor array matches the hidden symbol. Since the |
3682 // hidden symbols hash code is zero (and no other string has hash | 3690 // hidden symbols hash code is zero (and no other string has hash |
3683 // code zero) it will always occupy the first entry if present. | 3691 // code zero) it will always occupy the first entry if present. |
3684 DescriptorArray* descriptors = this->map()->instance_descriptors(); | 3692 DescriptorArray* descriptors = this->map()->instance_descriptors(); |
3685 if ((descriptors->number_of_descriptors() > 0) && | 3693 if ((descriptors->number_of_descriptors() > 0) && |
3686 (descriptors->GetKey(0) == GetHeap()->hidden_symbol())) { | 3694 (descriptors->GetKey(0) == GetHeap()->hidden_symbol())) { |
3687 if (descriptors->GetType(0) == FIELD) { | 3695 if (descriptors->GetType(0) == FIELD) { |
3688 this->FastPropertyAtPut(descriptors->GetFieldIndex(0), dictionary); | 3696 this->FastPropertyAtPut(descriptors->GetFieldIndex(0), dictionary); |
3689 return this; | 3697 return this; |
3690 } else { | 3698 } else { |
3691 ASSERT(descriptors->GetType(0) == NULL_DESCRIPTOR || | 3699 ASSERT(descriptors->GetType(0) == NULL_DESCRIPTOR || |
3692 descriptors->GetType(0) == MAP_TRANSITION); | 3700 descriptors->GetType(0) == MAP_TRANSITION); |
3693 } | 3701 } |
3694 } | 3702 } |
3695 } | 3703 } |
3696 MaybeObject* store_result = | 3704 MaybeObject* store_result = |
3697 SetPropertyPostInterceptor(GetHeap()->hidden_symbol(), | 3705 SetPropertyPostInterceptor(GetHeap()->hidden_symbol(), |
3698 dictionary, | 3706 dictionary, |
3699 DONT_ENUM, | 3707 DONT_ENUM, |
3700 kNonStrictMode); | 3708 kNonStrictMode, |
| 3709 OMIT_EXTENSIBILITY_CHECK); |
3701 if (store_result->IsFailure()) return store_result; | 3710 if (store_result->IsFailure()) return store_result; |
3702 return this; | 3711 return this; |
3703 } | 3712 } |
3704 | 3713 |
3705 | 3714 |
3706 MaybeObject* JSObject::DeletePropertyPostInterceptor(String* name, | 3715 MaybeObject* JSObject::DeletePropertyPostInterceptor(String* name, |
3707 DeleteMode mode) { | 3716 DeleteMode mode) { |
3708 // Check local property, ignore interceptor. | 3717 // Check local property, ignore interceptor. |
3709 LookupResult result(GetIsolate()); | 3718 LookupResult result(GetIsolate()); |
3710 LocalLookupRealNamedProperty(name, &result); | 3719 LocalLookupRealNamedProperty(name, &result); |
(...skipping 9485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13196 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); | 13205 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); |
13197 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); | 13206 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); |
13198 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); | 13207 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); |
13199 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); | 13208 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); |
13200 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); | 13209 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); |
13201 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); | 13210 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); |
13202 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); | 13211 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); |
13203 } | 13212 } |
13204 | 13213 |
13205 } } // namespace v8::internal | 13214 } } // namespace v8::internal |
OLD | NEW |