diff options
Diffstat (limited to 'src/declarative/qml/qdeclarativeglobalscriptclass.cpp')
-rw-r--r-- | src/declarative/qml/qdeclarativeglobalscriptclass.cpp | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/src/declarative/qml/qdeclarativeglobalscriptclass.cpp b/src/declarative/qml/qdeclarativeglobalscriptclass.cpp index 3e22c82..d43443d 100644 --- a/src/declarative/qml/qdeclarativeglobalscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeglobalscriptclass.cpp @@ -42,10 +42,13 @@ #include "private/qdeclarativeglobalscriptclass_p.h" #include <QtCore/qstringlist.h> +#include <QtCore/qvector.h> #include <QtScript/qscriptstring.h> #include <QtScript/qscriptengine.h> #include <QtScript/qscriptvalueiterator.h> +#include <private/qscriptdeclarativeclass_p.h> + QT_BEGIN_NAMESPACE /* @@ -57,26 +60,34 @@ QDeclarativeGlobalScriptClass::QDeclarativeGlobalScriptClass(QScriptEngine *engi QString eval = QLatin1String("eval"); QString version = QLatin1String("version"); - QScriptValue globalObject = engine->globalObject(); + QScriptValue originalGlobalObject = engine->globalObject(); - m_globalObject = engine->newObject(); QScriptValue newGlobalObject = engine->newObject(); - QScriptValueIterator iter(globalObject); - - while (iter.hasNext()) { - iter.next(); - - QString name = iter.name(); - - if (name == version) - continue; - - if (name != eval) - m_globalObject.setProperty(iter.scriptName(), iter.value()); - newGlobalObject.setProperty(iter.scriptName(), iter.value()); - - m_illegalNames.insert(name); + { + QScriptValueIterator iter(originalGlobalObject); + QVector<QString> names; + QVector<QScriptValue> values; + QVector<QScriptValue::PropertyFlags> flags; + while (iter.hasNext()) { + iter.next(); + + QString name = iter.name(); + + if (name == version) + continue; + + if (name != eval) { + names.append(name); + values.append(iter.value()); + flags.append(iter.flags() | QScriptValue::Undeletable); + } + newGlobalObject.setProperty(iter.scriptName(), iter.value()); + + m_illegalNames.insert(name); + } + m_staticGlobalObject = QScriptDeclarativeClass::newStaticScopeObject( + engine, names.size(), names.constData(), values.constData(), flags.constData()); } newGlobalObject.setScriptClass(this); |