diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp
index e3ce70e..694c30e 100644
--- a/src/declarative/qml/qdeclarativecompiler.cpp
+++ b/src/declarative/qml/qdeclarativecompiler.cpp
@@ -65,7 +65,6 @@
 #include "private/qdeclarativescriptparser_p.h"
 #include "private/qdeclarativebinding_p.h"
 #include "private/qdeclarativecompiledbindings_p.h"
-#include "private/qdeclarativeglobalscriptclass_p.h"
 
 #include <QColor>
 #include <QDebug>
@@ -2217,7 +2216,7 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj)
         if (QString::fromUtf8(prop.name).at(0).isUpper()) 
             COMPILE_EXCEPTION(&prop, tr("Property names cannot begin with an upper case letter"));
 
-        if (QDeclarativeEnginePrivate::get(engine)->globalClass->illegalNames().contains(prop.name))
+        if (QDeclarativeEnginePrivate::get(engine)->scriptEngine.illegalNames().contains(prop.name))
             COMPILE_EXCEPTION(&prop, tr("Illegal property name"));
 
         propNames.insert(prop.name);
@@ -2229,7 +2228,7 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj)
             COMPILE_EXCEPTION(obj, tr("Duplicate signal name"));
         if (QString::fromUtf8(name).at(0).isUpper()) 
             COMPILE_EXCEPTION(obj, tr("Signal names cannot begin with an upper case letter"));
-        if (QDeclarativeEnginePrivate::get(engine)->globalClass->illegalNames().contains(name))
+        if (QDeclarativeEnginePrivate::get(engine)->scriptEngine.illegalNames().contains(name))
             COMPILE_EXCEPTION(obj, tr("Illegal signal name"));
         methodNames.insert(name);
     }
@@ -2239,7 +2238,7 @@ bool QDeclarativeCompiler::checkDynamicMeta(QDeclarativeParser::Object *obj)
             COMPILE_EXCEPTION(obj, tr("Duplicate method name"));
         if (QString::fromUtf8(name).at(0).isUpper()) 
             COMPILE_EXCEPTION(obj, tr("Method names cannot begin with an upper case letter"));
-        if (QDeclarativeEnginePrivate::get(engine)->globalClass->illegalNames().contains(name))
+        if (QDeclarativeEnginePrivate::get(engine)->scriptEngine.illegalNames().contains(name))
             COMPILE_EXCEPTION(obj, tr("Illegal method name"));
         methodNames.insert(name);
     }
@@ -2517,7 +2516,7 @@ bool QDeclarativeCompiler::checkValidId(QDeclarativeParser::Value *v, const QStr
 
     }
 
-    if (enginePrivate->globalClass->illegalNames().contains(val))
+    if (enginePrivate->scriptEngine.illegalNames().contains(val))
         COMPILE_EXCEPTION(v, tr( "ID illegally masks global JavaScript property"));
 
     return true;
diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp
index 3d25291..878c6d7 100644
--- a/src/declarative/qml/qdeclarativecontext.cpp
+++ b/src/declarative/qml/qdeclarativecontext.cpp
@@ -48,7 +48,6 @@
 #include "qdeclarativeengine.h"
 #include "private/qdeclarativecompiledbindings_p.h"
 #include "qdeclarativeinfo.h"
-#include "private/qdeclarativeglobalscriptclass_p.h"
 
 #include <qscriptengine.h>
 #include <QtCore/qvarlengtharray.h>
@@ -662,7 +661,7 @@ void QDeclarativeContextData::addImportedScript(const QDeclarativeParser::Object
             QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine);
 
             scriptContext->pushScope(enginePriv->contextClass->newUrlContext(url));
-            scriptContext->pushScope(enginePriv->globalClass->staticGlobalObject());
+            scriptContext->pushScope(enginePriv->scriptEngine.qmlGlobalObject());
         
             QScriptValue scope = QScriptDeclarativeClass::newStaticScopeObject(scriptEngine);
             scriptContext->pushScope(scope);
