diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-08-10 12:38:22 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-08-10 12:39:32 (GMT) |
commit | 70f320f661a0241fcb5fc85f5b9df8e565f5f7e0 (patch) | |
tree | 6a305679da8b8584c123150607ae1cc4168de6a6 /src/script/api | |
parent | aa3aeaee694fb5f15fb8beb32dafdaca97361563 (diff) | |
download | Qt-70f320f661a0241fcb5fc85f5b9df8e565f5f7e0.zip Qt-70f320f661a0241fcb5fc85f5b9df8e565f5f7e0.tar.gz Qt-70f320f661a0241fcb5fc85f5b9df8e565f5f7e0.tar.bz2 |
finish implementation of QScriptEngine::importExtension()
Added the properties to the activation object: __extension__,
__setupPackage__ and __postInit__.
Diffstat (limited to 'src/script/api')
-rw-r--r-- | src/script/api/qscriptengine.cpp | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index fa6e8dd..f84e36e 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -777,6 +777,25 @@ JSC::JSValue stringProtoFuncArg(JSC::ExecState *exec, JSC::JSObject*, JSC::JSVal } +#if !defined(QT_NO_QOBJECT) && !defined(QT_NO_LIBRARY) +static QScriptValue __setupPackage__(QScriptContext *ctx, QScriptEngine *eng) +{ + QString path = ctx->argument(0).toString(); + QStringList components = path.split(QLatin1Char('.')); + QScriptValue o = eng->globalObject(); + for (int i = 0; i < components.count(); ++i) { + QString name = components.at(i); + QScriptValue oo = o.property(name); + if (!oo.isValid()) { + oo = eng->newObject(); + o.setProperty(name, oo); + } + o = oo; + } + return o; +} +#endif + QScriptPushScopeHelper::QScriptPushScopeHelper(JSC::CallFrame *exec, bool calledAsConstructor) { engine = scriptEngineFromExec(exec); @@ -1024,7 +1043,6 @@ QScriptContext *QScriptEnginePrivate::contextForFrame(JSC::ExecState *frame) return reinterpret_cast<QScriptContext *>(frame); } - JSC::JSGlobalObject *QScriptEnginePrivate::originalGlobalObject() const { return globalData->head; @@ -2937,27 +2955,11 @@ QScriptValue QScriptEngine::importExtension(const QString &extension) // initialize the extension in a new context QScriptContext *ctx = pushContext(); ctx->setThisObject(globalObject()); -#if 0 // ### implement me - ctx->setActivationObject(newActivationObject()); - QScriptObject *activation_data = ctx_p->m_activation.m_object_value; - activation_data->m_scope = globalObject(); - - activation_data->m_members.resize(4); - activation_data->m_values.resize(4); - activation_data->m_members[0].object( - nameId(QLatin1String("__extension__")), 0, - QScriptValue::ReadOnly | QScriptValue::Undeletable); - activation_data->m_values[0] = QScriptValueImpl(this, ext); - activation_data->m_members[1].object( - nameId(QLatin1String("__setupPackage__")), 1, 0); - activation_data->m_values[1] = createFunction(__setupPackage__, 0, 0); - activation_data->m_members[2].object( - nameId(QLatin1String("__all__")), 2, 0); - activation_data->m_values[2] = undefinedValue(); - activation_data->m_members[3].object( - nameId(QLatin1String("__postInit__")), 3, 0); - activation_data->m_values[3] = undefinedValue(); -#endif + ctx->activationObject().setProperty(QLatin1String("__extension__"), ext, + QScriptValue::ReadOnly | QScriptValue::Undeletable); + ctx->activationObject().setProperty(QLatin1String("__setupPackage__"), + newFunction(QScript::__setupPackage__)); + ctx->activationObject().setProperty(QLatin1String("__postInit__"), QScriptValue(QScriptValue::UndefinedValue)); // the script is evaluated first if (!initjsContents.isEmpty()) { @@ -2981,8 +2983,7 @@ QScriptValue QScriptEngine::importExtension(const QString &extension) } // if the __postInit__ function has been set, we call it - // ### enable once activationObject() works - QScriptValue postInit; // = ctx->activationObject().property(QLatin1String("__postInit__")); + QScriptValue postInit = ctx->activationObject().property(QLatin1String("__postInit__")); if (postInit.isFunction()) { postInit.call(globalObject()); if (hasUncaughtException()) { |