OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/objects.h" | 5 #include "src/objects.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <iomanip> | 8 #include <iomanip> |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 4271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4282 // property. | 4282 // property. |
4283 | 4283 |
4284 ShouldThrow should_throw = | 4284 ShouldThrow should_throw = |
4285 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR; | 4285 is_sloppy(language_mode) ? DONT_THROW : THROW_ON_ERROR; |
4286 | 4286 |
4287 if (!it->GetReceiver()->IsJSReceiver()) { | 4287 if (!it->GetReceiver()->IsJSReceiver()) { |
4288 return WriteToReadOnlyProperty(it, value, should_throw); | 4288 return WriteToReadOnlyProperty(it, value, should_throw); |
4289 } | 4289 } |
4290 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(it->GetReceiver()); | 4290 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(it->GetReceiver()); |
4291 | 4291 |
4292 LookupIterator::Configuration c = LookupIterator::HIDDEN; | 4292 LookupIterator::Configuration c = LookupIterator::OWN; |
4293 LookupIterator own_lookup = | 4293 LookupIterator own_lookup = |
4294 it->IsElement() ? LookupIterator(isolate, receiver, it->index(), c) | 4294 it->IsElement() ? LookupIterator(isolate, receiver, it->index(), c) |
4295 : LookupIterator(receiver, it->name(), c); | 4295 : LookupIterator(receiver, it->name(), c); |
4296 | 4296 |
4297 for (; own_lookup.IsFound(); own_lookup.Next()) { | 4297 for (; own_lookup.IsFound(); own_lookup.Next()) { |
4298 switch (own_lookup.state()) { | 4298 switch (own_lookup.state()) { |
4299 case LookupIterator::ACCESS_CHECK: | 4299 case LookupIterator::ACCESS_CHECK: |
4300 if (!own_lookup.HasAccess()) { | 4300 if (!own_lookup.HasAccess()) { |
4301 return JSObject::SetPropertyWithFailedAccessCheck(&own_lookup, value, | 4301 return JSObject::SetPropertyWithFailedAccessCheck(&own_lookup, value, |
4302 should_throw); | 4302 should_throw); |
(...skipping 1678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5981 } | 5981 } |
5982 } | 5982 } |
5983 | 5983 |
5984 return Just(true); | 5984 return Just(true); |
5985 } | 5985 } |
5986 | 5986 |
5987 | 5987 |
5988 Maybe<bool> JSReceiver::DeleteElement(Handle<JSReceiver> object, uint32_t index, | 5988 Maybe<bool> JSReceiver::DeleteElement(Handle<JSReceiver> object, uint32_t index, |
5989 LanguageMode language_mode) { | 5989 LanguageMode language_mode) { |
5990 LookupIterator it(object->GetIsolate(), object, index, object, | 5990 LookupIterator it(object->GetIsolate(), object, index, object, |
5991 LookupIterator::HIDDEN); | 5991 LookupIterator::OWN); |
5992 return DeleteProperty(&it, language_mode); | 5992 return DeleteProperty(&it, language_mode); |
5993 } | 5993 } |
5994 | 5994 |
5995 | 5995 |
5996 Maybe<bool> JSReceiver::DeleteProperty(Handle<JSReceiver> object, | 5996 Maybe<bool> JSReceiver::DeleteProperty(Handle<JSReceiver> object, |
5997 Handle<Name> name, | 5997 Handle<Name> name, |
5998 LanguageMode language_mode) { | 5998 LanguageMode language_mode) { |
5999 LookupIterator it(object, name, object, LookupIterator::HIDDEN); | 5999 LookupIterator it(object, name, object, LookupIterator::OWN); |
6000 return DeleteProperty(&it, language_mode); | 6000 return DeleteProperty(&it, language_mode); |
6001 } | 6001 } |
6002 | 6002 |
6003 | 6003 |
6004 Maybe<bool> JSReceiver::DeletePropertyOrElement(Handle<JSReceiver> object, | 6004 Maybe<bool> JSReceiver::DeletePropertyOrElement(Handle<JSReceiver> object, |
6005 Handle<Name> name, | 6005 Handle<Name> name, |
6006 LanguageMode language_mode) { | 6006 LanguageMode language_mode) { |
6007 LookupIterator it = LookupIterator::PropertyOrElement( | 6007 LookupIterator it = LookupIterator::PropertyOrElement( |
6008 name->GetIsolate(), object, name, object, LookupIterator::HIDDEN); | 6008 name->GetIsolate(), object, name, object, LookupIterator::OWN); |
6009 return DeleteProperty(&it, language_mode); | 6009 return DeleteProperty(&it, language_mode); |
6010 } | 6010 } |
6011 | 6011 |
6012 | 6012 |
6013 // ES6 7.1.14 | 6013 // ES6 7.1.14 |
6014 // static | 6014 // static |
6015 MaybeHandle<Object> Object::ToPropertyKey(Isolate* isolate, | 6015 MaybeHandle<Object> Object::ToPropertyKey(Isolate* isolate, |
6016 Handle<Object> value) { | 6016 Handle<Object> value) { |
6017 // 1. Let key be ToPrimitive(argument, hint String). | 6017 // 1. Let key be ToPrimitive(argument, hint String). |
6018 MaybeHandle<Object> maybe_key = | 6018 MaybeHandle<Object> maybe_key = |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6099 int capacity = keys->length(); | 6099 int capacity = keys->length(); |
6100 std::vector<PropertyDescriptor> descriptors(capacity); | 6100 std::vector<PropertyDescriptor> descriptors(capacity); |
6101 size_t descriptors_index = 0; | 6101 size_t descriptors_index = 0; |
6102 // 7. Repeat for each element nextKey of keys in List order, | 6102 // 7. Repeat for each element nextKey of keys in List order, |
6103 for (int i = 0; i < keys->length(); ++i) { | 6103 for (int i = 0; i < keys->length(); ++i) { |
6104 Handle<Object> next_key(keys->get(i), isolate); | 6104 Handle<Object> next_key(keys->get(i), isolate); |
6105 // 7a. Let propDesc be props.[[GetOwnProperty]](nextKey). | 6105 // 7a. Let propDesc be props.[[GetOwnProperty]](nextKey). |
6106 // 7b. ReturnIfAbrupt(propDesc). | 6106 // 7b. ReturnIfAbrupt(propDesc). |
6107 bool success = false; | 6107 bool success = false; |
6108 LookupIterator it = LookupIterator::PropertyOrElement( | 6108 LookupIterator it = LookupIterator::PropertyOrElement( |
6109 isolate, props, next_key, &success, LookupIterator::HIDDEN); | 6109 isolate, props, next_key, &success, LookupIterator::OWN); |
6110 DCHECK(success); | 6110 DCHECK(success); |
6111 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); | 6111 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); |
6112 if (!maybe.IsJust()) return MaybeHandle<Object>(); | 6112 if (!maybe.IsJust()) return MaybeHandle<Object>(); |
6113 PropertyAttributes attrs = maybe.FromJust(); | 6113 PropertyAttributes attrs = maybe.FromJust(); |
6114 // 7c. If propDesc is not undefined and propDesc.[[Enumerable]] is true: | 6114 // 7c. If propDesc is not undefined and propDesc.[[Enumerable]] is true: |
6115 if (attrs == ABSENT) continue; | 6115 if (attrs == ABSENT) continue; |
6116 if (attrs & DONT_ENUM) continue; | 6116 if (attrs & DONT_ENUM) continue; |
6117 // 7c i. Let descObj be Get(props, nextKey). | 6117 // 7c i. Let descObj be Get(props, nextKey). |
6118 // 7c ii. ReturnIfAbrupt(descObj). | 6118 // 7c ii. ReturnIfAbrupt(descObj). |
6119 Handle<Object> desc_obj; | 6119 Handle<Object> desc_obj; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6174 | 6174 |
6175 // static | 6175 // static |
6176 Maybe<bool> JSReceiver::OrdinaryDefineOwnProperty(Isolate* isolate, | 6176 Maybe<bool> JSReceiver::OrdinaryDefineOwnProperty(Isolate* isolate, |
6177 Handle<JSObject> object, | 6177 Handle<JSObject> object, |
6178 Handle<Object> key, | 6178 Handle<Object> key, |
6179 PropertyDescriptor* desc, | 6179 PropertyDescriptor* desc, |
6180 ShouldThrow should_throw) { | 6180 ShouldThrow should_throw) { |
6181 bool success = false; | 6181 bool success = false; |
6182 DCHECK(key->IsName() || key->IsNumber()); // |key| is a PropertyKey... | 6182 DCHECK(key->IsName() || key->IsNumber()); // |key| is a PropertyKey... |
6183 LookupIterator it = LookupIterator::PropertyOrElement( | 6183 LookupIterator it = LookupIterator::PropertyOrElement( |
6184 isolate, object, key, &success, LookupIterator::HIDDEN); | 6184 isolate, object, key, &success, LookupIterator::OWN); |
6185 DCHECK(success); // ...so creating a LookupIterator can't fail. | 6185 DCHECK(success); // ...so creating a LookupIterator can't fail. |
6186 | 6186 |
6187 // Deal with access checks first. | 6187 // Deal with access checks first. |
6188 if (it.state() == LookupIterator::ACCESS_CHECK) { | 6188 if (it.state() == LookupIterator::ACCESS_CHECK) { |
6189 if (!it.HasAccess()) { | 6189 if (!it.HasAccess()) { |
6190 isolate->ReportFailedAccessCheck(it.GetHolder<JSObject>()); | 6190 isolate->ReportFailedAccessCheck(it.GetHolder<JSObject>()); |
6191 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, Nothing<bool>()); | 6191 RETURN_VALUE_IF_SCHEDULED_EXCEPTION(isolate, Nothing<bool>()); |
6192 return Just(true); | 6192 return Just(true); |
6193 } | 6193 } |
6194 it.Next(); | 6194 it.Next(); |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6901 | 6901 |
6902 | 6902 |
6903 // static | 6903 // static |
6904 Maybe<bool> JSReceiver::GetOwnPropertyDescriptor(Isolate* isolate, | 6904 Maybe<bool> JSReceiver::GetOwnPropertyDescriptor(Isolate* isolate, |
6905 Handle<JSReceiver> object, | 6905 Handle<JSReceiver> object, |
6906 Handle<Object> key, | 6906 Handle<Object> key, |
6907 PropertyDescriptor* desc) { | 6907 PropertyDescriptor* desc) { |
6908 bool success = false; | 6908 bool success = false; |
6909 DCHECK(key->IsName() || key->IsNumber()); // |key| is a PropertyKey... | 6909 DCHECK(key->IsName() || key->IsNumber()); // |key| is a PropertyKey... |
6910 LookupIterator it = LookupIterator::PropertyOrElement( | 6910 LookupIterator it = LookupIterator::PropertyOrElement( |
6911 isolate, object, key, &success, LookupIterator::HIDDEN); | 6911 isolate, object, key, &success, LookupIterator::OWN); |
6912 DCHECK(success); // ...so creating a LookupIterator can't fail. | 6912 DCHECK(success); // ...so creating a LookupIterator can't fail. |
6913 return GetOwnPropertyDescriptor(&it, desc); | 6913 return GetOwnPropertyDescriptor(&it, desc); |
6914 } | 6914 } |
6915 | 6915 |
6916 | 6916 |
6917 // ES6 9.1.5.1 | 6917 // ES6 9.1.5.1 |
6918 // Returns true on success, false if the property didn't exist, nothing if | 6918 // Returns true on success, false if the property didn't exist, nothing if |
6919 // an exception was thrown. | 6919 // an exception was thrown. |
6920 // static | 6920 // static |
6921 Maybe<bool> JSReceiver::GetOwnPropertyDescriptor(LookupIterator* it, | 6921 Maybe<bool> JSReceiver::GetOwnPropertyDescriptor(LookupIterator* it, |
(...skipping 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8276 | 8276 |
8277 | 8277 |
8278 MaybeHandle<Object> JSObject::DefineAccessor(Handle<JSObject> object, | 8278 MaybeHandle<Object> JSObject::DefineAccessor(Handle<JSObject> object, |
8279 Handle<Name> name, | 8279 Handle<Name> name, |
8280 Handle<Object> getter, | 8280 Handle<Object> getter, |
8281 Handle<Object> setter, | 8281 Handle<Object> setter, |
8282 PropertyAttributes attributes) { | 8282 PropertyAttributes attributes) { |
8283 Isolate* isolate = object->GetIsolate(); | 8283 Isolate* isolate = object->GetIsolate(); |
8284 | 8284 |
8285 LookupIterator it = LookupIterator::PropertyOrElement( | 8285 LookupIterator it = LookupIterator::PropertyOrElement( |
8286 isolate, object, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR); | 8286 isolate, object, name, LookupIterator::OWN_SKIP_INTERCEPTOR); |
8287 return DefineAccessor(&it, getter, setter, attributes); | 8287 return DefineAccessor(&it, getter, setter, attributes); |
8288 } | 8288 } |
8289 | 8289 |
8290 | 8290 |
8291 MaybeHandle<Object> JSObject::DefineAccessor(LookupIterator* it, | 8291 MaybeHandle<Object> JSObject::DefineAccessor(LookupIterator* it, |
8292 Handle<Object> getter, | 8292 Handle<Object> getter, |
8293 Handle<Object> setter, | 8293 Handle<Object> setter, |
8294 PropertyAttributes attributes) { | 8294 PropertyAttributes attributes) { |
8295 Isolate* isolate = it->isolate(); | 8295 Isolate* isolate = it->isolate(); |
8296 | 8296 |
(...skipping 23 matching lines...) Expand all Loading... |
8320 return isolate->factory()->undefined_value(); | 8320 return isolate->factory()->undefined_value(); |
8321 } | 8321 } |
8322 | 8322 |
8323 | 8323 |
8324 MaybeHandle<Object> JSObject::SetAccessor(Handle<JSObject> object, | 8324 MaybeHandle<Object> JSObject::SetAccessor(Handle<JSObject> object, |
8325 Handle<AccessorInfo> info) { | 8325 Handle<AccessorInfo> info) { |
8326 Isolate* isolate = object->GetIsolate(); | 8326 Isolate* isolate = object->GetIsolate(); |
8327 Handle<Name> name(Name::cast(info->name()), isolate); | 8327 Handle<Name> name(Name::cast(info->name()), isolate); |
8328 | 8328 |
8329 LookupIterator it = LookupIterator::PropertyOrElement( | 8329 LookupIterator it = LookupIterator::PropertyOrElement( |
8330 isolate, object, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR); | 8330 isolate, object, name, LookupIterator::OWN_SKIP_INTERCEPTOR); |
8331 | 8331 |
8332 // Duplicate ACCESS_CHECK outside of GetPropertyAttributes for the case that | 8332 // Duplicate ACCESS_CHECK outside of GetPropertyAttributes for the case that |
8333 // the FailedAccessCheckCallbackFunction doesn't throw an exception. | 8333 // the FailedAccessCheckCallbackFunction doesn't throw an exception. |
8334 // | 8334 // |
8335 // TODO(verwaest): Force throw an exception if the callback doesn't, so we can | 8335 // TODO(verwaest): Force throw an exception if the callback doesn't, so we can |
8336 // remove reliance on default return values. | 8336 // remove reliance on default return values. |
8337 if (it.state() == LookupIterator::ACCESS_CHECK) { | 8337 if (it.state() == LookupIterator::ACCESS_CHECK) { |
8338 if (!it.HasAccess()) { | 8338 if (!it.HasAccess()) { |
8339 isolate->ReportFailedAccessCheck(object); | 8339 isolate->ReportFailedAccessCheck(object); |
8340 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); | 8340 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); |
(...skipping 5609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13950 from->length()); | 13950 from->length()); |
13951 } | 13951 } |
13952 | 13952 |
13953 // static | 13953 // static |
13954 void JSArray::Initialize(Handle<JSArray> array, int capacity, int length) { | 13954 void JSArray::Initialize(Handle<JSArray> array, int capacity, int length) { |
13955 DCHECK(capacity >= 0); | 13955 DCHECK(capacity >= 0); |
13956 array->GetIsolate()->factory()->NewJSArrayStorage( | 13956 array->GetIsolate()->factory()->NewJSArrayStorage( |
13957 array, length, capacity, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); | 13957 array, length, capacity, INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE); |
13958 } | 13958 } |
13959 | 13959 |
13960 | |
13961 void JSArray::SetLength(Handle<JSArray> array, uint32_t new_length) { | 13960 void JSArray::SetLength(Handle<JSArray> array, uint32_t new_length) { |
13962 // We should never end in here with a pixel or external array. | 13961 // We should never end in here with a pixel or external array. |
13963 DCHECK(array->AllowsSetLength()); | 13962 DCHECK(array->AllowsSetLength()); |
13964 if (array->SetLengthWouldNormalize(new_length)) { | 13963 if (array->SetLengthWouldNormalize(new_length)) { |
13965 JSObject::NormalizeElements(array); | 13964 JSObject::NormalizeElements(array); |
13966 } | 13965 } |
13967 array->GetElementsAccessor()->SetLength(array, new_length); | 13966 array->GetElementsAccessor()->SetLength(array, new_length); |
13968 } | 13967 } |
13969 | 13968 |
13970 | 13969 |
(...skipping 4326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
18297 if (cell->value() != *new_value) { | 18296 if (cell->value() != *new_value) { |
18298 cell->set_value(*new_value); | 18297 cell->set_value(*new_value); |
18299 Isolate* isolate = cell->GetIsolate(); | 18298 Isolate* isolate = cell->GetIsolate(); |
18300 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 18299 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
18301 isolate, DependentCode::kPropertyCellChangedGroup); | 18300 isolate, DependentCode::kPropertyCellChangedGroup); |
18302 } | 18301 } |
18303 } | 18302 } |
18304 | 18303 |
18305 } // namespace internal | 18304 } // namespace internal |
18306 } // namespace v8 | 18305 } // namespace v8 |
OLD | NEW |