diff options
author | Lars Knoll <[email protected]> | 2015-02-13 15:23:13 +0100 |
---|---|---|
committer | Simon Hausmann <[email protected]> | 2015-04-24 15:20:28 +0000 |
commit | 3dd0a2328cde175dbdcbb8af94b5984f7d84796f (patch) | |
tree | 6a82e78909ac49ebd3de3ebdfd150fa0851866af | |
parent | 3830ad49cbab8ecacc17d7be81374e5b1727a21c (diff) |
More cleanups in qv4value_p.h
Change-Id: Ie48dc8f95daa4738e690902b5d33010afa7b974f
Reviewed-by: Simon Hausmann <[email protected]>
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 1 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4context.cpp | 10 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4context_p.h | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4engine_p.h | 13 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4managed_p.h | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4runtime_p.h | 1 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4value.cpp | 63 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4value_inl_p.h | 128 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4value_p.h | 66 | ||||
-rw-r--r-- | src/qml/qml/qqmldata_p.h | 1 |
10 files changed, 141 insertions, 146 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 02274ca793..0d83b21d84 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -33,6 +33,7 @@ #include "qv4codegen_p.h" #include "qv4util_p.h" +#include "qv4engine_p.h" #include <QtCore/QCoreApplication> #include <QtCore/QStringList> diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp index 0ef7d56c4d..11bfa62afc 100644 --- a/src/qml/jsruntime/qv4context.cpp +++ b/src/qml/jsruntime/qv4context.cpp @@ -154,7 +154,7 @@ Heap::CatchContext::CatchContext(ExecutionEngine *engine, QV4::String *exception lookups = parent->lookups; compilationUnit = parent->compilationUnit; - this->exceptionVarName = exceptionVarName; + this->exceptionVarName = exceptionVarName->d(); this->exceptionValue = exceptionValue; } @@ -217,7 +217,7 @@ bool ExecutionContext::deleteProperty(String *name) return withObject->deleteProperty(name); } else if (ctx->d()->type == Heap::ExecutionContext::Type_CatchContext) { Heap::CatchContext *c = static_cast<Heap::CatchContext *>(ctx->d()); - if (c->exceptionVarName->isEqualTo(name)) + if (c->exceptionVarName->isEqualTo(name->d())) return false; } else if (ctx->d()->type >= Heap::ExecutionContext::Type_CallContext) { Heap::CallContext *c = static_cast<Heap::CallContext *>(ctx->d()); @@ -290,7 +290,7 @@ void ExecutionContext::setProperty(String *name, const Value &value) w->put(name, value); return; } - } else if (ctx->d()->type == Heap::ExecutionContext::Type_CatchContext && static_cast<Heap::CatchContext *>(ctx->d())->exceptionVarName->isEqualTo(name)) { + } else if (ctx->d()->type == Heap::ExecutionContext::Type_CatchContext && static_cast<Heap::CatchContext *>(ctx->d())->exceptionVarName->isEqualTo(name->d())) { static_cast<Heap::CatchContext *>(ctx->d())->exceptionValue = value; return; } else { @@ -363,7 +363,7 @@ ReturnedValue ExecutionContext::getProperty(String *name) else if (ctx->d()->type == Heap::ExecutionContext::Type_CatchContext) { hasCatchScope = true; Heap::CatchContext *c = static_cast<Heap::CatchContext *>(ctx->d()); - if (c->exceptionVarName->isEqualTo(name)) + if (c->exceptionVarName->isEqualTo(name->d())) return c->exceptionValue.asReturnedValue(); } @@ -431,7 +431,7 @@ ReturnedValue ExecutionContext::getPropertyAndBase(String *name, Heap::Object ** else if (ctx->d()->type == Heap::ExecutionContext::Type_CatchContext) { hasCatchScope = true; Heap::CatchContext *c = static_cast<Heap::CatchContext *>(ctx->d()); - if (c->exceptionVarName->isEqualTo(name)) + if (c->exceptionVarName->isEqualTo(name->d())) return c->exceptionValue.asReturnedValue(); } diff --git a/src/qml/jsruntime/qv4context_p.h b/src/qml/jsruntime/qv4context_p.h index cf229d4221..2cff65b3d9 100644 --- a/src/qml/jsruntime/qv4context_p.h +++ b/src/qml/jsruntime/qv4context_p.h @@ -117,7 +117,7 @@ struct GlobalContext : ExecutionContext { struct CatchContext : ExecutionContext { CatchContext(ExecutionEngine *engine, QV4::String *exceptionVarName, const Value &exceptionValue); - StringValue exceptionVarName; + Pointer<String> exceptionVarName; Value exceptionValue; }; diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index 33dce48737..84ecc3843f 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -38,6 +38,7 @@ #include "qv4managed_p.h" #include "qv4context_p.h" #include "qv4string_p.h" +#include "qv4value_inl_p.h" #include "qv4internalclass_p.h" #include <private/qintrusivelist_p.h> @@ -376,18 +377,6 @@ Heap::ExecutionContext::ExecutionContext(ExecutionEngine *engine, ContextType t) } -// ### Remove me -inline -void Managed::mark(QV4::ExecutionEngine *engine) -{ - Q_ASSERT(inUse()); - if (markBit()) - return; - d()->setMarkBit(); - engine->pushForGC(d()); -} - - inline void Heap::Base::mark(QV4::ExecutionEngine *engine) { diff --git a/src/qml/jsruntime/qv4managed_p.h b/src/qml/jsruntime/qv4managed_p.h index a5d941e864..7cce80d087 100644 --- a/src/qml/jsruntime/qv4managed_p.h +++ b/src/qml/jsruntime/qv4managed_p.h @@ -124,8 +124,6 @@ private: public: - inline void mark(QV4::ExecutionEngine *engine); - enum Type { Type_Invalid, Type_String, diff --git a/src/qml/jsruntime/qv4runtime_p.h b/src/qml/jsruntime/qv4runtime_p.h index 44c7fbcb9c..4f10853bb1 100644 --- a/src/qml/jsruntime/qv4runtime_p.h +++ b/src/qml/jsruntime/qv4runtime_p.h @@ -36,6 +36,7 @@ #include "qv4global_p.h" #include "qv4value_inl_p.h" #include "qv4context_p.h" +#include "qv4engine_p.h" #include "qv4math_p.h" #include <QtCore/qnumeric.h> diff --git a/src/qml/jsruntime/qv4value.cpp b/src/qml/jsruntime/qv4value.cpp index 0ea4676f47..6574497ae6 100644 --- a/src/qml/jsruntime/qv4value.cpp +++ b/src/qml/jsruntime/qv4value.cpp @@ -32,6 +32,7 @@ ****************************************************************************/ #include <qv4engine_p.h> #include <qv4runtime_p.h> +#include <qv4string_p.h> #ifndef V4_BOOTSTRAP #include <qv4object_p.h> #include <qv4objectproto_p.h> @@ -68,6 +69,28 @@ int Value::toUInt16() const return (unsigned short)number; } +bool Value::toBoolean() const +{ + switch (type()) { + case Value::Undefined_Type: + case Value::Null_Type: + return false; + case Value::Boolean_Type: + case Value::Integer_Type: + return (bool)int_32; + case Value::Managed_Type: +#ifdef V4_BOOTSTRAP + Q_UNIMPLEMENTED(); +#else + if (isString()) + return stringValue()->toQString().length() > 0; +#endif + return true; + default: // double + return doubleValue() && !std::isnan(doubleValue()); + } +} + double Value::toInteger() const { if (integerCompatible()) @@ -87,10 +110,10 @@ double Value::toNumberImpl() const #else if (isString()) return RuntimeHelpers::stringToNumber(stringValue()->toQString()); - { - Q_ASSERT(isObject()); - Scope scope(objectValue()->engine()); - ScopedValue prim(scope, RuntimeHelpers::toPrimitive(*this, NUMBER_HINT)); + { + Q_ASSERT(isObject()); + Scope scope(objectValue()->engine()); + ScopedValue prim(scope, RuntimeHelpers::toPrimitive(*this, NUMBER_HINT)); if (scope.engine->hasException) return 0; return prim->toNumber(); @@ -282,3 +305,35 @@ Heap::Object *Value::toObject(ExecutionEngine *e) const } #endif // V4_BOOTSTRAP + +uint Value::asArrayLength(bool *ok) const +{ + *ok = true; + if (isInteger()) { + if (int_32 >= 0) { + return (uint)int_32; + } else { + *ok = false; + return UINT_MAX; + } + } + if (isNumber()) { + double d = doubleValue(); + uint idx = (uint)d; + if (idx != d) { + *ok = false; + return UINT_MAX; + } + return idx; + } + if (isString()) + return stringValue()->toUInt(ok); + + uint idx = toUInt32(); + double d = toNumber(); + if (d != idx) { + *ok = false; + return UINT_MAX; + } + return idx; +} diff --git a/src/qml/jsruntime/qv4value_inl_p.h b/src/qml/jsruntime/qv4value_inl_p.h index 9297f2ceda..9c6dbadc65 100644 --- a/src/qml/jsruntime/qv4value_inl_p.h +++ b/src/qml/jsruntime/qv4value_inl_p.h @@ -39,7 +39,6 @@ #include <private/qv4heap_p.h> #include "qv4string_p.h" #include "qv4managed_p.h" -#include "qv4engine_p.h" QT_BEGIN_NAMESPACE @@ -54,52 +53,6 @@ inline void Value::mark(ExecutionEngine *e) m->mark(e); } -inline Primitive Primitive::nullValue() -{ - Primitive v; -#if QT_POINTER_SIZE == 8 - v.val = quint64(_Null_Type) << Tag_Shift; -#else - v.tag = _Null_Type; - v.int_32 = 0; -#endif - return v; -} - -inline Primitive Primitive::fromBoolean(bool b) -{ - Primitive v; - v.tag = _Boolean_Type; - v.int_32 = (bool)b; - return v; -} - -inline Primitive Primitive::fromDouble(double d) -{ - Primitive v; - v.setDouble(d); - return v; -} - -inline Primitive Primitive::fromInt32(int i) -{ - Primitive v; - v.tag = _Integer_Type; - v.int_32 = i; - return v; -} - -inline Primitive Primitive::fromUInt32(uint i) -{ - Primitive v; - if (i < INT_MAX) { - v.tag = _Integer_Type; - v.int_32 = (int)i; - } else { - v.setDouble(i); - } - return v; -} inline double Value::toNumber() const { @@ -131,27 +84,7 @@ inline unsigned int Value::toUInt32() const } -inline bool Value::toBoolean() const -{ - switch (type()) { - case Value::Undefined_Type: - case Value::Null_Type: - return false; - case Value::Boolean_Type: - case Value::Integer_Type: - return (bool)int_32; - case Value::Managed_Type: -#ifdef V4_BOOTSTRAP - Q_UNIMPLEMENTED(); -#else - if (isString()) - return stringValue()->toQString().length() > 0; -#endif - return true; - default: // double - return doubleValue() && !std::isnan(doubleValue()); - } -} + inline ReturnedValue Heap::Base::asReturnedValue() const @@ -181,37 +114,7 @@ inline uint Value::asArrayIndex() const return idx; } -inline uint Value::asArrayLength(bool *ok) const -{ - *ok = true; - if (isInteger()) { - if (int_32 >= 0) { - return (uint)int_32; - } else { - *ok = false; - return UINT_MAX; - } - } - if (isNumber()) { - double d = doubleValue(); - uint idx = (uint)d; - if (idx != d) { - *ok = false; - return UINT_MAX; - } - return idx; - } - if (isString()) - return stringValue()->toUInt(ok); - uint idx = toUInt32(); - double d = toNumber(); - if (d != idx) { - *ok = false; - return UINT_MAX; - } - return idx; -} template<> inline ReturnedValue value_convert<String>(ExecutionEngine *e, const Value &v) @@ -221,6 +124,35 @@ inline ReturnedValue value_convert<String>(ExecutionEngine *e, const Value &v) #endif +template <typename T> +struct TypedValue : public Value +{ + template<typename X> + TypedValue &operator =(X *x) { + m = x; +#if QT_POINTER_SIZE == 4 + tag = Managed_Type; +#endif + return *this; + } + TypedValue &operator =(T *t); + TypedValue &operator =(const Scoped<T> &v); +// TypedValue &operator =(const ManagedRef<T> &v); + + TypedValue &operator =(const TypedValue<T> &t); + + bool operator!() const { return !managed(); } + + operator T *() { return static_cast<T *>(managed()); } + T *operator->() { return static_cast<T *>(managed()); } + const T *operator->() const { return static_cast<T *>(managed()); } + T *getPointer() const { return static_cast<T *>(managed()); } + + void mark(ExecutionEngine *e) { if (managed()) managed()->mark(e); } +}; +typedef TypedValue<String> StringValue; + + } // namespace QV4 QT_END_NAMESPACE diff --git a/src/qml/jsruntime/qv4value_p.h b/src/qml/jsruntime/qv4value_p.h index 7deb2098ac..aeaefb3d70 100644 --- a/src/qml/jsruntime/qv4value_p.h +++ b/src/qml/jsruntime/qv4value_p.h @@ -287,7 +287,7 @@ struct Q_QML_PRIVATE_EXPORT Value inline int toInt32() const; inline unsigned int toUInt32() const; - inline bool toBoolean() const; + bool toBoolean() const; double toInteger() const; inline double toNumber() const; double toNumberImpl() const; @@ -334,7 +334,7 @@ struct Q_QML_PRIVATE_EXPORT Value } inline uint asArrayIndex() const; - inline uint asArrayLength(bool *ok) const; + uint asArrayLength(bool *ok) const; ReturnedValue asReturnedValue() const { return val; } static Value fromReturnedValue(ReturnedValue val) { Value v; v.val = val; return v; } @@ -428,34 +428,52 @@ inline Primitive Primitive::emptyValue() return v; } -template <typename T> -struct TypedValue : public Value +inline Primitive Primitive::nullValue() { - template<typename X> - TypedValue &operator =(X *x) { - m = x; -#if QT_POINTER_SIZE == 4 - tag = Managed_Type; + Primitive v; +#if QT_POINTER_SIZE == 8 + v.val = quint64(_Null_Type) << Tag_Shift; +#else + v.tag = _Null_Type; + v.int_32 = 0; #endif - return *this; - } - TypedValue &operator =(T *t); - TypedValue &operator =(const Scoped<T> &v); -// TypedValue &operator =(const ManagedRef<T> &v); - - TypedValue &operator =(const TypedValue<T> &t); + return v; +} - bool operator!() const { return !managed(); } +inline Primitive Primitive::fromBoolean(bool b) +{ + Primitive v; + v.tag = _Boolean_Type; + v.int_32 = (bool)b; + return v; +} - operator T *() { return static_cast<T *>(managed()); } - T *operator->() { return static_cast<T *>(managed()); } - const T *operator->() const { return static_cast<T *>(managed()); } - T *getPointer() const { return static_cast<T *>(managed()); } +inline Primitive Primitive::fromDouble(double d) +{ + Primitive v; + v.setDouble(d); + return v; +} - void mark(ExecutionEngine *e) { if (managed()) managed()->mark(e); } -}; -typedef TypedValue<String> StringValue; +inline Primitive Primitive::fromInt32(int i) +{ + Primitive v; + v.tag = _Integer_Type; + v.int_32 = i; + return v; +} +inline Primitive Primitive::fromUInt32(uint i) +{ + Primitive v; + if (i < INT_MAX) { + v.tag = _Integer_Type; + v.int_32 = (int)i; + } else { + v.setDouble(i); + } + return v; +} struct Encode { static ReturnedValue undefined() { diff --git a/src/qml/qml/qqmldata_p.h b/src/qml/qml/qqmldata_p.h index c7654be545..c9c979c80e 100644 --- a/src/qml/qml/qqmldata_p.h +++ b/src/qml/qml/qqmldata_p.h @@ -50,6 +50,7 @@ #include <private/qv4value_inl_p.h> #include <private/qv4persistent_p.h> +#include <qjsengine.h> QT_BEGIN_NAMESPACE |