aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@qt.io>2017-09-15 10:14:58 +0200
committerErik Verbruggen <erik.verbruggen@qt.io>2017-09-15 10:41:08 +0000
commitacd206e317fd92f20aa4985f35288f793d05f3ac (patch)
tree0169ec7fb4adf7300c4e47f2a5372aa0b76b41a9 /src/qml/jsruntime
parentdfb3ba6329147f0d0ea22d62b9903246ce2934bd (diff)
Fix CallData setup for Script::run
By calling JSCall with an ExecutionContext as first parameter, the compiler would implicitly create a temporary Scope object in order to be able to do the call. However, the scope would then wipe the stack when it is being destructed. So subsequently retrieving argc would always result in 0 arguments. To prevent accidents like this, all Scope constructors are now explicit, and the QV4::Script's ExecutionContext is renamed from scope to context. Change-Id: Iea7930748a0544382a20b6617fa9818a8a2bea7f Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r--src/qml/jsruntime/qv4scopedvalue_p.h4
-rw-r--r--src/qml/jsruntime/qv4script.cpp14
-rw-r--r--src/qml/jsruntime/qv4script_p.h6
3 files changed, 12 insertions, 12 deletions
diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h
index 575f4e6e3f..afb5c21d36 100644
--- a/src/qml/jsruntime/qv4scopedvalue_p.h
+++ b/src/qml/jsruntime/qv4scopedvalue_p.h
@@ -87,7 +87,7 @@ struct ScopedValue;
return scope.engine->throwError(QString::fromUtf8(str))
struct Scope {
- inline Scope(ExecutionContext *ctx)
+ explicit Scope(ExecutionContext *ctx)
: engine(ctx->engine())
, mark(engine->jsStackTop)
{
@@ -99,7 +99,7 @@ struct Scope {
{
}
- inline Scope(const Managed *m)
+ explicit Scope(const Managed *m)
: engine(m->engine())
, mark(engine->jsStackTop)
{
diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp
index c3200fbcea..9850734aa1 100644
--- a/src/qml/jsruntime/qv4script.cpp
+++ b/src/qml/jsruntime/qv4script.cpp
@@ -61,7 +61,7 @@
using namespace QV4;
Script::Script(ExecutionEngine *v4, QmlContext *qml, CompiledData::CompilationUnit *compilationUnit)
- : line(1), column(0), scope(v4->rootContext()), strictMode(false), inheritContext(true), parsed(false)
+ : line(1), column(0), context(v4->rootContext()), strictMode(false), inheritContext(true), parsed(false)
, compilationUnit(compilationUnit), vmFunction(0), parseAsBinding(true)
{
if (qml)
@@ -85,7 +85,7 @@ void Script::parse()
parsed = true;
- ExecutionEngine *v4 = scope->engine();
+ ExecutionEngine *v4 = context->engine();
Scope valueScope(v4);
Module module(v4->debugger() != 0);
@@ -143,18 +143,18 @@ ReturnedValue Script::run()
if (!vmFunction)
return Encode::undefined();
- QV4::ExecutionEngine *engine = scope->engine();
+ QV4::ExecutionEngine *engine = context->engine();
QV4::Scope valueScope(engine);
if (qmlContext.isUndefined()) {
TemporaryAssignment<Function*> savedGlobalCode(engine->globalCode, vmFunction);
- ContextStateSaver stateSaver(valueScope, scope);
- scope->d()->v4Function = vmFunction;
+ ContextStateSaver stateSaver(valueScope, context);
+ context->d()->v4Function = vmFunction;
- QV4::JSCall jsCall(scope, nullptr);
+ QV4::JSCall jsCall(valueScope, nullptr);
jsCall->thisObject = engine->globalObject;
- jsCall->context = *scope;
+ jsCall->context = *context;
return vmFunction->call(jsCall);
} else {
Scoped<QmlContext> qml(valueScope, qmlContext.value());
diff --git a/src/qml/jsruntime/qv4script_p.h b/src/qml/jsruntime/qv4script_p.h
index 8d7500eb13..f3a4853fa3 100644
--- a/src/qml/jsruntime/qv4script_p.h
+++ b/src/qml/jsruntime/qv4script_p.h
@@ -91,11 +91,11 @@ struct ContextStateSaver {
struct Q_QML_EXPORT Script {
Script(ExecutionContext *scope, QV4::Compiler::CompilationMode mode, const QString &sourceCode, const QString &source = QString(), int line = 1, int column = 0)
: sourceFile(source), line(line), column(column), sourceCode(sourceCode)
- , scope(scope), strictMode(false), inheritContext(false), parsed(false), compilationMode(mode)
+ , context(scope), strictMode(false), inheritContext(false), parsed(false), compilationMode(mode)
, vmFunction(0), parseAsBinding(false) {}
Script(ExecutionEngine *engine, QmlContext *qml, const QString &sourceCode, const QString &source = QString(), int line = 1, int column = 0)
: sourceFile(source), line(line), column(column), sourceCode(sourceCode)
- , scope(engine->rootContext()), strictMode(false), inheritContext(true), parsed(false)
+ , context(engine->rootContext()), strictMode(false), inheritContext(true), parsed(false)
, vmFunction(0), parseAsBinding(true) {
if (qml)
qmlContext.set(engine, *qml);
@@ -106,7 +106,7 @@ struct Q_QML_EXPORT Script {
int line;
int column;
QString sourceCode;
- ExecutionContext *scope;
+ ExecutionContext *context;
bool strictMode;
bool inheritContext;
bool parsed;