From: cbruni Date: Thu, 10 Sep 2015 10:56:06 +0000 (-0700) Subject: Adding template parameter to PrototypeIterator GetCurrent X-Git-Tag: upstream/4.7.83~364 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=aacaafd00b313d53ba6efb8caede5d0c188b7afd;p=platform%2Fupstream%2Fv8.git Adding template parameter to PrototypeIterator GetCurrent BUG= Review URL: https://codereview.chromium.org/1330153003 Cr-Commit-Position: refs/heads/master@{#30676} --- diff --git a/src/api.cc b/src/api.cc index 1cf5d52..4833c31 100644 --- a/src/api.cc +++ b/src/api.cc @@ -3702,8 +3702,7 @@ Local v8::Object::FindInstanceInPrototypeChain( return Local(); } } - return Utils::ToLocal( - i::handle(i::JSObject::cast(iter.GetCurrent()), isolate)); + return Utils::ToLocal(i::handle(iter.GetCurrent(), isolate)); } diff --git a/src/builtins.cc b/src/builtins.cc index f777f14..4ad6c21 100644 --- a/src/builtins.cc +++ b/src/builtins.cc @@ -215,7 +215,7 @@ inline bool PrototypeHasNoElements(PrototypeIterator* iter) { DisallowHeapAllocation no_gc; for (; !iter->IsAtEnd(); iter->Advance()) { if (iter->GetCurrent()->IsJSProxy()) return false; - JSObject* current = JSObject::cast(iter->GetCurrent()); + JSObject* current = iter->GetCurrent(); if (current->IsAccessCheckNeeded()) return false; if (current->HasIndexedInterceptor()) return false; if (current->elements()->length() != 0) return false; @@ -953,9 +953,8 @@ void CollectElementIndices(Handle object, uint32_t range, if (!iter.IsAtEnd()) { // The prototype will usually have no inherited element indices, // but we have to check. - CollectElementIndices( - Handle::cast(PrototypeIterator::GetCurrent(iter)), range, - indices); + CollectElementIndices(PrototypeIterator::GetCurrent(iter), range, + indices); } } diff --git a/src/debug/debug-evaluate.cc b/src/debug/debug-evaluate.cc index 10bc754..8d7635c 100644 --- a/src/debug/debug-evaluate.cc +++ b/src/debug/debug-evaluate.cc @@ -106,7 +106,7 @@ MaybeHandle DebugEvaluate::Evaluate( if (result->IsJSGlobalProxy()) { PrototypeIterator iter(isolate, result); // TODO(verwaest): This will crash when the global proxy is detached. - result = Handle::cast(PrototypeIterator::GetCurrent(iter)); + result = PrototypeIterator::GetCurrent(iter); } return result; diff --git a/src/hydrogen.cc b/src/hydrogen.cc index 337c35b..4d88303 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -7368,7 +7368,7 @@ HInstruction* HOptimizedGraphBuilder::BuildMonomorphicElementAccess( PrototypeIterator iter(map); JSObject* holder = NULL; while (!iter.IsAtEnd()) { - holder = JSObject::cast(*PrototypeIterator::GetCurrent(iter)); + holder = *PrototypeIterator::GetCurrent(iter); iter.Advance(); } DCHECK(holder && holder->IsJSObject()); @@ -7932,15 +7932,13 @@ HInstruction* HGraphBuilder::BuildCheckPrototypeMaps(Handle prototype, PrototypeIterator::START_AT_RECEIVER); while (holder.is_null() || !PrototypeIterator::GetCurrent(iter).is_identical_to(holder)) { - BuildConstantMapCheck( - Handle::cast(PrototypeIterator::GetCurrent(iter))); + BuildConstantMapCheck(PrototypeIterator::GetCurrent(iter)); iter.Advance(); if (iter.IsAtEnd()) { return NULL; } } - return BuildConstantMapCheck( - Handle::cast(PrototypeIterator::GetCurrent(iter))); + return BuildConstantMapCheck(PrototypeIterator::GetCurrent(iter)); } diff --git a/src/ic/handler-compiler.cc b/src/ic/handler-compiler.cc index a42fc69..c7f1f24 100644 --- a/src/ic/handler-compiler.cc +++ b/src/ic/handler-compiler.cc @@ -330,7 +330,7 @@ Handle NamedLoadHandlerCompiler::CompileLoadInterceptor( PrototypeIterator iter(isolate(), last); while (!iter.IsAtEnd()) { lost_holder_register = true; - last = JSObject::cast(iter.GetCurrent()); + last = iter.GetCurrent(); iter.Advance(); } auto last_handle = handle(last); @@ -436,7 +436,7 @@ Handle NamedStoreHandlerCompiler::CompileStoreTransition( : PrototypeIterator::END_AT_NULL; PrototypeIterator iter(isolate(), holder()); while (!iter.IsAtEnd(end)) { - last = Handle::cast(PrototypeIterator::GetCurrent(iter)); + last = PrototypeIterator::GetCurrent(iter); iter.Advance(); } if (!last.is_null()) set_holder(last); diff --git a/src/isolate.cc b/src/isolate.cc index 80024ca..b8b3c26 100644 --- a/src/isolate.cc +++ b/src/isolate.cc @@ -1348,7 +1348,7 @@ bool Isolate::IsErrorObject(Handle obj) { for (PrototypeIterator iter(this, *obj, PrototypeIterator::START_AT_RECEIVER); !iter.IsAtEnd(); iter.Advance()) { if (iter.GetCurrent()->IsJSProxy()) return false; - if (JSObject::cast(iter.GetCurrent())->map()->GetConstructor() == + if (iter.GetCurrent()->map()->GetConstructor() == *error_constructor) { return true; } diff --git a/src/lookup.cc b/src/lookup.cc index e9dc3d3..69b733e 100644 --- a/src/lookup.cc +++ b/src/lookup.cc @@ -94,7 +94,7 @@ Handle LookupIterator::GetStoreTarget() const { if (receiver_->IsJSGlobalProxy()) { PrototypeIterator iter(isolate(), receiver_); if (iter.IsAtEnd()) return Handle::cast(receiver_); - return Handle::cast(PrototypeIterator::GetCurrent(iter)); + return PrototypeIterator::GetCurrent(iter); } return Handle::cast(receiver_); } @@ -359,7 +359,7 @@ bool LookupIterator::InternalHolderIsReceiverOrHiddenPrototype() const { PrototypeIterator iter(isolate(), current, PrototypeIterator::START_AT_RECEIVER); do { - if (JSReceiver::cast(iter.GetCurrent()) == holder) return true; + if (iter.GetCurrent() == holder) return true; DCHECK(!current->IsJSProxy()); iter.Advance(); } while (!iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN)); diff --git a/src/objects.cc b/src/objects.cc index c91ed7c..2287dd9 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -5076,7 +5076,7 @@ Object* JSObject::GetHiddenProperty(Handle key) { // If the proxy is detached, return undefined. if (iter.IsAtEnd()) return GetHeap()->the_hole_value(); DCHECK(iter.GetCurrent()->IsJSGlobalObject()); - return JSObject::cast(iter.GetCurrent())->GetHiddenProperty(key); + return iter.GetCurrent()->GetHiddenProperty(key); } DCHECK(!IsJSGlobalProxy()); Object* inline_value = GetHiddenPropertiesHashTable(); @@ -5101,9 +5101,8 @@ Handle JSObject::SetHiddenProperty(Handle object, // If the proxy is detached, return undefined. if (iter.IsAtEnd()) return isolate->factory()->undefined_value(); DCHECK(PrototypeIterator::GetCurrent(iter)->IsJSGlobalObject()); - return SetHiddenProperty( - Handle::cast(PrototypeIterator::GetCurrent(iter)), key, - value); + return SetHiddenProperty(PrototypeIterator::GetCurrent(iter), key, + value); } DCHECK(!object->IsJSGlobalProxy()); @@ -5134,8 +5133,8 @@ void JSObject::DeleteHiddenProperty(Handle object, Handle key) { PrototypeIterator iter(isolate, object); if (iter.IsAtEnd()) return; DCHECK(PrototypeIterator::GetCurrent(iter)->IsJSGlobalObject()); - return DeleteHiddenProperty( - Handle::cast(PrototypeIterator::GetCurrent(iter)), key); + return DeleteHiddenProperty(PrototypeIterator::GetCurrent(iter), + key); } Object* inline_value = object->GetHiddenPropertiesHashTable(); @@ -5548,8 +5547,7 @@ MaybeHandle JSObject::PreventExtensions(Handle object) { PrototypeIterator iter(isolate, object); if (iter.IsAtEnd()) return object; DCHECK(PrototypeIterator::GetCurrent(iter)->IsJSGlobalObject()); - return PreventExtensions( - Handle::cast(PrototypeIterator::GetCurrent(iter))); + return PreventExtensions(PrototypeIterator::GetCurrent(iter)); } // It's not possible to seal objects with external array elements @@ -5591,7 +5589,7 @@ bool JSObject::IsExtensible() { PrototypeIterator iter(GetIsolate(), this); if (iter.IsAtEnd()) return false; DCHECK(iter.GetCurrent()->IsJSGlobalObject()); - return JSObject::cast(iter.GetCurrent())->map()->is_extensible(); + return iter.GetCurrent()->map()->is_extensible(); } return map()->is_extensible(); } @@ -5642,7 +5640,7 @@ MaybeHandle JSObject::PreventExtensionsWithTransition( if (iter.IsAtEnd()) return object; DCHECK(PrototypeIterator::GetCurrent(iter)->IsJSGlobalObject()); return PreventExtensionsWithTransition( - Handle::cast(PrototypeIterator::GetCurrent(iter))); + PrototypeIterator::GetCurrent(iter)); } // It's not possible to seal or freeze objects with external array elements @@ -6097,14 +6095,14 @@ bool JSReceiver::IsSimpleEnum() { PrototypeIterator::START_AT_RECEIVER); !iter.IsAtEnd(); iter.Advance()) { if (!iter.GetCurrent()->IsJSObject()) return false; - JSObject* curr = JSObject::cast(iter.GetCurrent()); - int enum_length = curr->map()->EnumLength(); + JSObject* current = iter.GetCurrent(); + int enum_length = current->map()->EnumLength(); if (enum_length == kInvalidEnumCacheSentinel) return false; - if (curr->IsAccessCheckNeeded()) return false; - DCHECK(!curr->HasNamedInterceptor()); - DCHECK(!curr->HasIndexedInterceptor()); - if (curr->NumberOfEnumElements() > 0) return false; - if (curr != this && enum_length != 0) return false; + if (current->IsAccessCheckNeeded()) return false; + DCHECK(!current->HasNamedInterceptor()); + DCHECK(!current->HasIndexedInterceptor()); + if (current->NumberOfEnumElements() > 0) return false; + if (current != this && enum_length != 0) return false; } return true; } @@ -6305,8 +6303,7 @@ MaybeHandle JSReceiver::GetKeys(Handle object, PrototypeIterator::START_AT_RECEIVER); !iter.IsAtEnd(end); iter.Advance()) { if (PrototypeIterator::GetCurrent(iter)->IsJSProxy()) { - Handle proxy(JSProxy::cast(*PrototypeIterator::GetCurrent(iter)), - isolate); + Handle proxy = PrototypeIterator::GetCurrent(iter); Handle args[] = { proxy }; Handle names; ASSIGN_RETURN_ON_EXCEPTION( @@ -6325,8 +6322,7 @@ MaybeHandle JSReceiver::GetKeys(Handle object, break; } - Handle current = - Handle::cast(PrototypeIterator::GetCurrent(iter)); + Handle current = PrototypeIterator::GetCurrent(iter); // Check access rights if required. if (current->IsAccessCheckNeeded() && !isolate->MayAccess(current)) { @@ -6409,7 +6405,7 @@ bool Map::DictionaryElementsInPrototypeChainOnly() { if (iter.GetCurrent()->IsJSProxy()) return true; // String wrappers have non-configurable, non-writable elements. if (iter.GetCurrent()->IsStringWrapper()) return true; - JSObject* current = JSObject::cast(iter.GetCurrent()); + JSObject* current = iter.GetCurrent(); if (current->HasDictionaryElements() && current->element_dictionary()->requires_slow_elements()) { @@ -9968,7 +9964,7 @@ bool JSObject::UnregisterPrototypeUser(Handle user, Isolate* isolate) { if (slot == PrototypeInfo::UNREGISTERED) return false; if (prototype->IsJSGlobalProxy()) { PrototypeIterator iter(isolate, prototype); - prototype = Handle::cast(PrototypeIterator::GetCurrent(iter)); + prototype = PrototypeIterator::GetCurrent(iter); } DCHECK(prototype->map()->is_prototype_map()); Object* maybe_proto_info = prototype->map()->prototype_info(); @@ -10020,7 +10016,7 @@ void JSObject::InvalidatePrototypeChains(Map* map) { DisallowHeapAllocation no_gc; if (map->IsJSGlobalProxyMap()) { PrototypeIterator iter(map); - map = JSObject::cast(iter.GetCurrent())->map(); + map = iter.GetCurrent()->map(); } InvalidatePrototypeChainsInternal(map); } @@ -10060,7 +10056,7 @@ Handle Map::GetOrCreatePrototypeChainValidityCell(Handle map, Handle prototype = Handle::cast(maybe_prototype); if (prototype->IsJSGlobalProxy()) { PrototypeIterator iter(isolate, prototype); - prototype = Handle::cast(PrototypeIterator::GetCurrent(iter)); + prototype = PrototypeIterator::GetCurrent(iter); } // Ensure the prototype is registered with its own prototypes so its cell // will be invalidated when necessary. @@ -12391,7 +12387,7 @@ MaybeHandle JSObject::SetPrototype(Handle object, for (PrototypeIterator iter(isolate, *value, PrototypeIterator::START_AT_RECEIVER); !iter.IsAtEnd(); iter.Advance()) { - if (JSReceiver::cast(iter.GetCurrent()) == *object) { + if (iter.GetCurrent() == *object) { // Cycle detected. THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kCyclicProto), Object); @@ -12407,8 +12403,7 @@ MaybeHandle JSObject::SetPrototype(Handle object, // hidden and set the new prototype on that object. PrototypeIterator iter(isolate, real_receiver); while (!iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN)) { - real_receiver = - Handle::cast(PrototypeIterator::GetCurrent(iter)); + real_receiver = PrototypeIterator::GetCurrent(iter); iter.Advance(); if (!real_receiver->map()->is_extensible()) { THROW_NEW_ERROR( diff --git a/src/prototype.h b/src/prototype.h index 4df1114..0727749 100644 --- a/src/prototype.h +++ b/src/prototype.h @@ -39,6 +39,7 @@ class PrototypeIterator { Advance(); } } + PrototypeIterator(Isolate* isolate, Object* receiver, WhereToStart where_to_start = START_AT_PROTOTYPE) : did_jump_to_prototype_chain_(false), @@ -48,25 +49,32 @@ class PrototypeIterator { Advance(); } } + explicit PrototypeIterator(Map* receiver_map) : did_jump_to_prototype_chain_(true), object_(receiver_map->prototype()), isolate_(receiver_map->GetIsolate()) {} + explicit PrototypeIterator(Handle receiver_map) : did_jump_to_prototype_chain_(true), object_(NULL), handle_(handle(receiver_map->prototype(), receiver_map->GetIsolate())), isolate_(receiver_map->GetIsolate()) {} + ~PrototypeIterator() {} - Object* GetCurrent() const { + template + T* GetCurrent() const { DCHECK(handle_.is_null()); - return object_; + return T::cast(object_); } - static Handle GetCurrent(const PrototypeIterator& iterator) { + + template + static Handle GetCurrent(const PrototypeIterator& iterator) { DCHECK(!iterator.handle_.is_null()); - return iterator.handle_; + return Handle::cast(iterator.handle_); } + void Advance() { if (handle_.is_null() && object_->IsJSProxy()) { did_jump_to_prototype_chain_ = true; @@ -79,6 +87,7 @@ class PrototypeIterator { } AdvanceIgnoringProxies(); } + void AdvanceIgnoringProxies() { if (!did_jump_to_prototype_chain_) { did_jump_to_prototype_chain_ = true; @@ -96,6 +105,7 @@ class PrototypeIterator { } } } + bool IsAtEnd(WhereToEnd where_to_end = END_AT_NULL) const { if (handle_.is_null()) { return object_->IsNull() || @@ -109,10 +119,12 @@ class PrototypeIterator { !Handle::cast(handle_)->map()->is_hidden_prototype()); } } + bool IsAtEnd(Object* final_object) { DCHECK(handle_.is_null()); return object_->IsNull() || object_ == final_object; } + bool IsAtEnd(Handle final_object) { DCHECK(!handle_.is_null()); return handle_->IsNull() || *handle_ == *final_object; diff --git a/src/runtime/runtime-array.cc b/src/runtime/runtime-array.cc index 4b41bd8..721f291 100644 --- a/src/runtime/runtime-array.cc +++ b/src/runtime/runtime-array.cc @@ -203,14 +203,13 @@ RUNTIME_FUNCTION(Runtime_GetArrayKeys) { PrototypeIterator::START_AT_RECEIVER); !iter.IsAtEnd(); iter.Advance()) { if (PrototypeIterator::GetCurrent(iter)->IsJSProxy() || - JSObject::cast(*PrototypeIterator::GetCurrent(iter)) + PrototypeIterator::GetCurrent(iter) ->HasIndexedInterceptor()) { // Bail out if we find a proxy or interceptor, likely not worth // collecting keys in that case. return *isolate->factory()->NewNumberFromUint(length); } - Handle current = - Handle::cast(PrototypeIterator::GetCurrent(iter)); + Handle current = PrototypeIterator::GetCurrent(iter); Handle current_keys = isolate->factory()->NewFixedArray(current->NumberOfOwnElements(NONE)); current->GetOwnElementKeys(*current_keys, NONE); @@ -454,8 +453,7 @@ RUNTIME_FUNCTION(Runtime_HasComplexElements) { if (PrototypeIterator::GetCurrent(iter)->IsJSProxy()) { return isolate->heap()->true_value(); } - Handle current = - Handle::cast(PrototypeIterator::GetCurrent(iter)); + Handle current = PrototypeIterator::GetCurrent(iter); if (current->HasIndexedInterceptor()) { return isolate->heap()->true_value(); } diff --git a/src/runtime/runtime-object.cc b/src/runtime/runtime-object.cc index b475e56..9ffb250 100644 --- a/src/runtime/runtime-object.cc +++ b/src/runtime/runtime-object.cc @@ -186,8 +186,7 @@ RUNTIME_FUNCTION(Runtime_GetPrototype) { PrototypeIterator iter(isolate, obj, PrototypeIterator::START_AT_RECEIVER); do { if (PrototypeIterator::GetCurrent(iter)->IsAccessCheckNeeded() && - !isolate->MayAccess( - Handle::cast(PrototypeIterator::GetCurrent(iter)))) { + !isolate->MayAccess(PrototypeIterator::GetCurrent(iter))) { return isolate->heap()->null_value(); } iter.AdvanceIgnoringProxies(); diff --git a/src/string-stream.cc b/src/string-stream.cc index 92fff27..2801d23 100644 --- a/src/string-stream.cc +++ b/src/string-stream.cc @@ -531,7 +531,7 @@ void StringStream::PrintPrototype(JSFunction* fun, Object* receiver) { PrototypeIterator::START_AT_RECEIVER); !iter.IsAtEnd(); iter.Advance()) { if (iter.GetCurrent()->IsJSObject()) { - Object* key = JSObject::cast(iter.GetCurrent())->SlowReverseLookup(fun); + Object* key = iter.GetCurrent()->SlowReverseLookup(fun); if (key != isolate->heap()->undefined_value()) { if (!name->IsString() || !key->IsString() ||