include files in the caller's context

svn path=/trunk/KDE/kdebase/runtime/; revision=1075353
This commit is contained in:
Aaron J. Seigo 2010-01-15 22:23:00 +00:00
parent 049da47b89
commit cfb3f78aee

View File

@ -74,7 +74,17 @@ bool ScriptEnv::include(const QString &path)
QString script = file.readAll();
//kDebug() << "Script says" << script;
evaluate(script);
// change the context to the parent context so that the include is actually
// executed in the same context as the caller; seems to be what javascript
// coders expect :)
QScriptContext *ctx = currentContext();
if (ctx && ctx->parentContext()) {
ctx->setActivationObject(ctx->parentContext()->activationObject());
ctx->setThisObject(ctx->parentContext()->thisObject());
}
evaluate(script, path);
if (hasUncaughtException()) {
emit reportError(this, true);
return false;