summaryrefslogtreecommitdiffstats
path: root/src/script/api/qscriptengine.cpp
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-07-29 07:51:07 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-07-29 09:16:18 (GMT)
commit538153994cacc4613aef1eb8ef77e501be7f5a88 (patch)
tree5b1ae7732aa02e50d85a9f10280d3335f98e673b /src/script/api/qscriptengine.cpp
parent9e4aa947217d92c51d09a6adaddaf88829d42f89 (diff)
downloadQt-538153994cacc4613aef1eb8ef77e501be7f5a88.zip
Qt-538153994cacc4613aef1eb8ef77e501be7f5a88.tar.gz
Qt-538153994cacc4613aef1eb8ef77e501be7f5a88.tar.bz2
Enter a scope when enterning a native function.
so native function that would call engine->evaluate("var b = 'foo'); would not change the global object. The change in qscriptengine.cpp makes sure that the correct scope is used for the execution of QScriptEngine::evaluate. The changes in qscriptfunction.cpp push a new scope for native function calls. We might want to move that into QScriptContext later Reviewed-by: Kent Hansen
Diffstat (limited to 'src/script/api/qscriptengine.cpp')
-rw-r--r--src/script/api/qscriptengine.cpp34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp
index 01cf50b..d6f1a83 100644
--- a/src/script/api/qscriptengine.cpp
+++ b/src/script/api/qscriptengine.cpp
@@ -39,6 +39,7 @@
#include "SourceCode.h"
#include "FunctionPrototype.h"
#include "JSFunction.h"
+#include "Parser.h"
#include "utils/qscriptdate_p.h"
#include "bridge/qscriptfunction_p.h"
@@ -2189,27 +2190,36 @@ QScriptValue QScriptEngine::evaluate(const QString &program, const QString &file
JSC::UString jscProgram = QScript::qtStringToJSCUString(program);
JSC::UString jscFileName = QScript::qtStringToJSCUString(fileName);
-
JSC::ExecState* exec = d->currentFrame;
+ JSC::SourceCode source = JSC::makeSource(jscProgram, jscFileName, lineNumber);
+
exec->clearException();
- JSC::ScopeChain scopeChain = JSC::ScopeChain(exec->scopeChain());
JSC::DynamicGlobalObjectScope dynamicGlobalObjectScope(exec, exec->scopeChain()->globalObject());
- JSC::Completion comp = JSC::evaluate(exec, scopeChain,
- JSC::makeSource(jscProgram, jscFileName, lineNumber),
- d->thisForContext(exec));
- if ((comp.complType() == JSC::Normal) || (comp.complType() == JSC::ReturnValue)) {
- Q_ASSERT(!exec->hadException());
- return d->scriptValueFromJSCValue(comp.value());
+
+ int errorLine;
+ JSC::UString errorMessage;
+ WTF::RefPtr<JSC::EvalNode> evalNode = exec->globalData().parser->parse<JSC::EvalNode>(exec, exec->dynamicGlobalObject()->debugger(), source, &errorLine, &errorMessage);
+ if (!evalNode) {
+ JSC::JSValue exceptionValue = JSC::Error::create(exec, JSC::SyntaxError, errorMessage, errorLine, source.provider()->asID(), 0);
+ exec->setException(exceptionValue);
+ return d->scriptValueFromJSCValue(exceptionValue);
}
- if (comp.complType() == JSC::Throw) {
- exec->setException(comp.value());
- return d->scriptValueFromJSCValue(comp.value());
+ JSC::JSValue thisValue = d->thisForContext(exec);
+ JSC::JSObject* thisObject = (!thisValue || thisValue.isUndefinedOrNull()) ? exec->dynamicGlobalObject() : thisValue.toObject(exec);
+ JSC::JSValue exceptionValue;
+ JSC::JSValue result = exec->interpreter()->execute(evalNode.get(), exec, thisObject, exec->scopeChain(), &exceptionValue);
+
+ if (exceptionValue) {
+ exec->setException(exceptionValue);
+ return d->scriptValueFromJSCValue(exceptionValue);
}
- return QScriptValue();
+ Q_ASSERT(!exec->hadException());
+ return d->scriptValueFromJSCValue(result);
}
+
/*!
Returns the current context.