diff --git a/scriptengines/javascript/scriptenv.cpp b/scriptengines/javascript/scriptenv.cpp index 19deb31b8..fc15e21ef 100644 --- a/scriptengines/javascript/scriptenv.cpp +++ b/scriptengines/javascript/scriptenv.cpp @@ -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;