Remove code duplication in JSObject::HasRealElementProperty
Review URL: https://codereview.chromium.org/13540003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14144 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
af25102f41
commit
759f4b37ce
@ -3352,15 +3352,16 @@ bool v8::Object::HasRealNamedProperty(Handle<String> key) {
|
||||
ON_BAILOUT(isolate, "v8::Object::HasRealNamedProperty()",
|
||||
return false);
|
||||
return Utils::OpenHandle(this)->HasRealNamedProperty(
|
||||
isolate,
|
||||
*Utils::OpenHandle(*key));
|
||||
}
|
||||
|
||||
|
||||
bool v8::Object::HasRealIndexedProperty(uint32_t index) {
|
||||
ON_BAILOUT(Utils::OpenHandle(this)->GetIsolate(),
|
||||
"v8::Object::HasRealIndexedProperty()",
|
||||
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
|
||||
ON_BAILOUT(isolate, "v8::Object::HasRealIndexedProperty()",
|
||||
return false);
|
||||
return Utils::OpenHandle(this)->HasRealElementProperty(index);
|
||||
return Utils::OpenHandle(this)->HasRealElementProperty(isolate, index);
|
||||
}
|
||||
|
||||
|
||||
@ -3371,6 +3372,7 @@ bool v8::Object::HasRealNamedCallbackProperty(Handle<String> key) {
|
||||
return false);
|
||||
ENTER_V8(isolate);
|
||||
return Utils::OpenHandle(this)->HasRealNamedCallbackProperty(
|
||||
isolate,
|
||||
*Utils::OpenHandle(*key));
|
||||
}
|
||||
|
||||
|
@ -11545,9 +11545,8 @@ MaybeObject* JSObject::GetPropertyWithInterceptor(
|
||||
}
|
||||
|
||||
|
||||
bool JSObject::HasRealNamedProperty(Name* key) {
|
||||
bool JSObject::HasRealNamedProperty(Isolate* isolate, Name* key) {
|
||||
// Check access rights if needed.
|
||||
Isolate* isolate = GetIsolate();
|
||||
if (IsAccessCheckNeeded()) {
|
||||
if (!isolate->MayNamedAccess(this, key, v8::ACCESS_HAS)) {
|
||||
isolate->ReportFailedAccessCheck(this, v8::ACCESS_HAS);
|
||||
@ -11561,73 +11560,21 @@ bool JSObject::HasRealNamedProperty(Name* key) {
|
||||
}
|
||||
|
||||
|
||||
bool JSObject::HasRealElementProperty(uint32_t index) {
|
||||
bool JSObject::HasRealElementProperty(Isolate* isolate, uint32_t index) {
|
||||
// Check access rights if needed.
|
||||
if (IsAccessCheckNeeded()) {
|
||||
Heap* heap = GetHeap();
|
||||
if (!heap->isolate()->MayIndexedAccess(this, index, v8::ACCESS_HAS)) {
|
||||
heap->isolate()->ReportFailedAccessCheck(this, v8::ACCESS_HAS);
|
||||
if (!isolate->MayIndexedAccess(this, index, v8::ACCESS_HAS)) {
|
||||
isolate->ReportFailedAccessCheck(this, v8::ACCESS_HAS);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle [] on String objects.
|
||||
if (this->IsStringObjectWithCharacterAt(index)) return true;
|
||||
|
||||
switch (GetElementsKind()) {
|
||||
case FAST_SMI_ELEMENTS:
|
||||
case FAST_ELEMENTS:
|
||||
case FAST_HOLEY_SMI_ELEMENTS:
|
||||
case FAST_HOLEY_ELEMENTS: {
|
||||
uint32_t length = IsJSArray() ?
|
||||
static_cast<uint32_t>(
|
||||
Smi::cast(JSArray::cast(this)->length())->value()) :
|
||||
static_cast<uint32_t>(FixedArray::cast(elements())->length());
|
||||
return (index < length) &&
|
||||
!FixedArray::cast(elements())->get(index)->IsTheHole();
|
||||
}
|
||||
case FAST_DOUBLE_ELEMENTS:
|
||||
case FAST_HOLEY_DOUBLE_ELEMENTS: {
|
||||
uint32_t length = IsJSArray() ?
|
||||
static_cast<uint32_t>(
|
||||
Smi::cast(JSArray::cast(this)->length())->value()) :
|
||||
static_cast<uint32_t>(FixedDoubleArray::cast(elements())->length());
|
||||
return (index < length) &&
|
||||
!FixedDoubleArray::cast(elements())->is_the_hole(index);
|
||||
break;
|
||||
}
|
||||
case EXTERNAL_PIXEL_ELEMENTS: {
|
||||
ExternalPixelArray* pixels = ExternalPixelArray::cast(elements());
|
||||
return index < static_cast<uint32_t>(pixels->length());
|
||||
}
|
||||
case EXTERNAL_BYTE_ELEMENTS:
|
||||
case EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
|
||||
case EXTERNAL_SHORT_ELEMENTS:
|
||||
case EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
|
||||
case EXTERNAL_INT_ELEMENTS:
|
||||
case EXTERNAL_UNSIGNED_INT_ELEMENTS:
|
||||
case EXTERNAL_FLOAT_ELEMENTS:
|
||||
case EXTERNAL_DOUBLE_ELEMENTS: {
|
||||
ExternalArray* array = ExternalArray::cast(elements());
|
||||
return index < static_cast<uint32_t>(array->length());
|
||||
}
|
||||
case DICTIONARY_ELEMENTS: {
|
||||
return element_dictionary()->FindEntry(index)
|
||||
!= SeededNumberDictionary::kNotFound;
|
||||
}
|
||||
case NON_STRICT_ARGUMENTS_ELEMENTS:
|
||||
UNIMPLEMENTED();
|
||||
break;
|
||||
}
|
||||
// All possibilities have been handled above already.
|
||||
UNREACHABLE();
|
||||
return GetHeap()->null_value();
|
||||
return GetElementAttributeWithoutInterceptor(this, index, false) != ABSENT;
|
||||
}
|
||||
|
||||
|
||||
bool JSObject::HasRealNamedCallbackProperty(Name* key) {
|
||||
bool JSObject::HasRealNamedCallbackProperty(Isolate* isolate, Name* key) {
|
||||
// Check access rights if needed.
|
||||
Isolate* isolate = GetIsolate();
|
||||
if (IsAccessCheckNeeded()) {
|
||||
if (!isolate->MayNamedAccess(this, key, v8::ACCESS_HAS)) {
|
||||
isolate->ReportFailedAccessCheck(this, v8::ACCESS_HAS);
|
||||
|
@ -2034,9 +2034,9 @@ class JSObject: public JSReceiver {
|
||||
inline bool HasIndexedInterceptor();
|
||||
|
||||
// Support functions for v8 api (needed for correct interceptor behavior).
|
||||
bool HasRealNamedProperty(Name* key);
|
||||
bool HasRealElementProperty(uint32_t index);
|
||||
bool HasRealNamedCallbackProperty(Name* key);
|
||||
bool HasRealNamedProperty(Isolate* isolate, Name* key);
|
||||
bool HasRealElementProperty(Isolate* isolate, uint32_t index);
|
||||
bool HasRealNamedCallbackProperty(Isolate* isolate, Name* key);
|
||||
|
||||
// Get the header size for a JSObject. Used to compute the index of
|
||||
// internal fields as well as the number of internal fields.
|
||||
|
@ -4629,7 +4629,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_HasLocalProperty) {
|
||||
// Fast case: either the key is a real named property or it is not
|
||||
// an array index and there are no interceptors or hidden
|
||||
// prototypes.
|
||||
if (object->HasRealNamedProperty(key)) return isolate->heap()->true_value();
|
||||
if (object->HasRealNamedProperty(isolate, key))
|
||||
return isolate->heap()->true_value();
|
||||
Map* map = object->map();
|
||||
if (!key_is_array_index &&
|
||||
!map->has_named_interceptor() &&
|
||||
|
Loading…
Reference in New Issue
Block a user