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

Unified Diff: src/prototype.h

Issue 1330153003: Adding template parameter to PrototypeIterator GetCurrent for casting (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 3 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
Index: src/prototype.h
diff --git a/src/prototype.h b/src/prototype.h
index 4df1114c7705780ef2a97ae677b734857c9dbf90..75569dc827719acf9df91f19b295ef7e5fd1cb78 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,37 @@ 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<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) {
Jakob Kummerow 2015/09/09 14:29:55 Why do we still need this?
Camillo Bruni 2015/09/10 10:53:59 removed
DCHECK(!iterator.handle_.is_null());
return iterator.handle_;
}
+
+ template <typename T>
+ static Handle<T> GetCurrent(const PrototypeIterator& iterator) {
+ DCHECK(!iterator.handle_.is_null());
+ return Handle<T>::cast(iterator.handle_);
+ }
+
void Advance() {
if (handle_.is_null() && object_->IsJSProxy()) {
did_jump_to_prototype_chain_ = true;
@@ -79,6 +92,7 @@ class PrototypeIterator {
}
AdvanceIgnoringProxies();
}
+
void AdvanceIgnoringProxies() {
if (!did_jump_to_prototype_chain_) {
did_jump_to_prototype_chain_ = true;
@@ -96,6 +110,7 @@ class PrototypeIterator {
}
}
}
+
bool IsAtEnd(WhereToEnd where_to_end = END_AT_NULL) const {
if (handle_.is_null()) {
return object_->IsNull() ||
@@ -109,10 +124,12 @@ class PrototypeIterator {
!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;
« src/objects.cc ('K') | « src/objects.cc ('k') | src/runtime/runtime-array.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698