aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2016-11-24 15:39:07 +0100
committerLars Knoll <lars.knoll@qt.io>2016-11-29 19:59:58 +0000
commit6b641549536d199a0314049a34e61363bd4df7e0 (patch)
tree1a2f68d61862ede6a06a126d18a5435a0a0bb346 /src/qml/jsruntime
parent58d0fc4dcf99b867d1f0bd67327105983ec36e07 (diff)
Clean up duplicated checks whether a Value is a Managed
Change-Id: Ib044be254dbb41bd9fb4a6e0baa3bd3c007e6a2a Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r--src/qml/jsruntime/qv4dateobject_p.h2
-rw-r--r--src/qml/jsruntime/qv4engine_p.h3
-rw-r--r--src/qml/jsruntime/qv4errorobject_p.h2
-rw-r--r--src/qml/jsruntime/qv4functionobject_p.h2
-rw-r--r--src/qml/jsruntime/qv4lookup.cpp110
-rw-r--r--src/qml/jsruntime/qv4managed_p.h6
-rw-r--r--src/qml/jsruntime/qv4property_p.h4
-rw-r--r--src/qml/jsruntime/qv4string_p.h2
-rw-r--r--src/qml/jsruntime/qv4value_p.h12
9 files changed, 68 insertions, 75 deletions
diff --git a/src/qml/jsruntime/qv4dateobject_p.h b/src/qml/jsruntime/qv4dateobject_p.h
index 2d0648396e..835f6adbe0 100644
--- a/src/qml/jsruntime/qv4dateobject_p.h
+++ b/src/qml/jsruntime/qv4dateobject_p.h
@@ -101,7 +101,7 @@ struct DateObject: Object {
template<>
inline const DateObject *Value::as() const {
- return isManaged() && m() && m()->vtable()->type == Managed::Type_DateObject ? static_cast<const DateObject *>(this) : 0;
+ return isManaged() && m()->vtable()->type == Managed::Type_DateObject ? static_cast<const DateObject *>(this) : 0;
}
struct DateCtor: FunctionObject
diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h
index d20402b369..64bf77b1f5 100644
--- a/src/qml/jsruntime/qv4engine_p.h
+++ b/src/qml/jsruntime/qv4engine_p.h
@@ -584,9 +584,6 @@ void Heap::Base::mark(QV4::ExecutionEngine *engine)
inline void Value::mark(ExecutionEngine *e)
{
- if (!isManaged())
- return;
-
Heap::Base *o = heapObject();
if (o)
o->mark(e);
diff --git a/src/qml/jsruntime/qv4errorobject_p.h b/src/qml/jsruntime/qv4errorobject_p.h
index 42a6e0b4b1..2b3ab25e2d 100644
--- a/src/qml/jsruntime/qv4errorobject_p.h
+++ b/src/qml/jsruntime/qv4errorobject_p.h
@@ -178,7 +178,7 @@ struct ErrorObject: Object {
template<>
inline const ErrorObject *Value::as() const {
- return isManaged() && m() && m()->vtable()->isErrorObject ? reinterpret_cast<const ErrorObject *>(this) : 0;
+ return isManaged() && m()->vtable()->isErrorObject ? reinterpret_cast<const ErrorObject *>(this) : 0;
}
struct EvalErrorObject: ErrorObject {
diff --git a/src/qml/jsruntime/qv4functionobject_p.h b/src/qml/jsruntime/qv4functionobject_p.h
index e58b83e2c3..3dcc7ab482 100644
--- a/src/qml/jsruntime/qv4functionobject_p.h
+++ b/src/qml/jsruntime/qv4functionobject_p.h
@@ -168,7 +168,7 @@ struct Q_QML_EXPORT FunctionObject: Object {
template<>
inline const FunctionObject *Value::as() const {
- return isManaged() && m() && m()->vtable()->isFunctionObject ? reinterpret_cast<const FunctionObject *>(this) : 0;
+ return isManaged() && m()->vtable()->isFunctionObject ? reinterpret_cast<const FunctionObject *>(this) : 0;
}
diff --git a/src/qml/jsruntime/qv4lookup.cpp b/src/qml/jsruntime/qv4lookup.cpp
index 84755a6402..5e9d4cf57c 100644
--- a/src/qml/jsruntime/qv4lookup.cpp
+++ b/src/qml/jsruntime/qv4lookup.cpp
@@ -345,11 +345,11 @@ ReturnedValue Lookup::getterFallback(Lookup *l, ExecutionEngine *engine, const V
ReturnedValue Lookup::getter0(Lookup *l, ExecutionEngine *engine, const Value &object)
{
- if (object.isManaged()) {
- // we can safely cast to a QV4::Object here. If object is actually a string,
- // the internal class won't match
- Object *o = object.objectValue();
- if (l->classList[0] == o->internalClass())
+ // we can safely cast to a QV4::Object here. If object is actually a string,
+ // the internal class won't match
+ Heap::Object *o = static_cast<Heap::Object *>(object.heapObject());
+ if (o) {
+ if (l->classList[0] == o->internalClass)
return o->propertyData(l->index)->asReturnedValue();
}
return getterTwoClasses(l, engine, object);
@@ -357,25 +357,24 @@ ReturnedValue Lookup::getter0(Lookup *l, ExecutionEngine *engine, const Value &o
ReturnedValue Lookup::getter1(Lookup *l, ExecutionEngine *engine, const Value &object)
{
- if (object.isManaged()) {
- // we can safely cast to a QV4::Object here. If object is actually a string,
- // the internal class won't match
- Object *o = object.objectValue();
- if (l->classList[0] == o->internalClass() &&
- l->classList[1] == o->prototype()->internalClass)
- return o->prototype()->propertyData(l->index)->asReturnedValue();
+ // we can safely cast to a QV4::Object here. If object is actually a string,
+ // the internal class won't match
+ Heap::Object *o = static_cast<Heap::Object *>(object.heapObject());
+ if (o) {
+ if (l->classList[0] == o->internalClass && l->classList[1] == o->prototype->internalClass)
+ return o->prototype->propertyData(l->index)->asReturnedValue();
}
return getterTwoClasses(l, engine, object);
}
ReturnedValue Lookup::getter2(Lookup *l, ExecutionEngine *engine, const Value &object)
{
- if (object.isManaged()) {
- // we can safely cast to a QV4::Object here. If object is actually a string,
- // the internal class won't match
- Object *o = object.objectValue();
- if (l->classList[0] == o->internalClass()) {
- Heap::Object *p = o->prototype();
+ // we can safely cast to a QV4::Object here. If object is actually a string,
+ // the internal class won't match
+ Heap::Object *o = static_cast<Heap::Object *>(object.heapObject());
+ if (o) {
+ if (l->classList[0] == o->internalClass) {
+ Heap::Object *p = o->prototype;
if (l->classList[1] == p->internalClass) {
p = p->prototype;
if (l->classList[2] == p->internalClass)
@@ -389,13 +388,13 @@ ReturnedValue Lookup::getter2(Lookup *l, ExecutionEngine *engine, const Value &o
ReturnedValue Lookup::getter0getter0(Lookup *l, ExecutionEngine *engine, const Value &object)
{
- if (object.isManaged()) {
- // we can safely cast to a QV4::Object here. If object is actually a string,
- // the internal class won't match
- Object *o = object.objectValue();
- if (l->classList[0] == o->internalClass())
+ // we can safely cast to a QV4::Object here. If object is actually a string,
+ // the internal class won't match
+ Heap::Object *o = static_cast<Heap::Object *>(object.heapObject());
+ if (o) {
+ if (l->classList[0] == o->internalClass)
return o->propertyData(l->index)->asReturnedValue();
- if (l->classList[2] == o->internalClass())
+ if (l->classList[2] == o->internalClass)
return o->propertyData(l->index2)->asReturnedValue();
}
l->getter = getterFallback;
@@ -404,15 +403,14 @@ ReturnedValue Lookup::getter0getter0(Lookup *l, ExecutionEngine *engine, const V
ReturnedValue Lookup::getter0getter1(Lookup *l, ExecutionEngine *engine, const Value &object)
{
- if (object.isManaged()) {
- // we can safely cast to a QV4::Object here. If object is actually a string,
- // the internal class won't match
- Object *o = object.objectValue();
- if (l->classList[0] == o->internalClass())
+ // we can safely cast to a QV4::Object here. If object is actually a string,
+ // the internal class won't match
+ Heap::Object *o = static_cast<Heap::Object *>(object.heapObject());
+ if (o) {
+ if (l->classList[0] == o->internalClass)
return o->propertyData(l->index)->asReturnedValue();
- if (l->classList[2] == o->internalClass() &&
- l->classList[3] == o->prototype()->internalClass)
- return o->prototype()->propertyData(l->index2)->asReturnedValue();
+ if (l->classList[2] == o->internalClass && l->classList[3] == o->prototype->internalClass)
+ return o->prototype->propertyData(l->index2)->asReturnedValue();
}
l->getter = getterFallback;
return getterFallback(l, engine, object);
@@ -420,16 +418,16 @@ ReturnedValue Lookup::getter0getter1(Lookup *l, ExecutionEngine *engine, const V
ReturnedValue Lookup::getter1getter1(Lookup *l, ExecutionEngine *engine, const Value &object)
{
- if (object.isManaged()) {
- // we can safely cast to a QV4::Object here. If object is actually a string,
- // the internal class won't match
- Object *o = object.objectValue();
- if (l->classList[0] == o->internalClass() &&
- l->classList[1] == o->prototype()->internalClass)
- return o->prototype()->propertyData(l->index)->asReturnedValue();
- if (l->classList[2] == o->internalClass() &&
- l->classList[3] == o->prototype()->internalClass)
- return o->prototype()->propertyData(l->index2)->asReturnedValue();
+ // we can safely cast to a QV4::Object here. If object is actually a string,
+ // the internal class won't match
+ Heap::Object *o = static_cast<Heap::Object *>(object.heapObject());
+ if (o) {
+ if (l->classList[0] == o->internalClass &&
+ l->classList[1] == o->prototype->internalClass)
+ return o->prototype->propertyData(l->index)->asReturnedValue();
+ if (l->classList[2] == o->internalClass &&
+ l->classList[3] == o->prototype->internalClass)
+ return o->prototype->propertyData(l->index2)->asReturnedValue();
return getterFallback(l, engine, object);
}
l->getter = getterFallback;
@@ -439,12 +437,12 @@ ReturnedValue Lookup::getter1getter1(Lookup *l, ExecutionEngine *engine, const V
ReturnedValue Lookup::getterAccessor0(Lookup *l, ExecutionEngine *engine, const Value &object)
{
- if (object.isManaged()) {
- // we can safely cast to a QV4::Object here. If object is actually a string,
- // the internal class won't match
- Object *o = object.objectValue();
- if (l->classList[0] == o->internalClass()) {
- Scope scope(o->engine());
+ // we can safely cast to a QV4::Object here. If object is actually a string,
+ // the internal class won't match
+ Heap::Object *o = static_cast<Heap::Object *>(object.heapObject());
+ if (o) {
+ if (l->classList[0] == o->internalClass) {
+ Scope scope(o->internalClass->engine);
ScopedFunctionObject getter(scope, o->propertyData(l->index + Object::GetterOffset));
if (!getter)
return Encode::undefined();
@@ -461,10 +459,10 @@ ReturnedValue Lookup::getterAccessor0(Lookup *l, ExecutionEngine *engine, const
ReturnedValue Lookup::getterAccessor1(Lookup *l, ExecutionEngine *engine, const Value &object)
{
- if (object.isManaged()) {
- // we can safely cast to a QV4::Object here. If object is actually a string,
- // the internal class won't match
- Heap::Object *o = object.objectValue()->d();
+ // we can safely cast to a QV4::Object here. If object is actually a string,
+ // the internal class won't match
+ Heap::Object *o = static_cast<Heap::Object *>(object.heapObject());
+ if (o) {
if (l->classList[0] == o->internalClass &&
l->classList[1] == o->prototype->internalClass) {
Scope scope(o->internalClass->engine);
@@ -484,10 +482,10 @@ ReturnedValue Lookup::getterAccessor1(Lookup *l, ExecutionEngine *engine, const
ReturnedValue Lookup::getterAccessor2(Lookup *l, ExecutionEngine *engine, const Value &object)
{
- if (object.isManaged()) {
- // we can safely cast to a QV4::Object here. If object is actually a string,
- // the internal class won't match
- Heap::Object *o = object.objectValue()->d();
+ // we can safely cast to a QV4::Object here. If object is actually a string,
+ // the internal class won't match
+ Heap::Object *o = static_cast<Heap::Object *>(object.heapObject());
+ if (o) {
if (l->classList[0] == o->internalClass) {
o = o->prototype;
if (l->classList[1] == o->internalClass) {
diff --git a/src/qml/jsruntime/qv4managed_p.h b/src/qml/jsruntime/qv4managed_p.h
index 28b255bd9a..56a1fcedf5 100644
--- a/src/qml/jsruntime/qv4managed_p.h
+++ b/src/qml/jsruntime/qv4managed_p.h
@@ -215,14 +215,12 @@ private:
template<>
inline const Managed *Value::as() const {
- if (isManaged())
- return managed();
- return 0;
+ return managed();
}
template<>
inline const Object *Value::as() const {
- return isManaged() && m() && m()->vtable()->isObject ? objectValue() : 0;
+ return objectValue();
}
}
diff --git a/src/qml/jsruntime/qv4property_p.h b/src/qml/jsruntime/qv4property_p.h
index 50e8f0ae7f..5069d7690b 100644
--- a/src/qml/jsruntime/qv4property_p.h
+++ b/src/qml/jsruntime/qv4property_p.h
@@ -87,8 +87,8 @@ struct Property {
inline bool isSubset(const PropertyAttributes &attrs, const Property *other, PropertyAttributes otherAttrs) const;
inline void merge(PropertyAttributes &attrs, const Property *other, PropertyAttributes otherAttrs);
- inline Heap::FunctionObject *getter() const { return value.isManaged() ? reinterpret_cast<Heap::FunctionObject *>(value.heapObject()) : 0; }
- inline Heap::FunctionObject *setter() const { return set.isManaged() ? reinterpret_cast<Heap::FunctionObject *>(set.heapObject()) : 0; }
+ inline Heap::FunctionObject *getter() const { return reinterpret_cast<Heap::FunctionObject *>(value.heapObject()); }
+ inline Heap::FunctionObject *setter() const { return reinterpret_cast<Heap::FunctionObject *>(set.heapObject()); }
inline void setGetter(FunctionObject *g) { value = reinterpret_cast<Managed *>(g); }
inline void setSetter(FunctionObject *s) { set = (s ? reinterpret_cast<Managed *>(s) : 0); }
diff --git a/src/qml/jsruntime/qv4string_p.h b/src/qml/jsruntime/qv4string_p.h
index 23ec3349b9..4890a85724 100644
--- a/src/qml/jsruntime/qv4string_p.h
+++ b/src/qml/jsruntime/qv4string_p.h
@@ -267,7 +267,7 @@ public:
template<>
inline const String *Value::as() const {
- return isManaged() && m() && m()->vtable()->isString ? static_cast<const String *>(this) : 0;
+ return isManaged() && m()->vtable()->isString ? static_cast<const String *>(this) : 0;
}
#ifndef V4_BOOTSTRAP
diff --git a/src/qml/jsruntime/qv4value_p.h b/src/qml/jsruntime/qv4value_p.h
index 29d8f196ee..e9a5b569a2 100644
--- a/src/qml/jsruntime/qv4value_p.h
+++ b/src/qml/jsruntime/qv4value_p.h
@@ -374,17 +374,17 @@ public:
QML_NEARLY_ALWAYS_INLINE String *stringValue() const {
if (!isString())
return nullptr;
- return m() ? reinterpret_cast<String*>(const_cast<Value *>(this)) : 0;
+ return reinterpret_cast<String*>(const_cast<Value *>(this));
}
QML_NEARLY_ALWAYS_INLINE Object *objectValue() const {
if (!isObject())
return nullptr;
- return m() ? reinterpret_cast<Object*>(const_cast<Value *>(this)) : 0;
+ return reinterpret_cast<Object*>(const_cast<Value *>(this));
}
QML_NEARLY_ALWAYS_INLINE Managed *managed() const {
if (!isManaged())
return nullptr;
- return m() ? reinterpret_cast<Managed*>(const_cast<Value *>(this)) : 0;
+ return reinterpret_cast<Managed*>(const_cast<Value *>(this));
}
QML_NEARLY_ALWAYS_INLINE Heap::Base *heapObject() const {
return isManaged() ? m() : nullptr;
@@ -420,7 +420,7 @@ public:
template <typename T>
const T *as() const {
- if (!m() || !isManaged())
+ if (!isManaged())
return 0;
Q_ASSERT(m()->vtable());
@@ -487,13 +487,13 @@ inline bool Value::isString() const
{
if (!isManaged())
return false;
- return m() && m()->vtable()->isString;
+ return m()->vtable()->isString;
}
inline bool Value::isObject() const
{
if (!isManaged())
return false;
- return m() && m()->vtable()->isObject;
+ return m()->vtable()->isObject;
}
inline bool Value::isPrimitive() const