Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Unified Diff: src/objects.cc

Issue 1381083004: Improving error messages when adding properties to non JSObject receiver in (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: removing unused branch Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.h ('k') | test/mjsunit/harmony/super.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
« no previous file with comments | « src/objects.h ('k') | test/mjsunit/harmony/super.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698