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 return CannotCreateProperty(it, value, language_mode); |
3918 return WriteToReadOnlyProperty(it, value, language_mode); | |
3919 } | 3941 } |
3920 | 3942 |
3921 DCHECK_NE(LookupIterator::INTEGER_INDEXED_EXOTIC, it->state()); | 3943 DCHECK_NE(LookupIterator::INTEGER_INDEXED_EXOTIC, it->state()); |
3922 | 3944 |
3923 Handle<JSObject> receiver = it->GetStoreTarget(); | 3945 Handle<JSObject> receiver = it->GetStoreTarget(); |
3924 | 3946 |
3925 // If the receiver is a JSGlobalProxy, store on the prototype (JSGlobalObject) | 3947 // If the receiver is a JSGlobalProxy, store on the prototype (JSGlobalObject) |
3926 // instead. If the prototype is Null, the proxy is detached. | 3948 // instead. If the prototype is Null, the proxy is detached. |
3927 if (receiver->IsJSGlobalProxy()) return value; | 3949 if (receiver->IsJSGlobalProxy()) return value; |
3928 | 3950 |
(...skipping 9564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13493 uint32_t length = 0; | 13515 uint32_t length = 0; |
13494 CHECK(array->length()->ToArrayLength(&length)); | 13516 CHECK(array->length()->ToArrayLength(&length)); |
13495 if (length <= index) return HasReadOnlyLength(array); | 13517 if (length <= index) return HasReadOnlyLength(array); |
13496 return false; | 13518 return false; |
13497 } | 13519 } |
13498 | 13520 |
13499 | 13521 |
13500 MaybeHandle<Object> JSArray::ReadOnlyLengthError(Handle<JSArray> array) { | 13522 MaybeHandle<Object> JSArray::ReadOnlyLengthError(Handle<JSArray> array) { |
13501 Isolate* isolate = array->GetIsolate(); | 13523 Isolate* isolate = array->GetIsolate(); |
13502 Handle<Name> length = isolate->factory()->length_string(); | 13524 Handle<Name> length = isolate->factory()->length_string(); |
13503 THROW_NEW_ERROR( | 13525 Handle<String> typeof_string = Object::TypeOf(isolate, array); |
13504 isolate, | 13526 THROW_NEW_ERROR(isolate, |
13505 NewTypeError(MessageTemplate::kStrictReadOnlyProperty, length, array), | 13527 NewTypeError(MessageTemplate::kStrictReadOnlyProperty, length, |
13506 Object); | 13528 typeof_string, array), |
| 13529 Object); |
13507 } | 13530 } |
13508 | 13531 |
13509 | 13532 |
13510 template <typename BackingStore> | 13533 template <typename BackingStore> |
13511 static int FastHoleyElementsUsage(JSObject* object, BackingStore* store) { | 13534 static int FastHoleyElementsUsage(JSObject* object, BackingStore* store) { |
13512 int limit = object->IsJSArray() | 13535 int limit = object->IsJSArray() |
13513 ? Smi::cast(JSArray::cast(object)->length())->value() | 13536 ? Smi::cast(JSArray::cast(object)->length())->value() |
13514 : store->length(); | 13537 : store->length(); |
13515 int used = 0; | 13538 int used = 0; |
13516 for (int i = 0; i < limit; ++i) { | 13539 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) { | 16892 if (cell->value() != *new_value) { |
16870 cell->set_value(*new_value); | 16893 cell->set_value(*new_value); |
16871 Isolate* isolate = cell->GetIsolate(); | 16894 Isolate* isolate = cell->GetIsolate(); |
16872 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 16895 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
16873 isolate, DependentCode::kPropertyCellChangedGroup); | 16896 isolate, DependentCode::kPropertyCellChangedGroup); |
16874 } | 16897 } |
16875 } | 16898 } |
16876 | 16899 |
16877 } // namespace internal | 16900 } // namespace internal |
16878 } // namespace v8 | 16901 } // namespace v8 |
OLD | NEW |