Commit 67bee814 authored by littledan's avatar littledan Committed by Commit bot

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}
parent 0395c50c
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment