/****************************************************************************
**
-** 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.
**
** 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$
**
****************************************************************************/
QT_BEGIN_NAMESPACE
+// This template is used indirectly by the Q_GLOBAL_STATIC macro below
+template<>
+class QGlobalStaticDeleter<QJSValuePrivate>
+{
+public:
+ QGlobalStatic<QJSValuePrivate> &globalStatic;
+ QGlobalStaticDeleter(QGlobalStatic<QJSValuePrivate> &_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(); }
{
if (!name.length())
return InvalidValue();
+ if (!isObject())
+ return InvalidValue();
v8::HandleScope handleScope;
return property(QJSConverter::toString(name));
return self->Delete(QJSConverter::toString(name));
}
+inline bool QJSValuePrivate::hasProperty(const QString &name) const
+{
+ if (!isObject())
+ return false;
+
+ v8::HandleScope handleScope;
+ v8::Handle<v8::Object> self(v8::Handle<v8::Object>::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<v8::Object> self(v8::Handle<v8::Object>::Cast(m_value));
+ return self->HasOwnProperty(QJSConverter::toString(name));
+}
+
inline QJSValue::PropertyFlags QJSValuePrivate::propertyFlags(const QString& name) const
{
if (!isObject())
return new QJSValuePrivate(e, result);
}
-inline QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::construct(int argc, v8::Handle<v8::Value> *argv)
+inline QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::callAsConstructor(int argc, v8::Handle<v8::Value> *argv)
{
QV8Engine *e = engine();
return new QJSValuePrivate(e, result);
}
-inline QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::construct(const QJSValueList& args)
+inline QScriptPassPointer<QJSValuePrivate> QJSValuePrivate::callAsConstructor(const QJSValueList& args)
{
if (!isCallable())
return InvalidValue();
int argc = args.size();
QVarLengthArray<v8::Handle<v8::Value>, 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
/*!
\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()) {
m_state = Invalid;
}
-/*!
- \internal
- reinitialize this value to an JSValue.
-*/
-void QJSValuePrivate::reinitialize(QV8Engine* engine, v8::Handle<v8::Value> 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<v8::Value>::New(value);
- m_engine->registerValue(this);
-}
-
QV8Engine* QJSValuePrivate::engine() const
{
return m_engine;