@@ -687,7 +686,7 @@ void QDeclarativeContextData::addImportedScript(const QDeclarativeParser::Object
         QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine);
 
         scriptContext->pushScope(enginePriv->contextClass->newUrlContext(this, 0, url));
-        scriptContext->pushScope(enginePriv->globalClass->staticGlobalObject());
+        scriptContext->pushScope(enginePriv->scriptEngine.qmlGlobalObject());
 
         QScriptValue scope = QScriptDeclarativeClass::newStaticScopeObject(scriptEngine);
         scriptContext->pushScope(scope);
diff --git a/src/declarative/qml/qdeclarativecontextscriptclass.cpp b/src/declarative/qml/qdeclarativecontextscriptclass.cpp
index 1ebedbb..6bf1d25 100644
--- a/src/declarative/qml/qdeclarativecontextscriptclass.cpp
+++ b/src/declarative/qml/qdeclarativecontextscriptclass.cpp
@@ -170,6 +170,7 @@ QDeclarativeContextScriptClass::queryProperty(Object *object, const Identifier &
 {
     Q_UNUSED(flags);
     
+    lastQueryFailure = false;
     lastScopeObject = 0;
     lastContext = 0;
     lastData = 0;
@@ -177,34 +178,41 @@ QDeclarativeContextScriptClass::queryProperty(Object *object, const Identifier &
 
     QDeclarativeContextData *bindContext = ((ContextData *)object)->getContext(engine);
     QObject *scopeObject = ((ContextData *)object)->getScope(engine);
-    if (!bindContext)
-        return 0;
+    if (bindContext) {
+
+        QObject *overrideObject = ((ContextData *)object)->overrideObject;
+        if (overrideObject) {
+            QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
+            QScriptClass::QueryFlags rv = 
+                ep->objectClass->queryProperty(overrideObject, name, flags, bindContext, 
+                                               QDeclarativeObjectScriptClass::ImplicitObject | 
+                                               QDeclarativeObjectScriptClass::SkipAttachedProperties);
+            if (rv) {
+                lastScopeObject = overrideObject;
+                lastContext = bindContext;
+                return rv;
+            }
+        }
 
-    QObject *overrideObject = ((ContextData *)object)->overrideObject;
-    if (overrideObject) {
-        QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
-        QScriptClass::QueryFlags rv = 
-            ep->objectClass->queryProperty(overrideObject, name, flags, bindContext, 
-                                           QDeclarativeObjectScriptClass::ImplicitObject | 
-                                           QDeclarativeObjectScriptClass::SkipAttachedProperties);
-        if (rv) {
-            lastScopeObject = overrideObject;
-            lastContext = bindContext;
-            return rv;
+        bool includeTypes = true;
+        while (bindContext) {
+            QScriptClass::QueryFlags rv = 
+                queryProperty(bindContext, scopeObject, name, flags, includeTypes);
+            scopeObject = 0; // Only applies to the first context
+            includeTypes = false; // Only applies to the first context
+            if (rv) return rv;
+            bindContext = bindContext->parent;
         }
-    }
 
-    bool includeTypes = true;
-    while (bindContext) {
-        QScriptClass::QueryFlags rv = 
-            queryProperty(bindContext, scopeObject, name, flags, includeTypes);
-        scopeObject = 0; // Only applies to the first context
-        includeTypes = false; // Only applies to the first context
-        if (rv) return rv;
-        bindContext = bindContext->parent;
     }
 
-    return 0;
+    QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
+    if (!hasGlobalProperty(scriptEngine, name)) {
+        lastQueryFailure = true;
+        return QScriptClass::HandlesReadAccess | QScriptClass::HandlesWriteAccess;
+    } else {
+        return 0;
+    }
 }
 
 QScriptClass::QueryFlags 
@@ -268,7 +276,11 @@ QDeclarativeContextScriptClass::property(Object *object, const Identifier &name)
     QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
     QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
 
-    if (lastScopeObject) {
+    if (lastQueryFailure) {
+        QString error = QLatin1String("Can't find variable: ") + toString(name);
+        scriptEngine->currentContext()->throwError(QScriptContext::ReferenceError, error);
+        return Value();
+    } else if (lastScopeObject) {
 
         return ep->objectClass->property(lastScopeObject, name);
 
@@ -329,7 +341,14 @@ void QDeclarativeContextScriptClass::setProperty(Object *object, const Identifie
 
     QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
 
-    ep->objectClass->setProperty(lastScopeObject, name, value, context(), bindContext);
+    if (lastQueryFailure) {
+        QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
+        QString error = QLatin1String("Invalid write to global property \"") + 
+                        toString(name) + QLatin1Char('\"');
+        scriptEngine->currentContext()->throwError(error);
+    } else {
+        ep->objectClass->setProperty(lastScopeObject, name, value, context(), bindContext);
+    }
 }
 
 QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativecontextscriptclass_p.h b/src/declarative/qml/qdeclarativecontextscriptclass_p.h
index 1215b00..a8072ab 100644
--- a/src/declarative/qml/qdeclarativecontextscriptclass_p.h
+++ b/src/declarative/qml/qdeclarativecontextscriptclass_p.h
@@ -91,6 +91,7 @@ private:
 
     QDeclarativeEngine *engine;
 
+    bool lastQueryFailure;
     QObject *lastScopeObject;
     QDeclarativeContextData *lastContext;
     QDeclarativeTypeNameCache::Data *lastData;
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index 8bf7450..9dc87fd 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -44,7 +44,6 @@
 
 #include "private/qdeclarativecontext_p.h"
 #include "private/qdeclarativecompiler_p.h"
-#include "private/qdeclarativeglobalscriptclass_p.h"
 #include "qdeclarative.h"
 #include "qdeclarativecontext.h"
 #include "qdeclarativeexpression.h"
@@ -71,6 +70,7 @@
 
 #include <QtCore/qmetaobject.h>
 #include <QScriptClass>
+#include <QScriptValueIterator>
 #include <QNetworkReply>
 #include <QNetworkRequest>
 #include <QNetworkAccessManager>
@@ -221,10 +221,10 @@ of their use.
 QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e)
 : captureProperties(false), rootContext(0), currentExpression(0), isDebugging(false),
   outputWarningsToStdErr(true), contextClass(0), sharedContext(0), sharedScope(0),
-  objectClass(0), valueTypeClass(0), globalClass(0), cleanup(0), erroredBindings(0),
-  inProgressCreations(0), scriptEngine(this), workerScriptEngine(0), componentAttached(0),
-  inBeginCreate(false), networkAccessManager(0), networkAccessManagerFactory(0),
-  typeManager(e), importDatabase(e), uniqueId(1)
+  objectClass(0), valueTypeClass(0), cleanup(0), erroredBindings(0), inProgressCreations(0), 
+  scriptEngine(this), workerScriptEngine(0), componentAttached(0), inBeginCreate(false), 
+  networkAccessManager(0), networkAccessManagerFactory(0), typeManager(e), importDatabase(e), 
+  uniqueId(1)
 {
     if (!qt_QmlQtModule_registered) {
         qt_QmlQtModule_registered = true;
@@ -233,7 +233,6 @@ QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e)
         QDeclarativeEnginePrivate::defineModule();
         QDeclarativeValueTypeFactory::registerValueTypes();
     }
-    globalClass = new QDeclarativeGlobalScriptClass(&scriptEngine);
 }
 
 /*!
@@ -258,9 +257,13 @@ QDeclarativeScriptEngine::QDeclarativeScriptEngine(QDeclarativeEnginePrivate *pr
 
     bool mainthread = priv != 0;
 
-    QScriptValue qtObject =
-        newQMetaObject(StaticQtMetaObject::get());
-    globalObject().setProperty(QLatin1String("Qt"), qtObject);
+    // First remove the various properties we don't want
+    QScriptEngine::setGlobalObject(cloneGlobal());
+
+    QScriptValue globalObject = QScriptEngine::globalObject();
+
+    QScriptValue qtObject = newQMetaObject(StaticQtMetaObject::get());
+    globalObject.setProperty(QLatin1String("Qt"), qtObject);
 
 #ifndef QT_NO_DESKTOPSERVICES
     offlineStoragePath = QDesktopServices::storageLocation(QDesktopServices::DataLocation).replace(QLatin1Char('/'), QDir::separator())
@@ -323,11 +326,14 @@ QDeclarativeScriptEngine::QDeclarativeScriptEngine(QDeclarativeEnginePrivate *pr
     QScriptValue consoleObject = newObject();
     consoleObject.setProperty(QLatin1String("log"),newFunction(QDeclarativeEnginePrivate::consoleLog, 1));
     consoleObject.setProperty(QLatin1String("debug"),newFunction(QDeclarativeEnginePrivate::consoleLog, 1));
-    globalObject().setProperty(QLatin1String("console"), consoleObject);
+    globalObject.setProperty(QLatin1String("console"), consoleObject);
 
     // translation functions need to be installed
     // before the global script class is constructed (QTBUG-6437)
-    installTranslatorFunctions();
+    installTranslatorFunctions(globalObject);
+
+    if (mainthread)
+        createQmlGlobalObject(globalObject);
 }
 
 QDeclarativeScriptEngine::~QDeclarativeScriptEngine()
@@ -337,6 +343,47 @@ QDeclarativeScriptEngine::~QDeclarativeScriptEngine()
     delete namedNodeMapClass;
 }
 
+QScriptValue QDeclarativeScriptEngine::cloneGlobal() 
+{
+    QString version = QLatin1String("version");
+
+    QScriptValue object = newObject();
+    QScriptValue originalGlobalObject = globalObject();
+
+    QScriptValueIterator iter(originalGlobalObject);
+    while (iter.hasNext()) {
+        iter.next();
+        object.setProperty(iter.scriptName(), iter.value(), iter.flags());
+    }
+
+    return object;
+}
+
+void QDeclarativeScriptEngine::createQmlGlobalObject(const QScriptValue &object)
+{
+    QString eval = QLatin1String("eval");
+
+    QScriptValueIterator iter(object);
+    QVector<QString> names;
+    QVector<QScriptValue> values;
+    QVector<QScriptValue::PropertyFlags> flags;
+    while (iter.hasNext()) {
+        iter.next();
+        QString name = iter.name();
+
+        if (name != eval) {
+            names.append(name);
+            values.append(iter.value());
+            flags.append(iter.flags() | QScriptValue::Undeletable);
+        }
+
+        m_illegalNames.insert(name);
+    }
+    m_qmlGlobalObject = 
+        QScriptDeclarativeClass::newStaticScopeObject(this, names.size(), names.constData(), 
+                                                      values.constData(), flags.constData());
+}
+
 QScriptValue QDeclarativeScriptEngine::resolvedUrl(QScriptContext *ctxt, QScriptEngine *engine)
 {
     QString arg = ctxt->argument(0).toString();
@@ -376,8 +423,6 @@ QDeclarativeEnginePrivate::~QDeclarativeEnginePrivate()
     typeNameClass = 0;
     delete listClass;
     listClass = 0;
-    delete globalClass;
-    globalClass = 0;
 
     for(QHash<int, QDeclarativeCompiledData*>::ConstIterator iter = m_compositeTypes.constBegin(); iter != m_compositeTypes.constEnd(); ++iter)
         (*iter)->release();
@@ -741,6 +786,13 @@ void QDeclarativeEngine::setOutputWarningsToStandardError(bool enabled)
     d->outputWarningsToStdErr = enabled;
 }
 
+/*! \internal */
+QScriptEngine *QDeclarativeEngine::scriptEngine() const
+{
+    Q_D(const QDeclarativeEngine);
+    return const_cast<QDeclarativeScriptEngine *>(&d->scriptEngine);
+}
+
 /*!
   Returns the QDeclarativeContext for the \a object, or 0 if no
   context has been set.
diff --git a/src/declarative/qml/qdeclarativeengine.h b/src/declarative/qml/qdeclarativeengine.h
index 01487f5..fb2fd86 100644
--- a/src/declarative/qml/qdeclarativeengine.h
+++ b/src/declarative/qml/qdeclarativeengine.h
@@ -106,6 +106,8 @@ public:
     bool outputWarningsToStandardError() const;
     void setOutputWarningsToStandardError(bool);
 
+    QScriptEngine *scriptEngine() const;
+
     static QDeclarativeContext *contextForObject(const QObject *);
     static void setContextForObject(QObject *, QDeclarativeContext *);
 
diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h
index cfa9d73..f357e21 100644
--- a/src/declarative/qml/qdeclarativeengine_p.h
+++ b/src/declarative/qml/qdeclarativeengine_p.h
@@ -135,6 +135,16 @@ public:
     QUrl baseUrl;
 
     virtual QNetworkAccessManager *networkAccessManager();
+
+    const QScriptValue &qmlGlobalObject() const { return m_qmlGlobalObject; }
+    const QSet<QString> &illegalNames() const { return m_illegalNames; }
+
+private:
+    QScriptValue cloneGlobal();
+    void createQmlGlobalObject(const QScriptValue &);
+
+    QSet<QString> m_illegalNames;
+    QScriptValue m_qmlGlobalObject;
 };
 
 class Q_AUTOTEST_EXPORT QDeclarativeEnginePrivate : public QObjectPrivate
@@ -173,8 +183,6 @@ public:
     QDeclarativeValueTypeScriptClass *valueTypeClass;
     QDeclarativeTypeNameScriptClass *typeNameClass;
     QDeclarativeListScriptClass *listClass;
-    // Global script class
-    QDeclarativeGlobalScriptClass *globalClass;
 
     // Registered cleanup handlers
     QDeclarativeCleanup *cleanup;
diff --git a/src/declarative/qml/qdeclarativeexpression.cpp b/src/declarative/qml/qdeclarativeexpression.cpp
index 96cdec1..864bda2 100644
--- a/src/declarative/qml/qdeclarativeexpression.cpp
+++ b/src/declarative/qml/qdeclarativeexpression.cpp
@@ -46,7 +46,6 @@
 #include "private/qdeclarativecontext_p.h"
 #include "private/qdeclarativerewrite_p.h"
 #include "private/qdeclarativecompiler_p.h"
-#include "private/qdeclarativeglobalscriptclass_p.h"
 
 #include <QtCore/qdebug.h>
 #include <QtScript/qscriptprogram.h>
@@ -145,7 +144,7 @@ void QDeclarativeExpressionPrivate::init(QDeclarativeContextData *ctxt, void *ex
         if (!dd->cachedClosures.at(progIdx)) {
             QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine);
             scriptContext->pushScope(ep->contextClass->newSharedContext());
-            scriptContext->pushScope(ep->globalClass->staticGlobalObject());
+            scriptContext->pushScope(ep->scriptEngine.qmlGlobalObject());
             dd->cachedClosures[progIdx] = new QScriptValue(scriptEngine->evaluate(data->expression, data->url, data->line));
             scriptEngine->popContext();
         }
@@ -188,7 +187,7 @@ QScriptValue QDeclarativeExpressionPrivate::evalInObjectScope(QDeclarativeContex
     } else {
         scriptContext->pushScope(ep->contextClass->newContext(context, object));
     }
-    scriptContext->pushScope(ep->globalClass->staticGlobalObject());
+    scriptContext->pushScope(ep->scriptEngine.qmlGlobalObject());
     QScriptValue rv = ep->scriptEngine.evaluate(program, fileName, lineNumber);
     ep->scriptEngine.popContext();
     return rv;
@@ -206,7 +205,7 @@ QScriptValue QDeclarativeExpressionPrivate::evalInObjectScope(QDeclarativeContex
     } else {
         scriptContext->pushScope(ep->contextClass->newContext(context, object));
     }
-    scriptContext->pushScope(ep->globalClass->staticGlobalObject());
+    scriptContext->pushScope(ep->scriptEngine.qmlGlobalObject());
     QScriptValue rv = ep->scriptEngine.evaluate(program);
     ep->scriptEngine.popContext();
     return rv;
@@ -391,7 +390,7 @@ QScriptValue QDeclarativeExpressionPrivate::eval(QObject *secondaryScope, bool *
         QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine);
         data->expressionContext = ep->contextClass->newContext(data->context(), data->me);
         scriptContext->pushScope(data->expressionContext);
-        scriptContext->pushScope(ep->globalClass->staticGlobalObject());
+        scriptContext->pushScope(ep->scriptEngine.qmlGlobalObject());
 
         if (data->expressionRewritten) {
             data->expressionFunction = scriptEngine->evaluate(data->expression, 
diff --git a/src/declarative/qml/qdeclarativeinclude.cpp b/src/declarative/qml/qdeclarativeinclude.cpp
index f26b54f..f3998b3 100644
--- a/src/declarative/qml/qdeclarativeinclude.cpp
+++ b/src/declarative/qml/qdeclarativeinclude.cpp
@@ -47,7 +47,6 @@
 #include <QtCore/qfile.h>
 
 #include <private/qdeclarativeengine_p.h>
-#include <private/qdeclarativeglobalscriptclass_p.h>
 
 QT_BEGIN_NAMESPACE
 
@@ -240,7 +239,7 @@ QScriptValue QDeclarativeInclude::include(QScriptContext *ctxt, QScriptEngine *e
 
             QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(engine);
             scriptContext->pushScope(ep->contextClass->newUrlContext(context, 0, urlString));
-            scriptContext->pushScope(ep->globalClass->staticGlobalObject());
+            scriptContext->pushScope(ep->scriptEngine.qmlGlobalObject());
             QScriptValue scope = QScriptDeclarativeClass::scopeChainValue(ctxt, -5);
             scriptContext->pushScope(scope);
             scriptContext->setActivationObject(scope);
diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri
index 12f9794..133e2f7 100644
--- a/src/declarative/qml/qml.pri
+++ b/src/declarative/qml/qml.pri
@@ -46,7 +46,6 @@ SOURCES += \
     $$PWD/qdeclarativescriptstring.cpp \
     $$PWD/qdeclarativeobjectscriptclass.cpp \
     $$PWD/qdeclarativecontextscriptclass.cpp \
-    $$PWD/qdeclarativeglobalscriptclass.cpp \
     $$PWD/qdeclarativevaluetypescriptclass.cpp \
     $$PWD/qdeclarativetypenamescriptclass.cpp \
     $$PWD/qdeclarativelistscriptclass.cpp \
@@ -121,7 +120,6 @@ HEADERS += \
     $$PWD/qdeclarativescriptstring.h \
     $$PWD/qdeclarativeobjectscriptclass_p.h \
     $$PWD/qdeclarativecontextscriptclass_p.h \
-    $$PWD/qdeclarativeglobalscriptclass_p.h \
     $$PWD/qdeclarativevaluetypescriptclass_p.h \
     $$PWD/qdeclarativetypenamescriptclass_p.h \
     $$PWD/qdeclarativelistscriptclass_p.h \
diff --git a/src/script/bridge/qscriptdeclarativeclass.cpp b/src/script/bridge/qscriptdeclarativeclass.cpp
index 8080b9f..de5b315 100644
--- a/src/script/bridge/qscriptdeclarativeclass.cpp
+++ b/src/script/bridge/qscriptdeclarativeclass.cpp
@@ -332,6 +332,24 @@ QScriptDeclarativeClass::propertyValue(const QScriptValue &v, const Identifier &
     return Value();
 }
 
+bool QScriptDeclarativeClass::hasGlobalProperty(QScriptEngine *engine, const Identifier &name)
+{
+    QScriptEnginePrivate *p = QScriptEnginePrivate::get(engine);
+
+    QScript::APIShim shim(p);
+    JSC::ExecState *exec = p->currentFrame;
+    JSC::JSObject *object = p->originalGlobalObject();
+    JSC::PropertySlot slot;
+
+    JSC::Identifier id(exec, (JSC::UString::Rep *)name);
+
+    if (const_cast<JSC::JSObject*>(object)->getOwnPropertySlot(exec, id, slot)) {
+        return true;
+    } else {
+        return false;
+    }
+}
+
 /*
 Returns the scope chain entry at \a index.  If index is less than 0, returns
 entries starting at the end.  For example, scopeChainValue(context, -1) will return
diff --git a/src/script/bridge/qscriptdeclarativeclass_p.h b/src/script/bridge/qscriptdeclarativeclass_p.h
index 420b133..e3d0f5f 100644
--- a/src/script/bridge/qscriptdeclarativeclass_p.h
+++ b/src/script/bridge/qscriptdeclarativeclass_p.h
@@ -88,6 +88,7 @@ public:
     static QScriptValue property(const QScriptValue &, const Identifier &);
     static Value functionValue(const QScriptValue &, const Identifier &);
     static Value propertyValue(const QScriptValue &, const Identifier &);
+    static bool hasGlobalProperty(QScriptEngine *, const Identifier &);
 
     static QScriptValue scopeChainValue(QScriptContext *, int index);
     static QScriptContext *pushCleanContext(QScriptEngine *);
diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
index a6d2dac..29cc2d2 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
@@ -49,7 +49,6 @@
 #include <QtCore/qdir.h>
 #include <QtCore/qnumeric.h>
 #include <private/qdeclarativeengine_p.h>
-#include <private/qdeclarativeglobalscriptclass_p.h>
 #include "testtypes.h"
 #include "testhttpserver.h"
 
@@ -1323,13 +1322,10 @@ void tst_qdeclarativeecmascript::callQtInvokables()
 
     QDeclarativeEngine qmlengine;
     QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(&qmlengine);
-    QScriptEngine *engine = &ep->scriptEngine;
+    QScriptEngine *engine = qmlengine.scriptEngine();
 
-    QStringList names; QList<QScriptValue> values;
-    names << QLatin1String("object"); values << ep->objectClass->newQObject(&o);
-    names << QLatin1String("undefined"); values << engine->undefinedValue();
-
-    ep->globalClass->explicitSetProperty(names, values);
+    qmlengine.scriptEngine()->globalObject().setProperty("object", ep->objectClass->newQObject(&o));
+    qmlengine.scriptEngine()->globalObject().setProperty("undefined", engine->undefinedValue());
 
     // Non-existent methods
     o.reset();
diff --git a/tests/auto/declarative/qdeclarativexmlhttprequest/data/defaultState.qml b/tests/auto/declarative/qdeclarativexmlhttprequest/data/defaultState.qml
index d66f283..a36aff9 100644
--- a/tests/auto/declarative/qdeclarativexmlhttprequest/data/defaultState.qml
+++ b/tests/auto/declarative/qdeclarativexmlhttprequest/data/defaultState.qml
@@ -12,13 +12,13 @@ QtObject {
 
         readyState = xhr.readyState;
         try {
-            status = xhr.status;
+            var status = xhr.status;
         } catch (error) {
             if (error.code == DOMException.INVALID_STATE_ERR)
                 statusIsException = true;
         }
         try {
-            statusText = xhr.statusText;
+            var statusText = xhr.statusText;
         } catch (error) {
             if (error.code == DOMException.INVALID_STATE_ERR)
                 statusTextIsException = true;
