return Local<Object>();
}
}
- return Utils::ToLocal(
- i::handle(i::JSObject::cast(iter.GetCurrent()), isolate));
+ return Utils::ToLocal(i::handle(iter.GetCurrent<i::JSObject>(), isolate));
}
DisallowHeapAllocation no_gc;
for (; !iter->IsAtEnd(); iter->Advance()) {
if (iter->GetCurrent()->IsJSProxy()) return false;
- JSObject* current = JSObject::cast(iter->GetCurrent());
+ JSObject* current = iter->GetCurrent<JSObject>();
if (current->IsAccessCheckNeeded()) return false;
if (current->HasIndexedInterceptor()) return false;
if (current->elements()->length() != 0) return false;
if (!iter.IsAtEnd()) {
// The prototype will usually have no inherited element indices,
// but we have to check.
- CollectElementIndices(
- Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)), range,
- indices);
+ CollectElementIndices(PrototypeIterator::GetCurrent<JSObject>(iter), range,
+ indices);
}
}
if (result->IsJSGlobalProxy()) {
PrototypeIterator iter(isolate, result);
// TODO(verwaest): This will crash when the global proxy is detached.
- result = Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter));
+ result = PrototypeIterator::GetCurrent<JSObject>(iter);
}
return result;
PrototypeIterator iter(map);
JSObject* holder = NULL;
while (!iter.IsAtEnd()) {
- holder = JSObject::cast(*PrototypeIterator::GetCurrent(iter));
+ holder = *PrototypeIterator::GetCurrent<JSObject>(iter);
iter.Advance();
}
DCHECK(holder && holder->IsJSObject());
PrototypeIterator::START_AT_RECEIVER);
while (holder.is_null() ||
!PrototypeIterator::GetCurrent(iter).is_identical_to(holder)) {
- BuildConstantMapCheck(
- Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)));
+ BuildConstantMapCheck(PrototypeIterator::GetCurrent<JSObject>(iter));
iter.Advance();
if (iter.IsAtEnd()) {
return NULL;
}
}
- return BuildConstantMapCheck(
- Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)));
+ return BuildConstantMapCheck(PrototypeIterator::GetCurrent<JSObject>(iter));
}
PrototypeIterator iter(isolate(), last);
while (!iter.IsAtEnd()) {
lost_holder_register = true;
- last = JSObject::cast(iter.GetCurrent());
+ last = iter.GetCurrent<JSObject>();
iter.Advance();
}
auto last_handle = handle(last);
: PrototypeIterator::END_AT_NULL;
PrototypeIterator iter(isolate(), holder());
while (!iter.IsAtEnd(end)) {
- last = Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter));
+ last = PrototypeIterator::GetCurrent<JSObject>(iter);
iter.Advance();
}
if (!last.is_null()) set_holder(last);
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<JSObject>()->map()->GetConstructor() ==
*error_constructor) {
return true;
}
if (receiver_->IsJSGlobalProxy()) {
PrototypeIterator iter(isolate(), receiver_);
if (iter.IsAtEnd()) return Handle<JSGlobalProxy>::cast(receiver_);
- return Handle<JSGlobalObject>::cast(PrototypeIterator::GetCurrent(iter));
+ return PrototypeIterator::GetCurrent<JSGlobalObject>(iter);
}
return Handle<JSObject>::cast(receiver_);
}
PrototypeIterator iter(isolate(), current,
PrototypeIterator::START_AT_RECEIVER);
do {
- if (JSReceiver::cast(iter.GetCurrent()) == holder) return true;
+ if (iter.GetCurrent<JSReceiver>() == holder) return true;
DCHECK(!current->IsJSProxy());
iter.Advance();
} while (!iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN));
// 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<JSObject>()->GetHiddenProperty(key);
}
DCHECK(!IsJSGlobalProxy());
Object* inline_value = GetHiddenPropertiesHashTable();
// If the proxy is detached, return undefined.
if (iter.IsAtEnd()) return isolate->factory()->undefined_value();
DCHECK(PrototypeIterator::GetCurrent(iter)->IsJSGlobalObject());
- return SetHiddenProperty(
- Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)), key,
- value);
+ return SetHiddenProperty(PrototypeIterator::GetCurrent<JSObject>(iter), key,
+ value);
}
DCHECK(!object->IsJSGlobalProxy());
PrototypeIterator iter(isolate, object);
if (iter.IsAtEnd()) return;
DCHECK(PrototypeIterator::GetCurrent(iter)->IsJSGlobalObject());
- return DeleteHiddenProperty(
- Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)), key);
+ return DeleteHiddenProperty(PrototypeIterator::GetCurrent<JSObject>(iter),
+ key);
}
Object* inline_value = object->GetHiddenPropertiesHashTable();
PrototypeIterator iter(isolate, object);
if (iter.IsAtEnd()) return object;
DCHECK(PrototypeIterator::GetCurrent(iter)->IsJSGlobalObject());
- return PreventExtensions(
- Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)));
+ return PreventExtensions(PrototypeIterator::GetCurrent<JSObject>(iter));
}
// It's not possible to seal objects with external array elements
PrototypeIterator iter(GetIsolate(), this);
if (iter.IsAtEnd()) return false;
DCHECK(iter.GetCurrent()->IsJSGlobalObject());
- return JSObject::cast(iter.GetCurrent())->map()->is_extensible();
+ return iter.GetCurrent<JSObject>()->map()->is_extensible();
}
return map()->is_extensible();
}
if (iter.IsAtEnd()) return object;
DCHECK(PrototypeIterator::GetCurrent(iter)->IsJSGlobalObject());
return PreventExtensionsWithTransition<attrs>(
- Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)));
+ PrototypeIterator::GetCurrent<JSObject>(iter));
}
// It's not possible to seal or freeze objects with external array elements
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<JSObject>();
+ 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;
}
PrototypeIterator::START_AT_RECEIVER);
!iter.IsAtEnd(end); iter.Advance()) {
if (PrototypeIterator::GetCurrent(iter)->IsJSProxy()) {
- Handle<JSProxy> proxy(JSProxy::cast(*PrototypeIterator::GetCurrent(iter)),
- isolate);
+ Handle<JSProxy> proxy = PrototypeIterator::GetCurrent<JSProxy>(iter);
Handle<Object> args[] = { proxy };
Handle<Object> names;
ASSIGN_RETURN_ON_EXCEPTION(
break;
}
- Handle<JSObject> current =
- Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter));
+ Handle<JSObject> current = PrototypeIterator::GetCurrent<JSObject>(iter);
// Check access rights if required.
if (current->IsAccessCheckNeeded() && !isolate->MayAccess(current)) {
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<JSObject>();
if (current->HasDictionaryElements() &&
current->element_dictionary()->requires_slow_elements()) {
if (slot == PrototypeInfo::UNREGISTERED) return false;
if (prototype->IsJSGlobalProxy()) {
PrototypeIterator iter(isolate, prototype);
- prototype = Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter));
+ prototype = PrototypeIterator::GetCurrent<JSObject>(iter);
}
DCHECK(prototype->map()->is_prototype_map());
Object* maybe_proto_info = prototype->map()->prototype_info();
DisallowHeapAllocation no_gc;
if (map->IsJSGlobalProxyMap()) {
PrototypeIterator iter(map);
- map = JSObject::cast(iter.GetCurrent())->map();
+ map = iter.GetCurrent<JSObject>()->map();
}
InvalidatePrototypeChainsInternal(map);
}
Handle<JSObject> prototype = Handle<JSObject>::cast(maybe_prototype);
if (prototype->IsJSGlobalProxy()) {
PrototypeIterator iter(isolate, prototype);
- prototype = Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter));
+ prototype = PrototypeIterator::GetCurrent<JSObject>(iter);
}
// Ensure the prototype is registered with its own prototypes so its cell
// will be invalidated when necessary.
for (PrototypeIterator iter(isolate, *value,
PrototypeIterator::START_AT_RECEIVER);
!iter.IsAtEnd(); iter.Advance()) {
- if (JSReceiver::cast(iter.GetCurrent()) == *object) {
+ if (iter.GetCurrent<JSReceiver>() == *object) {
// Cycle detected.
THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kCyclicProto),
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<JSObject>::cast(PrototypeIterator::GetCurrent(iter));
+ real_receiver = PrototypeIterator::GetCurrent<JSObject>(iter);
iter.Advance();
if (!real_receiver->map()->is_extensible()) {
THROW_NEW_ERROR(
Advance();
}
}
+
PrototypeIterator(Isolate* isolate, Object* receiver,
WhereToStart where_to_start = START_AT_PROTOTYPE)
: did_jump_to_prototype_chain_(false),
Advance();
}
}
+
explicit PrototypeIterator(Map* receiver_map)
: did_jump_to_prototype_chain_(true),
object_(receiver_map->prototype()),
isolate_(receiver_map->GetIsolate()) {}
+
explicit PrototypeIterator(Handle<Map> 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 <typename T = Object>
+ T* GetCurrent() const {
DCHECK(handle_.is_null());
- return object_;
+ return T::cast(object_);
}
- static Handle<Object> GetCurrent(const PrototypeIterator& iterator) {
+
+ template <typename T = Object>
+ static Handle<T> GetCurrent(const PrototypeIterator& iterator) {
DCHECK(!iterator.handle_.is_null());
- return iterator.handle_;
+ return Handle<T>::cast(iterator.handle_);
}
+
void Advance() {
if (handle_.is_null() && object_->IsJSProxy()) {
did_jump_to_prototype_chain_ = true;
}
AdvanceIgnoringProxies();
}
+
void AdvanceIgnoringProxies() {
if (!did_jump_to_prototype_chain_) {
did_jump_to_prototype_chain_ = true;
}
}
}
+
bool IsAtEnd(WhereToEnd where_to_end = END_AT_NULL) const {
if (handle_.is_null()) {
return object_->IsNull() ||
!Handle<HeapObject>::cast(handle_)->map()->is_hidden_prototype());
}
}
+
bool IsAtEnd(Object* final_object) {
DCHECK(handle_.is_null());
return object_->IsNull() || object_ == final_object;
}
+
bool IsAtEnd(Handle<Object> final_object) {
DCHECK(!handle_.is_null());
return handle_->IsNull() || *handle_ == *final_object;
PrototypeIterator::START_AT_RECEIVER);
!iter.IsAtEnd(); iter.Advance()) {
if (PrototypeIterator::GetCurrent(iter)->IsJSProxy() ||
- JSObject::cast(*PrototypeIterator::GetCurrent(iter))
+ PrototypeIterator::GetCurrent<JSObject>(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<JSObject> current =
- Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter));
+ Handle<JSObject> current = PrototypeIterator::GetCurrent<JSObject>(iter);
Handle<FixedArray> current_keys =
isolate->factory()->NewFixedArray(current->NumberOfOwnElements(NONE));
current->GetOwnElementKeys(*current_keys, NONE);
if (PrototypeIterator::GetCurrent(iter)->IsJSProxy()) {
return isolate->heap()->true_value();
}
- Handle<JSObject> current =
- Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter));
+ Handle<JSObject> current = PrototypeIterator::GetCurrent<JSObject>(iter);
if (current->HasIndexedInterceptor()) {
return isolate->heap()->true_value();
}
PrototypeIterator iter(isolate, obj, PrototypeIterator::START_AT_RECEIVER);
do {
if (PrototypeIterator::GetCurrent(iter)->IsAccessCheckNeeded() &&
- !isolate->MayAccess(
- Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter)))) {
+ !isolate->MayAccess(PrototypeIterator::GetCurrent<JSObject>(iter))) {
return isolate->heap()->null_value();
}
iter.AdvanceIgnoringProxies();
PrototypeIterator::START_AT_RECEIVER);
!iter.IsAtEnd(); iter.Advance()) {
if (iter.GetCurrent()->IsJSObject()) {
- Object* key = JSObject::cast(iter.GetCurrent())->SlowReverseLookup(fun);
+ Object* key = iter.GetCurrent<JSObject>()->SlowReverseLookup(fun);
if (key != isolate->heap()->undefined_value()) {
if (!name->IsString() ||
!key->IsString() ||