Throw exceptions from CreateDataProperty when should_throw
Previously, when a property was non-configurable or the object was non-extensible, CreateDataProperty might just return false rather than throwing, even if should_throw was on. This patch fixes that issue. Tested by running the patch at https://codereview.chromium.org/1814933002 on top of this code and observing the tests to see an exception thrown. R=adamk BUG=chromium:595319 LOG=Y Review URL: https://codereview.chromium.org/1809233002 Cr-Commit-Position: refs/heads/master@{#34875}
This commit is contained in:
parent
0395c50c60
commit
67bee8149a
@ -6666,7 +6666,7 @@ Maybe<bool> JSReceiver::CreateDataProperty(LookupIterator* it,
|
||||
Isolate* isolate = receiver->GetIsolate();
|
||||
|
||||
if (receiver->IsJSObject()) {
|
||||
return JSObject::CreateDataProperty(it, value); // Shortcut.
|
||||
return JSObject::CreateDataProperty(it, value, should_throw); // Shortcut.
|
||||
}
|
||||
|
||||
PropertyDescriptor new_desc;
|
||||
@ -6679,17 +6679,26 @@ Maybe<bool> JSReceiver::CreateDataProperty(LookupIterator* it,
|
||||
&new_desc, should_throw);
|
||||
}
|
||||
|
||||
|
||||
Maybe<bool> JSObject::CreateDataProperty(LookupIterator* it,
|
||||
Handle<Object> value) {
|
||||
Handle<Object> value,
|
||||
ShouldThrow should_throw) {
|
||||
DCHECK(it->GetReceiver()->IsJSObject());
|
||||
MAYBE_RETURN(JSReceiver::GetPropertyAttributes(it), Nothing<bool>());
|
||||
Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(it->GetReceiver());
|
||||
Isolate* isolate = receiver->GetIsolate();
|
||||
|
||||
if (it->IsFound()) {
|
||||
if (!it->IsConfigurable()) return Just(false);
|
||||
if (!it->IsConfigurable()) {
|
||||
RETURN_FAILURE(
|
||||
isolate, should_throw,
|
||||
NewTypeError(MessageTemplate::kRedefineDisallowed, it->GetName()));
|
||||
}
|
||||
} else {
|
||||
if (!JSObject::IsExtensible(Handle<JSObject>::cast(it->GetReceiver())))
|
||||
return Just(false);
|
||||
if (!JSObject::IsExtensible(Handle<JSObject>::cast(it->GetReceiver()))) {
|
||||
RETURN_FAILURE(
|
||||
isolate, should_throw,
|
||||
NewTypeError(MessageTemplate::kDefineDisallowed, it->GetName()));
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_ON_EXCEPTION_VALUE(it->isolate(),
|
||||
|
@ -2104,8 +2104,9 @@ class JSObject: public JSReceiver {
|
||||
|
||||
// Adds or reconfigures a property to attributes NONE. It will fail when it
|
||||
// cannot.
|
||||
MUST_USE_RESULT static Maybe<bool> CreateDataProperty(LookupIterator* it,
|
||||
Handle<Object> value);
|
||||
MUST_USE_RESULT static Maybe<bool> CreateDataProperty(
|
||||
LookupIterator* it, Handle<Object> value,
|
||||
ShouldThrow should_throw = DONT_THROW);
|
||||
|
||||
static void AddProperty(Handle<JSObject> object, Handle<Name> name,
|
||||
Handle<Object> value, PropertyAttributes attributes);
|
||||
|
Loading…
Reference in New Issue
Block a user