Reviewers: dcarney,
Message:
PTAL
Description:
Move template instance check from Object to
FunctionTemplateInfo::IsTemplateFor
BUG=
Please review this at https://chromiumcodereview.appspot.com/67613005/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+39, -33 lines):
M src/api.cc
M src/bootstrapper.cc
M src/builtins.cc
M src/objects-inl.h
M src/objects.h
M src/objects.cc
M src/stub-cache.h
M src/stub-cache.cc
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
736f0b00d7ac833ca3409ebd703a90f8ef49a5bc..5d954ef8c4a0493901ea8cd852c2a2c23242514f
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -1264,7 +1264,7 @@ int TypeSwitch::match(v8::Handle<Value> value) {
i::Handle<i::TypeSwitchInfo> info = Utils::OpenHandle(this);
i::FixedArray* types = i::FixedArray::cast(info->types());
for (int i = 0; i < types->length(); i++) {
- if (obj->IsInstanceOf(i::FunctionTemplateInfo::cast(types->get(i))))
+ if (i::FunctionTemplateInfo::cast(types->get(i))->IsTemplateFor(*obj))
return i + 1;
}
return 0;
@@ -3346,7 +3346,7 @@ Local<Object>
v8::Object::FindInstanceInPrototypeChain(
ENTER_V8(isolate);
i::JSObject* object = *Utils::OpenHandle(this);
i::FunctionTemplateInfo* tmpl_info = *Utils::OpenHandle(*tmpl);
- while (!object->IsInstanceOf(tmpl_info)) {
+ while (!tmpl_info->IsTemplateFor(object)) {
i::Object* prototype = object->GetPrototype();
if (!prototype->IsJSObject()) return Local<Object>();
object = i::JSObject::cast(prototype);
@@ -5427,7 +5427,7 @@ bool
FunctionTemplate::HasInstance(v8::Handle<v8::Value> value) {
ON_BAILOUT(i::Isolate::Current(), "v8::FunctionTemplate::HasInstanceOf()",
return false);
i::Object* obj = *Utils::OpenHandle(*value);
- return obj->IsInstanceOf(*Utils::OpenHandle(this));
+ return Utils::OpenHandle(this)->IsTemplateFor(obj);
}
Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index
234a2118bdd7002189906df3e21f6446869f594e..bc52fa858feedd970e686368cae17f47eb445e0c
100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -2426,8 +2426,8 @@ bool Genesis::ConfigureGlobalObjects(
bool Genesis::ConfigureApiObject(Handle<JSObject> object,
Handle<ObjectTemplateInfo> object_template) {
ASSERT(!object_template.is_null());
- ASSERT(object->IsInstanceOf(
- FunctionTemplateInfo::cast(object_template->constructor())));
+ ASSERT(FunctionTemplateInfo::cast(object_template->constructor())
+ ->IsTemplateFor(object->map()));;
bool pending_exception = false;
Handle<JSObject> obj =
Index: src/builtins.cc
diff --git a/src/builtins.cc b/src/builtins.cc
index
655b808f1be51910bf1e482c5d1cc17ffcc935b6..f950c595b9a3ff32c506a9fb627050f49fcd85ce
100644
--- a/src/builtins.cc
+++ b/src/builtins.cc
@@ -1104,7 +1104,7 @@ BUILTIN(StrictModePoisonPill) {
static inline Object* FindHidden(Heap* heap,
Object* object,
FunctionTemplateInfo* type) {
- if (object->IsInstanceOf(type)) return object;
+ if (type->IsTemplateFor(object)) return object;
Object* proto = object->GetPrototype(heap->isolate());
if (proto->IsJSObject() &&
JSObject::cast(proto)->map()->is_hidden_prototype()) {
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index
20a44c32166c6dd4411f3c76f9ce2af586df9502..2e8c0ada3877b3633e34c5f4d9732c94868de3c2
100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -150,25 +150,6 @@ bool Object::IsAccessorInfo() {
}
-bool Object::IsInstanceOf(FunctionTemplateInfo* expected) {
- // There is a constraint on the object; check.
- if (!this->IsJSObject()) return false;
- // Fetch the constructor function of the object.
- Object* cons_obj = JSObject::cast(this)->map()->constructor();
- if (!cons_obj->IsJSFunction()) return false;
- JSFunction* fun = JSFunction::cast(cons_obj);
- // Iterate through the chain of inheriting function templates to
- // see if the required one occurs.
- for (Object* type = fun->shared()->function_data();
- type->IsFunctionTemplateInfo();
- type = FunctionTemplateInfo::cast(type)->parent_template()) {
- if (type == expected) return true;
- }
- // Didn't find the required type in the inheritance chain.
- return false;
-}
-
-
bool Object::IsSmi() {
return HAS_SMI_TAG(this);
}
@@ -5957,7 +5938,7 @@ void
AccessorInfo::set_property_attributes(PropertyAttributes attributes) {
bool AccessorInfo::IsCompatibleReceiver(Object* receiver) {
Object* function_template = expected_receiver_type();
if (!function_template->IsFunctionTemplateInfo()) return true;
- return
receiver->IsInstanceOf(FunctionTemplateInfo::cast(function_template));
+ return
FunctionTemplateInfo::cast(function_template)->IsTemplateFor(receiver);
}
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index
6cb5e212026de06051e8d83d9000964d4e3a7ba5..8a95b980a19ce5a5db6d589160cf6aae4027d0ca
100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -203,6 +203,31 @@ bool Object::ToUint32(uint32_t* value) {
}
+bool FunctionTemplateInfo::IsTemplateFor(Object* object) {
+ if (!object->IsHeapObject()) return false;
+ return IsTemplateFor(HeapObject::cast(object)->map());
+}
+
+
+bool FunctionTemplateInfo::IsTemplateFor(Map* map) {
+ // There is a constraint on the object; check.
+ if (!map->IsJSObjectMap()) return false;
+ // Fetch the constructor function of the object.
+ Object* cons_obj = map->constructor();
+ if (!cons_obj->IsJSFunction()) return false;
+ JSFunction* fun = JSFunction::cast(cons_obj);
+ // Iterate through the chain of inheriting function templates to
+ // see if the required one occurs.
+ for (Object* type = fun->shared()->function_data();
+ type->IsFunctionTemplateInfo();
+ type = FunctionTemplateInfo::cast(type)->parent_template()) {
+ if (type == this) return true;
+ }
+ // Didn't find the required type in the inheritance chain.
+ return false;
+}
+
+
template<typename To>
static inline To* CheckedCast(void *from) {
uintptr_t temp = reinterpret_cast<uintptr_t>(from);
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index
d44ae28053de6cce777caf8129c8fa84f07d0254..c8e2b368b51ce640e9c6df082f520f76677586e6
100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -1351,10 +1351,6 @@ class Object : public MaybeObject {
inline bool IsExternal();
inline bool IsAccessorInfo();
- // Returns true if this object is an instance of the specified
- // function template.
- inline bool IsInstanceOf(FunctionTemplateInfo* type);
-
inline bool IsStruct();
#define DECLARE_STRUCT_PREDICATE(NAME, Name, name) inline bool Is##Name();
STRUCT_LIST(DECLARE_STRUCT_PREDICATE)
@@ -10266,6 +10262,10 @@ class FunctionTemplateInfo: public TemplateInfo {
static const int kLengthOffset = kFlagOffset + kPointerSize;
static const int kSize = kLengthOffset + kPointerSize;
+ // Returns true if |object| is an instance of this function template.
+ bool IsTemplateFor(Object* object);
+ bool IsTemplateFor(Map* map);
+
private:
// Bit position in the flag, from least significant bit position.
static const int kHiddenPrototypeBit = 0;
Index: src/stub-cache.cc
diff --git a/src/stub-cache.cc b/src/stub-cache.cc
index
f9918ed62ef46c1286f743f37584527b3a3f7349..f8607bfe60651747cc1ca44102d18b9c70d21369
100644
--- a/src/stub-cache.cc
+++ b/src/stub-cache.cc
@@ -1785,12 +1785,12 @@ int
CallOptimization::GetPrototypeDepthOfExpectedType(
if (expected_receiver_type_.is_null()) return 0;
int depth = 0;
while (!object.is_identical_to(holder)) {
- if (object->IsInstanceOf(*expected_receiver_type_)) return depth;
+ if (expected_receiver_type_->IsTemplateFor(object->map())) return
depth;
object = Handle<JSObject>(JSObject::cast(object->GetPrototype()));
if (!object->map()->is_hidden_prototype()) return kInvalidProtoDepth;
++depth;
}
- if (holder->IsInstanceOf(*expected_receiver_type_)) return depth;
+ if (expected_receiver_type_->IsTemplateFor(holder->map())) return depth;
return kInvalidProtoDepth;
}
Index: src/stub-cache.h
diff --git a/src/stub-cache.h b/src/stub-cache.h
index
adfa44a3ef01a8e4ff794bffb66a1c9d57986450..91f340933cfc7c4dc512085aa123c3d3b5df480a
100644
--- a/src/stub-cache.h
+++ b/src/stub-cache.h
@@ -1037,7 +1037,7 @@ class CallOptimization BASE_EMBEDDED {
bool IsCompatibleReceiver(Object* receiver) {
ASSERT(is_simple_api_call());
if (expected_receiver_type_.is_null()) return true;
- return receiver->IsInstanceOf(*expected_receiver_type_);
+ return expected_receiver_type_->IsTemplateFor(receiver);
}
private:
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.