Chromium Code Reviews| Index: src/objects.cc |
| diff --git a/src/objects.cc b/src/objects.cc |
| index 9f25145bf2c197048ee858906c251158c8e8570e..dbcbd5a1048731243134cfa0694aed50f642f29b 100644 |
| --- a/src/objects.cc |
| +++ b/src/objects.cc |
| @@ -802,6 +802,99 @@ MaybeHandle<Object> Object::GetElementWithReceiver(Isolate* isolate, |
| } |
| +static MaybeHandle<Object> GetElementStructure(Isolate* isolate, |
| + Handle<JSObject> object, |
| + uint32_t index) { |
| + if (!object->HasDictionaryElements() && |
| + !object->HasDictionaryArgumentsElements()) |
| + return MaybeHandle<Object>(); |
| + Handle<FixedArray> elements(FixedArray::cast(object->elements())); |
| + bool is_arguments = |
| + (elements->map() == isolate->heap()->sloppy_arguments_elements_map()); |
| + Handle<SeededNumberDictionary> dictionary( |
| + is_arguments ? SeededNumberDictionary::cast(elements->get(1)) |
| + : SeededNumberDictionary::cast(*elements)); |
| + int entry = dictionary->FindEntry(index); |
| + if (entry != SeededNumberDictionary::kNotFound) { |
| + Handle<Object> element(dictionary->ValueAt(entry), isolate); |
| + PropertyDetails details = dictionary->DetailsAt(entry); |
| + if (details.type() == CALLBACKS) return element; |
| + } |
| + return MaybeHandle<Object>(); |
| +} |
| + |
| + |
| +MaybeHandle<Object> Object::SetElementWithReceiver( |
| + Isolate* isolate, Handle<Object> object, Handle<Object> receiver, |
| + uint32_t index, Handle<Object> value, StrictMode strict_mode) { |
| + // Iterate up the prototype chain until an element is found or the null |
| + // prototype is encountered. |
| + bool done = false; |
| + for (PrototypeIterator iter(isolate, object, |
| + object->IsJSProxy() || object->IsJSObject() |
| + ? PrototypeIterator::START_AT_RECEIVER |
| + : PrototypeIterator::START_AT_PROTOTYPE); |
| + !iter.IsAtEnd() && !done; iter.Advance()) { |
| + if (PrototypeIterator::GetCurrent(iter)->IsJSProxy()) { |
| + // TODO(dslomov): implement. |
| + isolate->ThrowIllegalOperation(); |
| + return MaybeHandle<Object>(); |
| + } |
| + |
| + Handle<JSObject> js_object = |
| + Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)); |
| + |
| + // Check access rights if needed. |
| + if (js_object->IsAccessCheckNeeded()) { |
| + if (!isolate->MayIndexedAccess(js_object, index, v8::ACCESS_SET)) { |
| + isolate->ReportFailedAccessCheck(js_object, v8::ACCESS_SET); |
| + RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); |
| + return isolate->factory()->undefined_value(); |
| + } |
| + } |
| + |
| + if (js_object->HasIndexedInterceptor()) { |
|
Toon Verwaest
2014/10/13 12:16:36
If the holder is not the receiver, query the attri
Dmitry Lomov (no reviews)
2014/10/13 13:48:59
Done.
|
| + Handle<InterceptorInfo> interceptor(js_object->GetIndexedInterceptor()); |
| + if (interceptor->setter()->IsUndefined()) { |
| + return WriteToReadOnlyElement(isolate, receiver, index, value, |
| + strict_mode); |
| + } |
| + // Treat indexed interceptor as presense of data property. |
| + done = true; |
| + } else if (js_object->elements() != isolate->heap()->empty_fixed_array()) { |
| + ElementsAccessor* accessor = js_object->GetElementsAccessor(); |
| + PropertyAttributes attrs = |
| + accessor->GetAttributes(receiver, js_object, index); |
| + if ((attrs & READ_ONLY) != 0) { |
| + return WriteToReadOnlyElement(isolate, receiver, index, value, |
| + strict_mode); |
| + } |
| + Handle<Object> element_structure; |
| + if (GetElementStructure(isolate, js_object, index) |
| + .ToHandle(&element_structure)) { |
| + return JSObject::SetElementWithCallback( |
| + receiver, element_structure, index, value, js_object, strict_mode); |
| + } else { |
| + done = attrs != ABSENT; |
| + } |
| + } |
| + } |
| + |
| + if (!receiver->IsJSObject()) { |
| + return WriteToReadOnlyElement(isolate, receiver, index, value, strict_mode); |
|
Toon Verwaest
2014/10/13 12:16:36
You only need to throw read-only exceptions for in
Dmitry Lomov (no reviews)
2014/10/13 13:48:59
Done.
|
| + } |
| + Handle<JSObject> target = Handle<JSObject>::cast(receiver); |
| + ElementsAccessor* accessor = target->GetElementsAccessor(); |
| + PropertyAttributes attrs = accessor->GetAttributes(receiver, target, index); |
| + if ((attrs & READ_ONLY) != 0) { |
| + return WriteToReadOnlyElement(isolate, receiver, index, value, strict_mode); |
| + } |
| + PropertyAttributes new_attrs = attrs != ABSENT ? attrs : NONE; |
| + return JSObject::SetElement(target, index, value, new_attrs, strict_mode, |
| + false); |
|
Toon Verwaest
2014/10/13 12:16:36
Add a test to ensure that SetElement updates the l
Dmitry Lomov (no reviews)
2014/10/13 13:48:59
Done.
|
| +} |
| + |
| + |
| Map* Object::GetRootMap(Isolate* isolate) { |
| DisallowHeapAllocation no_alloc; |
| if (IsSmi()) { |
| @@ -2930,6 +3023,21 @@ MaybeHandle<Object> Object::WriteToReadOnlyProperty(LookupIterator* it, |
| } |
| +MaybeHandle<Object> Object::WriteToReadOnlyElement(Isolate* isolate, |
| + Handle<Object> receiver, |
| + uint32_t index, |
| + Handle<Object> value, |
| + StrictMode strict_mode) { |
| + if (strict_mode != STRICT) return value; |
| + |
| + Handle<Object> args[] = {isolate->factory()->NewNumberFromUint(index), |
| + receiver}; |
| + THROW_NEW_ERROR(isolate, NewTypeError("strict_read_only_property", |
| + HandleVector(args, arraysize(args))), |
| + Object); |
| +} |
| + |
| + |
| Handle<Object> Object::SetDataProperty(LookupIterator* it, |
| Handle<Object> value) { |
| // Proxies are handled on the WithHandler path. Other non-JSObjects cannot |
| @@ -11865,13 +11973,10 @@ MaybeHandle<Object> JSObject::GetElementWithCallback( |
| } |
| -MaybeHandle<Object> JSObject::SetElementWithCallback(Handle<JSObject> object, |
| - Handle<Object> structure, |
| - uint32_t index, |
| - Handle<Object> value, |
| - Handle<JSObject> holder, |
| - StrictMode strict_mode) { |
| - Isolate* isolate = object->GetIsolate(); |
| +MaybeHandle<Object> JSObject::SetElementWithCallback( |
| + Handle<Object> object, Handle<Object> structure, uint32_t index, |
| + Handle<Object> value, Handle<JSObject> holder, StrictMode strict_mode) { |
| + Isolate* isolate = holder->GetIsolate(); |
| // We should never get here to initialize a const with the hole |
| // value since a const declaration would conflict with the setter. |
| @@ -11887,7 +11992,7 @@ MaybeHandle<Object> JSObject::SetElementWithCallback(Handle<JSObject> object, |
| if (call_fun == NULL) return value; |
| Handle<Object> number = isolate->factory()->NewNumberFromUint(index); |
| Handle<String> key(isolate->factory()->NumberToString(number)); |
| - LOG(isolate, ApiNamedPropertyAccess("store", *object, *key)); |
| + LOG(isolate, ApiNamedPropertyAccess("store", *holder, *key)); |
| PropertyCallbackArguments |
| args(isolate, data->data(), *object, *holder); |
| args.Call(call_fun, |