diff options
Diffstat (limited to 'src/qml/jsruntime/qv4scopedvalue_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4scopedvalue_p.h | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h index a6f7f8e0e7..aa811ddba4 100644 --- a/src/qml/jsruntime/qv4scopedvalue_p.h +++ b/src/qml/jsruntime/qv4scopedvalue_p.h @@ -71,14 +71,18 @@ struct ScopedValue; struct Scope { inline Scope(ExecutionContext *ctx) : engine(ctx->d()->engine) + , mark(engine->jsStackTop) + , result(*engine->jsAlloca(1)) { - mark = engine->jsStackTop; + result = Encode::undefined(); } explicit Scope(ExecutionEngine *e) : engine(e) + , mark(engine->jsStackTop) + , result(*engine->jsAlloca(1)) { - mark = engine->jsStackTop; + result = Encode::undefined(); } ~Scope() { @@ -93,7 +97,7 @@ struct Scope { engine->jsStackTop = mark; } - Value *alloc(int nValues) { + Value *alloc(int nValues) const { return engine->jsAlloca(nValues); } @@ -103,6 +107,7 @@ struct Scope { ExecutionEngine *engine; Value *mark; + Value &result; private: Q_DISABLE_COPY(Scope) @@ -190,59 +195,59 @@ struct Scoped Scoped(const Scope &scope) { - ptr = scope.engine->jsStackTop++; - ptr->setM(0); + ptr = scope.engine->jsAlloca(1); } Scoped(const Scope &scope, const Value &v) { - ptr = scope.engine->jsStackTop++; + ptr = scope.engine->jsAlloca(1); setPointer(v.as<T>()); } Scoped(const Scope &scope, Heap::Base *o) { Value v; v = o; - ptr = scope.engine->jsStackTop++; + ptr = scope.engine->jsAlloca(1); setPointer(v.as<T>()); } Scoped(const Scope &scope, const ScopedValue &v) { - ptr = scope.engine->jsStackTop++; + ptr = scope.engine->jsAlloca(1); setPointer(v.ptr->as<T>()); } Scoped(const Scope &scope, const Value &v, ConvertType) { - ptr = scope.engine->jsStackTop++; + ptr = scope.engine->jsAlloca(1); ptr->setRawValue(value_convert<T>(scope.engine, v)); } Scoped(const Scope &scope, const Value *v) { - ptr = scope.engine->jsStackTop++; + ptr = scope.engine->jsAlloca(1); setPointer(v ? v->as<T>() : 0); } Scoped(const Scope &scope, T *t) { - ptr = scope.engine->jsStackTop++; + ptr = scope.engine->jsAlloca(1); setPointer(t); } Scoped(const Scope &scope, typename T::Data *t) { - ptr = scope.engine->jsStackTop++; + ptr = scope.engine->jsAlloca(1); *ptr = t; } Scoped(const Scope &scope, const ReturnedValue &v) { - ptr = scope.engine->jsStackTop++; + ptr = scope.engine->jsAlloca(1); setPointer(QV4::Value::fromReturnedValue(v).as<T>()); } + Scoped(const Scope &scope, const ReturnedValue &v, ConvertType) { - ptr = scope.engine->jsStackTop++; + ptr = scope.engine->jsAlloca(1); ptr->setRawValue(value_convert<T>(scope.engine, QV4::Value::fromReturnedValue(v))); } @@ -311,7 +316,7 @@ struct Scoped }; struct ScopedCallData { - ScopedCallData(Scope &scope, int argc = 0) + ScopedCallData(const Scope &scope, int argc = 0) { int size = qMax(argc, (int)QV4::Global::ReservedArgumentCount) + qOffsetOf(QV4::CallData, args)/sizeof(QV4::Value); ptr = reinterpret_cast<CallData *>(scope.alloc(size)); @@ -362,19 +367,19 @@ struct ScopedProperty struct ExecutionContextSaver { - ExecutionEngine *engine; + Scope scope; // this makes sure that a reference to context on the JS stack goes out of scope as soon as the context is not used anymore. ExecutionContext *savedContext; - ExecutionContextSaver(Scope &scope) - : engine(scope.engine) + ExecutionContextSaver(const Scope &scope) + : scope(scope.engine) { - savedContext = engine->currentContext; + savedContext = scope.engine->currentContext; } ~ExecutionContextSaver() { - Q_ASSERT(engine->jsStackTop > engine->currentContext); - engine->currentContext = savedContext; - engine->current = savedContext->d(); + Q_ASSERT(scope.engine->jsStackTop > scope.engine->currentContext); + scope.engine->currentContext = savedContext; + scope.engine->current = savedContext->d(); } }; |