Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index 99c24d8aff67e1f32f447d6daace83242d94515e..9da7a50967bf6d3f1cb7345b554e376e2f4808e1 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -382,6 +382,7 @@ Handle<String> Object::TypeOf(Isolate* isolate, Handle<Object> object) { |
} |
if (object->IsBoolean()) return isolate->factory()->boolean_string(); |
if (object->IsSymbol()) return isolate->factory()->symbol_string(); |
+ if (object->IsString()) return isolate->factory()->string_string(); |
#define SIMD128_TYPE(TYPE, Type, type, lane_count, lane_type) \ |
if (object->Is##Type()) return isolate->factory()->type##_string(); |
SIMD128_TYPES(SIMD128_TYPE) |
@@ -3688,8 +3689,7 @@ MaybeHandle<Object> Object::SetSuperProperty(LookupIterator* it, |
if (found) return result; |
if (!it->GetReceiver()->IsJSReceiver()) { |
- return WriteToReadOnlyProperty(it->isolate(), it->GetReceiver(), |
- it->GetName(), value, language_mode); |
+ return WriteToReadOnlyProperty(it, value, language_mode); |
} |
LookupIterator::Configuration c = LookupIterator::OWN; |
@@ -3775,6 +3775,28 @@ MaybeHandle<Object> Object::ReadAbsentProperty(Isolate* isolate, |
} |
+MaybeHandle<Object> Object::CannotCreateProperty(LookupIterator* it, |
+ Handle<Object> value, |
+ LanguageMode language_mode) { |
+ return CannotCreateProperty(it->isolate(), it->GetReceiver(), it->GetName(), |
+ value, language_mode); |
+} |
+ |
+ |
+MaybeHandle<Object> Object::CannotCreateProperty(Isolate* isolate, |
+ Handle<Object> receiver, |
+ Handle<Object> name, |
+ Handle<Object> value, |
+ LanguageMode language_mode) { |
+ if (is_sloppy(language_mode)) return value; |
+ Handle<String> typeof_string = Object::TypeOf(isolate, receiver); |
+ THROW_NEW_ERROR(isolate, |
+ NewTypeError(MessageTemplate::kStrictCannotCreateProperty, |
+ name, typeof_string, receiver), |
+ Object); |
+} |
+ |
+ |
MaybeHandle<Object> Object::WriteToReadOnlyProperty( |
LookupIterator* it, Handle<Object> value, LanguageMode language_mode) { |
return WriteToReadOnlyProperty(it->isolate(), it->GetReceiver(), |
@@ -3786,10 +3808,11 @@ MaybeHandle<Object> Object::WriteToReadOnlyProperty( |
Isolate* isolate, Handle<Object> receiver, Handle<Object> name, |
Handle<Object> value, LanguageMode language_mode) { |
if (is_sloppy(language_mode)) return value; |
- THROW_NEW_ERROR( |
- isolate, |
- NewTypeError(MessageTemplate::kStrictReadOnlyProperty, name, receiver), |
- Object); |
+ Handle<String> typeof_string = Object::TypeOf(isolate, receiver); |
+ THROW_NEW_ERROR(isolate, |
+ NewTypeError(MessageTemplate::kStrictReadOnlyProperty, name, |
+ typeof_string, receiver), |
+ Object); |
} |
@@ -3914,8 +3937,7 @@ MaybeHandle<Object> Object::AddDataProperty(LookupIterator* it, |
StoreFromKeyed store_mode) { |
DCHECK(!it->GetReceiver()->IsJSProxy()); |
if (!it->GetReceiver()->IsJSObject()) { |
- // TODO(verwaest): Throw a TypeError with a more specific message. |
- return WriteToReadOnlyProperty(it, value, language_mode); |
+ return CannotCreateProperty(it, value, language_mode); |
} |
DCHECK_NE(LookupIterator::INTEGER_INDEXED_EXOTIC, it->state()); |
@@ -13500,10 +13522,11 @@ bool JSArray::WouldChangeReadOnlyLength(Handle<JSArray> array, |
MaybeHandle<Object> JSArray::ReadOnlyLengthError(Handle<JSArray> array) { |
Isolate* isolate = array->GetIsolate(); |
Handle<Name> length = isolate->factory()->length_string(); |
- THROW_NEW_ERROR( |
- isolate, |
- NewTypeError(MessageTemplate::kStrictReadOnlyProperty, length, array), |
- Object); |
+ Handle<String> typeof_string = Object::TypeOf(isolate, array); |
+ THROW_NEW_ERROR(isolate, |
+ NewTypeError(MessageTemplate::kStrictReadOnlyProperty, length, |
+ typeof_string, array), |
+ Object); |
} |