Commit d550e818 authored by verwaest's avatar verwaest Committed by Commit bot

Cleanup API property handling

BUG=v8:4137
LOG=n

Review URL: https://codereview.chromium.org/1226473003

Cr-Commit-Position: refs/heads/master@{#29444}
parent 65a1d726
......@@ -3566,16 +3566,9 @@ static i::MaybeHandle<i::Object> DefineObjectProperty(
}
i::Handle<i::Name> name;
if (key->IsName()) {
name = i::Handle<i::Name>::cast(key);
} else {
// Call-back into JavaScript to convert the key to a string.
i::Handle<i::Object> converted;
ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, converted,
i::Execution::ToString(isolate, key),
ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, name,
i::Runtime::ToName(isolate, key),
i::MaybeHandle<i::Object>());
name = i::Handle<i::String>::cast(converted);
}
return i::JSObject::DefinePropertyOrElementIgnoreAttributes(js_object, name,
value, attrs);
......@@ -3614,44 +3607,24 @@ bool v8::Object::ForceSet(v8::Handle<Value> key, v8::Handle<Value> value,
}
namespace {
i::MaybeHandle<i::Object> DeleteObjectProperty(
MUST_USE_RESULT
static i::MaybeHandle<i::Object> DeleteObjectProperty(
i::Isolate* isolate, i::Handle<i::JSReceiver> receiver,
i::Handle<i::Object> key, i::LanguageMode language_mode) {
// Check if the given key is an array index.
uint32_t index = 0;
if (key->ToArrayIndex(&index)) {
// In Firefox/SpiderMonkey, Safari and Opera you can access the
// characters of a string using [] notation. In the case of a
// String object we just need to redirect the deletion to the
// underlying string if the index is in range. Since the
// underlying string does nothing with the deletion, we can ignore
// such deletions.
if (receiver->IsStringObjectWithCharacterAt(index)) {
return isolate->factory()->false_value();
}
return i::JSReceiver::DeleteElement(receiver, index, language_mode);
}
i::Handle<i::Name> name;
if (key->IsName()) {
name = i::Handle<i::Name>::cast(key);
} else {
// Call-back into JavaScript to convert the key to a string.
i::Handle<i::Object> converted;
if (!i::Execution::ToString(isolate, key).ToHandle(&converted)) {
return i::MaybeHandle<i::Object>();
}
name = i::Handle<i::String>::cast(converted);
}
ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, name,
i::Runtime::ToName(isolate, key),
i::MaybeHandle<i::Object>());
return i::JSReceiver::DeleteProperty(receiver, name, language_mode);
return i::JSReceiver::DeletePropertyOrElement(receiver, name, language_mode);
}
} // namespace
MaybeLocal<Value> v8::Object::Get(Local<v8::Context> context,
Local<Value> key) {
......
......@@ -5288,6 +5288,13 @@ MaybeHandle<Object> JSReceiver::DeleteElement(Handle<JSReceiver> object,
MaybeHandle<Object> JSReceiver::DeleteProperty(Handle<JSReceiver> object,
Handle<Name> name,
LanguageMode language_mode) {
LookupIterator it(object, name, LookupIterator::HIDDEN);
return JSObject::DeleteProperty(&it, language_mode);
}
MaybeHandle<Object> JSReceiver::DeletePropertyOrElement(
Handle<JSReceiver> object, Handle<Name> name, LanguageMode language_mode) {
LookupIterator it = LookupIterator::PropertyOrElement(
name->GetIsolate(), object, name, LookupIterator::HIDDEN);
return JSObject::DeleteProperty(&it, language_mode);
......
......@@ -1687,6 +1687,9 @@ class JSReceiver: public HeapObject {
Handle<JSReceiver> object, uint32_t index);
// Implementation of [[Delete]], ECMA-262 5th edition, section 8.12.7.
MUST_USE_RESULT static MaybeHandle<Object> DeletePropertyOrElement(
Handle<JSReceiver> object, Handle<Name> name,
LanguageMode language_mode = SLOPPY);
MUST_USE_RESULT static MaybeHandle<Object> DeleteProperty(
Handle<JSReceiver> object, Handle<Name> name,
LanguageMode language_mode = SLOPPY);
......
......@@ -596,7 +596,8 @@ RUNTIME_FUNCTION(Runtime_DeleteProperty) {
CONVERT_LANGUAGE_MODE_ARG_CHECKED(language_mode, 2);
Handle<Object> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result, JSReceiver::DeleteProperty(object, key, language_mode));
isolate, result,
JSReceiver::DeletePropertyOrElement(object, key, language_mode));
return *result;
}
......
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