X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fdeclarative%2Fqml%2Fv8%2Fqjsvalue_impl_p.h;h=28b928d62c21d784a6aceb48bbe7300e4a37b872;hb=45b14259fc0cf704692df1c00da511527d1fba1d;hp=adff6ce94580889240f8df6f7ebddf91ac19b820;hpb=f9949f501890a7f8289fcbda85d3a4085bdbb21a;p=profile%2Fivi%2Fqtdeclarative.git diff --git a/src/declarative/qml/v8/qjsvalue_impl_p.h b/src/declarative/qml/v8/qjsvalue_impl_p.h index adff6ce..28b928d 100644 --- a/src/declarative/qml/v8/qjsvalue_impl_p.h +++ b/src/declarative/qml/v8/qjsvalue_impl_p.h @@ -1,8 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ ** ** This file is part of the QtScript module of the Qt Toolkit. ** @@ -16,7 +15,8 @@ ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. +** us via http://www.qt-project.org/. +** ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -42,6 +42,29 @@ QT_BEGIN_NAMESPACE +// This template is used indirectly by the Q_GLOBAL_STATIC macro below +template<> +class QGlobalStaticDeleter +{ +public: + QGlobalStatic &globalStatic; + QGlobalStaticDeleter(QGlobalStatic &_globalStatic) + : globalStatic(_globalStatic) + { + globalStatic.pointer.load()->ref.ref(); + } + + inline ~QGlobalStaticDeleter() + { + if (!globalStatic.pointer.load()->ref.deref()) { // Logic copy & paste from SharedDataPointer + delete globalStatic.pointer.load(); + } + globalStatic.pointer.store(0); + globalStatic.destroyed = true; + } +}; + +Q_GLOBAL_STATIC(QJSValuePrivate, InvalidValue) QJSValuePrivate* QJSValuePrivate::get(const QJSValue& q) { Q_ASSERT(q.d_ptr.data()); return q.d_ptr.data(); } @@ -803,6 +826,8 @@ inline QScriptPassPointer QJSValuePrivate::property(const QStri { if (!name.length()) return InvalidValue(); + if (!isObject()) + return InvalidValue(); v8::HandleScope handleScope; return property(QJSConverter::toString(name)); @@ -855,6 +880,26 @@ inline bool QJSValuePrivate::deleteProperty(const QString& name) return self->Delete(QJSConverter::toString(name)); } +inline bool QJSValuePrivate::hasProperty(const QString &name) const +{ + if (!isObject()) + return false; + + v8::HandleScope handleScope; + v8::Handle self(v8::Handle::Cast(m_value)); + return self->Has(QJSConverter::toString(name)); +} + +inline bool QJSValuePrivate::hasOwnProperty(const QString &name) const +{ + if (!isObject()) + return false; + + v8::HandleScope handleScope; + v8::Handle self(v8::Handle::Cast(m_value)); + return self->HasOwnProperty(QJSConverter::toString(name)); +} + inline QJSValue::PropertyFlags QJSValuePrivate::propertyFlags(const QString& name) const { if (!isObject()) @@ -929,7 +974,7 @@ QScriptPassPointer QJSValuePrivate::call(QJSValuePrivate* thisO return new QJSValuePrivate(e, result); } -inline QScriptPassPointer QJSValuePrivate::construct(int argc, v8::Handle *argv) +inline QScriptPassPointer QJSValuePrivate::callAsConstructor(int argc, v8::Handle *argv) { QV8Engine *e = engine(); @@ -950,7 +995,7 @@ inline QScriptPassPointer QJSValuePrivate::construct(int argc, return new QJSValuePrivate(e, result); } -inline QScriptPassPointer QJSValuePrivate::construct(const QJSValueList& args) +inline QScriptPassPointer QJSValuePrivate::callAsConstructor(const QJSValueList& args) { if (!isCallable()) return InvalidValue(); @@ -961,11 +1006,11 @@ inline QScriptPassPointer QJSValuePrivate::construct(const QJSV int argc = args.size(); QVarLengthArray, 8> argv(argc); if (!prepareArgumentsForCall(argv.data(), args)) { - qWarning("QJSValue::construct() failed: cannot construct function with argument created in a different engine"); + qWarning("QJSValue::callAsConstructor() failed: cannot construct function with argument created in a different engine"); return InvalidValue(); } - return construct(argc, argv.data()); + return callAsConstructor(argc, argv.data()); } /*! \internal @@ -1013,12 +1058,14 @@ bool QJSValuePrivate::assignEngine(QV8Engine* engine) /*! \internal - reinitialize this value to an invalid value. + Invalidates this value. + + Does not remove the value from the engine's list of + registered values; that's the responsibility of the caller. */ -void QJSValuePrivate::reinitialize() +void QJSValuePrivate::invalidate() { if (isJSBased()) { - m_engine->unregisterValue(this); m_value.Dispose(); m_value.Clear(); } else if (isStringBased()) { @@ -1028,26 +1075,6 @@ void QJSValuePrivate::reinitialize() m_state = Invalid; } -/*! - \internal - reinitialize this value to an JSValue. -*/ -void QJSValuePrivate::reinitialize(QV8Engine* engine, v8::Handle value) -{ - Q_ASSERT_X(this != InvalidValue(), Q_FUNC_INFO, "static invalid can't be reinitialized to a different value"); - if (isJSBased()) { - m_value.Dispose(); - // avoid double registration - m_engine->unregisterValue(this); - } else if (isStringBased()) { - delete u.m_string; - } - m_engine = engine; - m_state = JSValue; - m_value = v8::Persistent::New(value); - m_engine->registerValue(this); -} - QV8Engine* QJSValuePrivate::engine() const { return m_engine;