From 35249faad6f1fbb38b868d1a4a8be9bb3fff2ba1 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Fri, 15 Jan 2010 23:18:08 +0000 Subject: [PATCH] include files in the caller's context svn path=/branches/KDE/4.4/kdebase/runtime/; revision=1075375 --- scriptengines/javascript/simplejavascriptapplet.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/scriptengines/javascript/simplejavascriptapplet.cpp b/scriptengines/javascript/simplejavascriptapplet.cpp index b2bc679cc..1b8aa9051 100644 --- a/scriptengines/javascript/simplejavascriptapplet.cpp +++ b/scriptengines/javascript/simplejavascriptapplet.cpp @@ -281,7 +281,16 @@ bool SimpleJavaScriptApplet::include(const QString &path) QString script = file.readAll(); //kDebug() << "Script says" << script; - m_engine->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 = m_engine->currentContext(); + if (ctx && ctx->parentContext()) { + ctx->setActivationObject(ctx->parentContext()->activationObject()); + ctx->setThisObject(ctx->parentContext()->thisObject()); + } + + m_engine->evaluate(script, path); if (m_engine->hasUncaughtException()) { reportError(m_engine, true); return false;