aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4scopedvalue_p.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/jsruntime/qv4scopedvalue_p.h')
-rw-r--r--src/qml/jsruntime/qv4scopedvalue_p.h71
1 files changed, 34 insertions, 37 deletions
diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h
index e01571c3d6..44d171e087 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() {
@@ -88,12 +92,12 @@ struct Scope {
memset(mark, 0, (engine->jsStackTop - mark)*sizeof(Value));
#endif
#ifdef V4_USE_VALGRIND
- VALGRIND_MAKE_MEM_UNDEFINED(mark, engine->jsStackLimit - mark);
+ VALGRIND_MAKE_MEM_UNDEFINED(mark, (engine->jsStackLimit - mark) * sizeof(Value));
#endif
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)
@@ -126,9 +131,6 @@ struct ScopedValue
{
ptr = scope.engine->jsStackTop++;
ptr->setM(o);
-#ifndef QV4_USE_64_BIT_VALUE_ENCODING
- ptr->setTag(QV4::Value::Managed_Type);
-#endif
}
ScopedValue(const Scope &scope, Managed *m)
@@ -150,9 +152,6 @@ struct ScopedValue
ScopedValue &operator=(Heap::Base *o) {
ptr->setM(o);
-#ifndef QV4_USE_64_BIT_VALUE_ENCODING
- ptr->setTag(QV4::Value::Managed_Type);
-#endif
return *this;
}
@@ -192,69 +191,63 @@ struct Scoped
inline void setPointer(const Managed *p) {
ptr->setM(p ? p->m() : 0);
-#ifndef QV4_USE_64_BIT_VALUE_ENCODING
- ptr->setTag(QV4::Value::Managed_Type);
-#endif
}
Scoped(const Scope &scope)
{
- ptr = scope.engine->jsStackTop++;
- ptr->setM(0);
-#ifndef QV4_USE_64_BIT_VALUE_ENCODING
- ptr->setTag(QV4::Value::Managed_Type);
-#endif
+ 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)));
}
@@ -301,6 +294,10 @@ struct Scoped
return ptr->cast<T>();
}
+ const T *operator->() const {
+ return ptr->cast<T>();
+ }
+
bool operator!() const {
return !ptr->m();
}
@@ -323,7 +320,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));
@@ -345,14 +342,14 @@ struct ScopedCallData {
inline Value &Value::operator =(const ScopedValue &v)
{
- _val = v.ptr->val();
+ _val = v.ptr->rawValue();
return *this;
}
template<typename T>
inline Value &Value::operator=(const Scoped<T> &t)
{
- _val = t.ptr->val();
+ _val = t.ptr->rawValue();
return *this;
}
@@ -374,19 +371,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();
}
};