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

Unified Diff: src/objects.cc

Issue 1238533003: Use the LookupIterator to transition to elements accessors (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Disallow defining accessors on typed arrays Created 5 years, 5 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/element-accessor.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 dfe7fce5ec39eae45531ca20f44f1efe4831b76b..850b6ff49f1a0e31222d599cd7172c2f718fef71 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -6238,100 +6238,6 @@ MaybeHandle<FixedArray> JSReceiver::GetKeys(Handle<JSReceiver> object,
}
-// Try to update an accessor in an elements dictionary. Return true if the
-// update succeeded, and false otherwise.
-static bool UpdateGetterSetterInDictionary(
- SeededNumberDictionary* dictionary,
- uint32_t index,
- Object* getter,
- Object* setter,
- PropertyAttributes attributes) {
- int entry = dictionary->FindEntry(index);
- if (entry != SeededNumberDictionary::kNotFound) {
- Object* result = dictionary->ValueAt(entry);
- PropertyDetails details = dictionary->DetailsAt(entry);
- if (details.type() == ACCESSOR_CONSTANT && result->IsAccessorPair()) {
- DCHECK(details.IsConfigurable());
- if (details.attributes() != attributes) {
- dictionary->DetailsAtPut(
- entry, PropertyDetails(attributes, ACCESSOR_CONSTANT, index,
- PropertyCellType::kNoCell));
- }
- AccessorPair::cast(result)->SetComponents(getter, setter);
- return true;
- }
- }
- return false;
-}
-
-
-void JSObject::DefineElementAccessor(Handle<JSObject> object,
- uint32_t index,
- Handle<Object> getter,
- Handle<Object> setter,
- PropertyAttributes attributes) {
- switch (object->GetElementsKind()) {
- case FAST_SMI_ELEMENTS:
- case FAST_ELEMENTS:
- case FAST_DOUBLE_ELEMENTS:
- case FAST_HOLEY_SMI_ELEMENTS:
- case FAST_HOLEY_ELEMENTS:
- case FAST_HOLEY_DOUBLE_ELEMENTS:
- break;
-
-#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
- case EXTERNAL_##TYPE##_ELEMENTS: \
- case TYPE##_ELEMENTS: \
-
- TYPED_ARRAYS(TYPED_ARRAY_CASE)
-#undef TYPED_ARRAY_CASE
- // Ignore getters and setters on pixel and external array elements.
- return;
-
- case DICTIONARY_ELEMENTS:
- if (UpdateGetterSetterInDictionary(object->element_dictionary(),
- index,
- *getter,
- *setter,
- attributes)) {
- return;
- }
- break;
- case FAST_SLOPPY_ARGUMENTS_ELEMENTS:
- case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: {
- // Ascertain whether we have read-only properties or an existing
- // getter/setter pair in an arguments elements dictionary backing
- // store.
- FixedArray* parameter_map = FixedArray::cast(object->elements());
- uint32_t length = parameter_map->length();
- Object* probe =
- index < (length - 2) ? parameter_map->get(index + 2) : NULL;
- if (probe == NULL || probe->IsTheHole()) {
- FixedArray* arguments = FixedArray::cast(parameter_map->get(1));
- if (arguments->IsDictionary()) {
- SeededNumberDictionary* dictionary =
- SeededNumberDictionary::cast(arguments);
- if (UpdateGetterSetterInDictionary(dictionary,
- index,
- *getter,
- *setter,
- attributes)) {
- return;
- }
- }
- }
- break;
- }
- }
-
- Isolate* isolate = object->GetIsolate();
- Handle<AccessorPair> accessors = isolate->factory()->NewAccessorPair();
- accessors->SetComponents(*getter, *setter);
-
- SetElementCallback(object, index, accessors, attributes);
-}
-
-
bool Map::DictionaryElementsInPrototypeChainOnly() {
if (IsDictionaryElementsKind(elements_kind())) {
return false;
@@ -6439,6 +6345,12 @@ MaybeHandle<Object> JSObject::DefineAccessor(Handle<JSObject> object,
it.Next();
}
+ // Ignore accessors on typed arrays.
+ if (it.IsElement() && (object->HasFixedTypedArrayElements() ||
+ object->HasExternalArrayElements())) {
+ return it.factory()->undefined_value();
+ }
+
Handle<Object> old_value = isolate->factory()->the_hole_value();
bool is_observed = object->map()->is_observed() &&
!isolate->IsInternallyUsedPropertyName(name);
@@ -6452,22 +6364,15 @@ MaybeHandle<Object> JSObject::DefineAccessor(Handle<JSObject> object,
}
}
- if (it.IsElement()) {
- DefineElementAccessor(it.GetStoreTarget(), it.index(), getter, setter,
- attributes);
- } else {
- DCHECK(getter->IsSpecFunction() || getter->IsUndefined() ||
- getter->IsNull());
- DCHECK(setter->IsSpecFunction() || setter->IsUndefined() ||
- setter->IsNull());
- // At least one of the accessors needs to be a new value.
- DCHECK(!getter->IsNull() || !setter->IsNull());
- if (!getter->IsNull()) {
- it.TransitionToAccessorProperty(ACCESSOR_GETTER, getter, attributes);
- }
- if (!setter->IsNull()) {
- it.TransitionToAccessorProperty(ACCESSOR_SETTER, setter, attributes);
- }
+ DCHECK(getter->IsSpecFunction() || getter->IsUndefined() || getter->IsNull());
+ DCHECK(setter->IsSpecFunction() || setter->IsUndefined() || setter->IsNull());
+ // At least one of the accessors needs to be a new value.
+ DCHECK(!getter->IsNull() || !setter->IsNull());
+ if (!getter->IsNull()) {
+ it.TransitionToAccessorProperty(ACCESSOR_GETTER, getter, attributes);
+ }
+ if (!setter->IsNull()) {
+ it.TransitionToAccessorProperty(ACCESSOR_SETTER, setter, attributes);
}
if (is_observed) {
« no previous file with comments | « src/objects.h ('k') | test/mjsunit/element-accessor.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698