Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 | 375 |
| 376 | 376 |
| 377 // static | 377 // static |
| 378 Handle<String> Object::TypeOf(Isolate* isolate, Handle<Object> object) { | 378 Handle<String> Object::TypeOf(Isolate* isolate, Handle<Object> object) { |
| 379 if (object->IsNumber()) return isolate->factory()->number_string(); | 379 if (object->IsNumber()) return isolate->factory()->number_string(); |
| 380 if (object->IsUndefined() || object->IsUndetectableObject()) { | 380 if (object->IsUndefined() || object->IsUndetectableObject()) { |
| 381 return isolate->factory()->undefined_string(); | 381 return isolate->factory()->undefined_string(); |
| 382 } | 382 } |
| 383 if (object->IsBoolean()) return isolate->factory()->boolean_string(); | 383 if (object->IsBoolean()) return isolate->factory()->boolean_string(); |
| 384 if (object->IsSymbol()) return isolate->factory()->symbol_string(); | 384 if (object->IsSymbol()) return isolate->factory()->symbol_string(); |
| 385 if (object->IsString()) return isolate->factory()->string_string(); | |
| 385 #define SIMD128_TYPE(TYPE, Type, type, lane_count, lane_type) \ | 386 #define SIMD128_TYPE(TYPE, Type, type, lane_count, lane_type) \ |
| 386 if (object->Is##Type()) return isolate->factory()->type##_string(); | 387 if (object->Is##Type()) return isolate->factory()->type##_string(); |
| 387 SIMD128_TYPES(SIMD128_TYPE) | 388 SIMD128_TYPES(SIMD128_TYPE) |
| 388 #undef SIMD128_TYPE | 389 #undef SIMD128_TYPE |
| 389 if (object->IsCallable()) return isolate->factory()->function_string(); | 390 if (object->IsCallable()) return isolate->factory()->function_string(); |
| 390 return isolate->factory()->object_string(); | 391 return isolate->factory()->object_string(); |
| 391 } | 392 } |
| 392 | 393 |
| 393 | 394 |
| 394 // static | 395 // static |
| (...skipping 3286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3681 MaybeHandle<Object> Object::SetSuperProperty(LookupIterator* it, | 3682 MaybeHandle<Object> Object::SetSuperProperty(LookupIterator* it, |
| 3682 Handle<Object> value, | 3683 Handle<Object> value, |
| 3683 LanguageMode language_mode, | 3684 LanguageMode language_mode, |
| 3684 StoreFromKeyed store_mode) { | 3685 StoreFromKeyed store_mode) { |
| 3685 bool found = false; | 3686 bool found = false; |
| 3686 MaybeHandle<Object> result = | 3687 MaybeHandle<Object> result = |
| 3687 SetPropertyInternal(it, value, language_mode, store_mode, &found); | 3688 SetPropertyInternal(it, value, language_mode, store_mode, &found); |
| 3688 if (found) return result; | 3689 if (found) return result; |
| 3689 | 3690 |
| 3690 if (!it->GetReceiver()->IsJSReceiver()) { | 3691 if (!it->GetReceiver()->IsJSReceiver()) { |
| 3691 return WriteToReadOnlyProperty(it->isolate(), it->GetReceiver(), | 3692 return WriteToReadOnlyProperty(it, value, language_mode); |
| 3692 it->GetName(), value, language_mode); | |
| 3693 } | 3693 } |
| 3694 | 3694 |
| 3695 LookupIterator::Configuration c = LookupIterator::OWN; | 3695 LookupIterator::Configuration c = LookupIterator::OWN; |
| 3696 LookupIterator own_lookup = | 3696 LookupIterator own_lookup = |
| 3697 it->IsElement() | 3697 it->IsElement() |
| 3698 ? LookupIterator(it->isolate(), it->GetReceiver(), it->index(), c) | 3698 ? LookupIterator(it->isolate(), it->GetReceiver(), it->index(), c) |
| 3699 : LookupIterator(it->GetReceiver(), it->name(), c); | 3699 : LookupIterator(it->GetReceiver(), it->name(), c); |
| 3700 | 3700 |
| 3701 for (; own_lookup.IsFound(); own_lookup.Next()) { | 3701 for (; own_lookup.IsFound(); own_lookup.Next()) { |
| 3702 switch (own_lookup.state()) { | 3702 switch (own_lookup.state()) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3768 if (is_strong(language_mode)) { | 3768 if (is_strong(language_mode)) { |
| 3769 THROW_NEW_ERROR( | 3769 THROW_NEW_ERROR( |
| 3770 isolate, | 3770 isolate, |
| 3771 NewTypeError(MessageTemplate::kStrongPropertyAccess, name, receiver), | 3771 NewTypeError(MessageTemplate::kStrongPropertyAccess, name, receiver), |
| 3772 Object); | 3772 Object); |
| 3773 } | 3773 } |
| 3774 return isolate->factory()->undefined_value(); | 3774 return isolate->factory()->undefined_value(); |
| 3775 } | 3775 } |
| 3776 | 3776 |
| 3777 | 3777 |
| 3778 MaybeHandle<Object> Object::CannotCreateProperty(LookupIterator* it, | |
| 3779 Handle<Object> value, | |
| 3780 LanguageMode language_mode) { | |
| 3781 return CannotCreateProperty(it->isolate(), it->GetReceiver(), it->GetName(), | |
| 3782 value, language_mode); | |
| 3783 } | |
| 3784 | |
| 3785 | |
| 3786 MaybeHandle<Object> Object::CannotCreateProperty(Isolate* isolate, | |
| 3787 Handle<Object> receiver, | |
| 3788 Handle<Object> name, | |
| 3789 Handle<Object> value, | |
| 3790 LanguageMode language_mode) { | |
| 3791 if (is_sloppy(language_mode)) return value; | |
| 3792 Handle<String> typeof_string = Object::TypeOf(isolate, receiver); | |
| 3793 THROW_NEW_ERROR(isolate, | |
| 3794 NewTypeError(MessageTemplate::kStrictCannotCreateProperty, | |
| 3795 name, typeof_string, receiver), | |
| 3796 Object); | |
| 3797 } | |
| 3798 | |
| 3799 | |
| 3778 MaybeHandle<Object> Object::WriteToReadOnlyProperty( | 3800 MaybeHandle<Object> Object::WriteToReadOnlyProperty( |
| 3779 LookupIterator* it, Handle<Object> value, LanguageMode language_mode) { | 3801 LookupIterator* it, Handle<Object> value, LanguageMode language_mode) { |
| 3780 return WriteToReadOnlyProperty(it->isolate(), it->GetReceiver(), | 3802 return WriteToReadOnlyProperty(it->isolate(), it->GetReceiver(), |
| 3781 it->GetName(), value, language_mode); | 3803 it->GetName(), value, language_mode); |
| 3782 } | 3804 } |
| 3783 | 3805 |
| 3784 | 3806 |
| 3785 MaybeHandle<Object> Object::WriteToReadOnlyProperty( | 3807 MaybeHandle<Object> Object::WriteToReadOnlyProperty( |
| 3786 Isolate* isolate, Handle<Object> receiver, Handle<Object> name, | 3808 Isolate* isolate, Handle<Object> receiver, Handle<Object> name, |
| 3787 Handle<Object> value, LanguageMode language_mode) { | 3809 Handle<Object> value, LanguageMode language_mode) { |
| 3788 if (is_sloppy(language_mode)) return value; | 3810 if (is_sloppy(language_mode)) return value; |
| 3789 THROW_NEW_ERROR( | 3811 Handle<String> typeof_string = Object::TypeOf(isolate, receiver); |
| 3790 isolate, | 3812 THROW_NEW_ERROR(isolate, |
| 3791 NewTypeError(MessageTemplate::kStrictReadOnlyProperty, name, receiver), | 3813 NewTypeError(MessageTemplate::kStrictReadOnlyProperty, name, |
| 3792 Object); | 3814 typeof_string, receiver), |
| 3815 Object); | |
| 3793 } | 3816 } |
| 3794 | 3817 |
| 3795 | 3818 |
| 3796 MaybeHandle<Object> Object::RedefineNonconfigurableProperty( | 3819 MaybeHandle<Object> Object::RedefineNonconfigurableProperty( |
| 3797 Isolate* isolate, Handle<Object> name, Handle<Object> value, | 3820 Isolate* isolate, Handle<Object> name, Handle<Object> value, |
| 3798 LanguageMode language_mode) { | 3821 LanguageMode language_mode) { |
| 3799 if (is_sloppy(language_mode)) return value; | 3822 if (is_sloppy(language_mode)) return value; |
| 3800 THROW_NEW_ERROR(isolate, | 3823 THROW_NEW_ERROR(isolate, |
| 3801 NewTypeError(MessageTemplate::kRedefineDisallowed, name), | 3824 NewTypeError(MessageTemplate::kRedefineDisallowed, name), |
| 3802 Object); | 3825 Object); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3907 } | 3930 } |
| 3908 | 3931 |
| 3909 | 3932 |
| 3910 MaybeHandle<Object> Object::AddDataProperty(LookupIterator* it, | 3933 MaybeHandle<Object> Object::AddDataProperty(LookupIterator* it, |
| 3911 Handle<Object> value, | 3934 Handle<Object> value, |
| 3912 PropertyAttributes attributes, | 3935 PropertyAttributes attributes, |
| 3913 LanguageMode language_mode, | 3936 LanguageMode language_mode, |
| 3914 StoreFromKeyed store_mode) { | 3937 StoreFromKeyed store_mode) { |
| 3915 DCHECK(!it->GetReceiver()->IsJSProxy()); | 3938 DCHECK(!it->GetReceiver()->IsJSProxy()); |
| 3916 if (!it->GetReceiver()->IsJSObject()) { | 3939 if (!it->GetReceiver()->IsJSObject()) { |
| 3917 // TODO(verwaest): Throw a TypeError with a more specific message. | 3940 if (!it->IsFound()) { |
| 3918 return WriteToReadOnlyProperty(it, value, language_mode); | 3941 return CannotCreateProperty(it, value, language_mode); |
| 3942 } else { | |
| 3943 return WriteToReadOnlyProperty(it, value, language_mode); | |
|
Toon Verwaest
2015/10/07 14:21:37
This case shouldn't happen I think.
Camillo Bruni
2015/10/07 14:30:41
removed.
| |
| 3944 } | |
| 3919 } | 3945 } |
| 3920 | 3946 |
| 3921 DCHECK_NE(LookupIterator::INTEGER_INDEXED_EXOTIC, it->state()); | 3947 DCHECK_NE(LookupIterator::INTEGER_INDEXED_EXOTIC, it->state()); |
| 3922 | 3948 |
| 3923 Handle<JSObject> receiver = it->GetStoreTarget(); | 3949 Handle<JSObject> receiver = it->GetStoreTarget(); |
| 3924 | 3950 |
| 3925 // If the receiver is a JSGlobalProxy, store on the prototype (JSGlobalObject) | 3951 // If the receiver is a JSGlobalProxy, store on the prototype (JSGlobalObject) |
| 3926 // instead. If the prototype is Null, the proxy is detached. | 3952 // instead. If the prototype is Null, the proxy is detached. |
| 3927 if (receiver->IsJSGlobalProxy()) return value; | 3953 if (receiver->IsJSGlobalProxy()) return value; |
| 3928 | 3954 |
| (...skipping 9564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13493 uint32_t length = 0; | 13519 uint32_t length = 0; |
| 13494 CHECK(array->length()->ToArrayLength(&length)); | 13520 CHECK(array->length()->ToArrayLength(&length)); |
| 13495 if (length <= index) return HasReadOnlyLength(array); | 13521 if (length <= index) return HasReadOnlyLength(array); |
| 13496 return false; | 13522 return false; |
| 13497 } | 13523 } |
| 13498 | 13524 |
| 13499 | 13525 |
| 13500 MaybeHandle<Object> JSArray::ReadOnlyLengthError(Handle<JSArray> array) { | 13526 MaybeHandle<Object> JSArray::ReadOnlyLengthError(Handle<JSArray> array) { |
| 13501 Isolate* isolate = array->GetIsolate(); | 13527 Isolate* isolate = array->GetIsolate(); |
| 13502 Handle<Name> length = isolate->factory()->length_string(); | 13528 Handle<Name> length = isolate->factory()->length_string(); |
| 13503 THROW_NEW_ERROR( | 13529 Handle<String> typeof_string = Object::TypeOf(isolate, array); |
| 13504 isolate, | 13530 THROW_NEW_ERROR(isolate, |
| 13505 NewTypeError(MessageTemplate::kStrictReadOnlyProperty, length, array), | 13531 NewTypeError(MessageTemplate::kStrictReadOnlyProperty, length, |
| 13506 Object); | 13532 typeof_string, array), |
| 13533 Object); | |
| 13507 } | 13534 } |
| 13508 | 13535 |
| 13509 | 13536 |
| 13510 template <typename BackingStore> | 13537 template <typename BackingStore> |
| 13511 static int FastHoleyElementsUsage(JSObject* object, BackingStore* store) { | 13538 static int FastHoleyElementsUsage(JSObject* object, BackingStore* store) { |
| 13512 int limit = object->IsJSArray() | 13539 int limit = object->IsJSArray() |
| 13513 ? Smi::cast(JSArray::cast(object)->length())->value() | 13540 ? Smi::cast(JSArray::cast(object)->length())->value() |
| 13514 : store->length(); | 13541 : store->length(); |
| 13515 int used = 0; | 13542 int used = 0; |
| 13516 for (int i = 0; i < limit; ++i) { | 13543 for (int i = 0; i < limit; ++i) { |
| (...skipping 3352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 16869 if (cell->value() != *new_value) { | 16896 if (cell->value() != *new_value) { |
| 16870 cell->set_value(*new_value); | 16897 cell->set_value(*new_value); |
| 16871 Isolate* isolate = cell->GetIsolate(); | 16898 Isolate* isolate = cell->GetIsolate(); |
| 16872 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 16899 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
| 16873 isolate, DependentCode::kPropertyCellChangedGroup); | 16900 isolate, DependentCode::kPropertyCellChangedGroup); |
| 16874 } | 16901 } |
| 16875 } | 16902 } |
| 16876 | 16903 |
| 16877 } // namespace internal | 16904 } // namespace internal |
| 16878 } // namespace v8 | 16905 } // namespace v8 |
| OLD | NEW |