Remove the executioncontext in a few more places where it's not needed

Change-Id: I4c92c7bc9d94d8265e306f45d863fdc080a5e2a6
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
This commit is contained in:
Lars Knoll 2014-11-13 12:14:09 +01:00 committed by Simon Hausmann
parent cf7bd35a93
commit b943d80dd9
11 changed files with 31 additions and 45 deletions

View File

@ -178,10 +178,9 @@ void RegExpObject::markObjects(Heap::Base *that, ExecutionEngine *e)
Object::markObjects(that, e); Object::markObjects(that, e);
} }
Property *RegExpObject::lastIndexProperty(ExecutionContext *ctx) Property *RegExpObject::lastIndexProperty()
{ {
Q_UNUSED(ctx); Q_ASSERT(0 == internalClass()->find(engine()->id_lastIndex));
Q_ASSERT(0 == internalClass()->find(ctx->d()->engine->id_lastIndex));
return propertyAt(0); return propertyAt(0);
} }
@ -362,9 +361,9 @@ ReturnedValue RegExpPrototype::method_exec(CallContext *ctx)
return Encode::undefined(); return Encode::undefined();
QString s = arg->stringValue()->toQString(); QString s = arg->stringValue()->toQString();
int offset = r->global() ? r->lastIndexProperty(ctx)->value.toInt32() : 0; int offset = r->global() ? r->lastIndexProperty()->value.toInt32() : 0;
if (offset < 0 || offset > s.length()) { if (offset < 0 || offset > s.length()) {
r->lastIndexProperty(ctx)->value = Primitive::fromInt32(0); r->lastIndexProperty()->value = Primitive::fromInt32(0);
return Encode::null(); return Encode::null();
} }
@ -375,7 +374,7 @@ ReturnedValue RegExpPrototype::method_exec(CallContext *ctx)
regExpCtor->d()->clearLastMatch(); regExpCtor->d()->clearLastMatch();
if (result == -1) { if (result == -1) {
r->lastIndexProperty(ctx)->value = Primitive::fromInt32(0); r->lastIndexProperty()->value = Primitive::fromInt32(0);
return Encode::null(); return Encode::null();
} }
@ -401,7 +400,7 @@ ReturnedValue RegExpPrototype::method_exec(CallContext *ctx)
dd->lastMatchEnd = matchOffsets[1]; dd->lastMatchEnd = matchOffsets[1];
if (r->global()) if (r->global())
r->lastIndexProperty(ctx)->value = Primitive::fromInt32(matchOffsets[1]); r->lastIndexProperty()->value = Primitive::fromInt32(matchOffsets[1]);
return array.asReturnedValue(); return array.asReturnedValue();
} }

View File

@ -103,7 +103,7 @@ struct RegExpObject: Object {
void init(ExecutionEngine *engine); void init(ExecutionEngine *engine);
Property *lastIndexProperty(ExecutionContext *ctx); Property *lastIndexProperty();
QRegExp toQRegExp() const; QRegExp toQRegExp() const;
QString toString() const; QString toString() const;
QString source() const; QString source() const;

View File

@ -45,8 +45,6 @@ class QQmlContextData;
namespace QV4 { namespace QV4 {
struct ExecutionContext;
struct ContextStateSaver { struct ContextStateSaver {
ExecutionContext *savedContext; ExecutionContext *savedContext;
bool strictMode; bool strictMode;

View File

@ -49,15 +49,15 @@ QT_BEGIN_NAMESPACE
using namespace QV4; using namespace QV4;
// helper function to generate valid warnings if errors occur during sequence operations. // helper function to generate valid warnings if errors occur during sequence operations.
static void generateWarning(QV4::ExecutionContext *ctx, const QString& description) static void generateWarning(QV4::ExecutionEngine *v4, const QString& description)
{ {
QQmlEngine *engine = ctx->d()->engine->v8Engine->engine(); QQmlEngine *engine = v4->v8Engine->engine();
if (!engine) if (!engine)
return; return;
QQmlError retn; QQmlError retn;
retn.setDescription(description); retn.setDescription(description);
QV4::StackFrame frame = ctx->d()->engine->currentStackFrame(); QV4::StackFrame frame = v4->currentStackFrame();
retn.setLine(frame.line); retn.setLine(frame.line);
retn.setUrl(QUrl(frame.source)); retn.setUrl(QUrl(frame.source));
@ -190,7 +190,7 @@ public:
{ {
/* Qt containers have int (rather than uint) allowable indexes. */ /* Qt containers have int (rather than uint) allowable indexes. */
if (index > INT_MAX) { if (index > INT_MAX) {
generateWarning(engine()->currentContext(), QLatin1String("Index out of range during indexed get")); generateWarning(engine(), QLatin1String("Index out of range during indexed get"));
if (hasProperty) if (hasProperty)
*hasProperty = false; *hasProperty = false;
return Encode::undefined(); return Encode::undefined();
@ -221,7 +221,7 @@ public:
/* Qt containers have int (rather than uint) allowable indexes. */ /* Qt containers have int (rather than uint) allowable indexes. */
if (index > INT_MAX) { if (index > INT_MAX) {
generateWarning(engine()->currentContext(), QLatin1String("Index out of range during indexed set")); generateWarning(engine(), QLatin1String("Index out of range during indexed set"));
return; return;
} }
@ -259,7 +259,7 @@ public:
{ {
/* Qt containers have int (rather than uint) allowable indexes. */ /* Qt containers have int (rather than uint) allowable indexes. */
if (index > INT_MAX) { if (index > INT_MAX) {
generateWarning(engine()->currentContext(), QLatin1String("Index out of range during indexed query")); generateWarning(engine(), QLatin1String("Index out of range during indexed query"));
return QV4::Attr_Invalid; return QV4::Attr_Invalid;
} }
if (d()->isReference) { if (d()->isReference) {
@ -411,7 +411,7 @@ public:
quint32 newLength = ctx->d()->callData->args[0].toUInt32(); quint32 newLength = ctx->d()->callData->args[0].toUInt32();
/* Qt containers have int (rather than uint) allowable indexes. */ /* Qt containers have int (rather than uint) allowable indexes. */
if (newLength > INT_MAX) { if (newLength > INT_MAX) {
generateWarning(ctx, QLatin1String("Index out of range during length set")); generateWarning(scope.engine, QLatin1String("Index out of range during length set"));
return QV4::Encode::undefined(); return QV4::Encode::undefined();
} }
/* Read the sequence from the QObject property if we're a reference */ /* Read the sequence from the QObject property if we're a reference */

View File

@ -230,7 +230,7 @@ static QString getThisString(ExecutionContext *ctx)
if (StringObject *thisString = t->asStringObject()) if (StringObject *thisString = t->asStringObject())
return thisString->d()->value.stringValue()->toQString(); return thisString->d()->value.stringValue()->toQString();
if (t->isUndefined() || t->isNull()) { if (t->isUndefined() || t->isNull()) {
ctx->engine()->throwTypeError(); scope.engine->throwTypeError();
return QString(); return QString();
} }
return t->toQString(); return t->toQString();
@ -517,7 +517,7 @@ ReturnedValue StringPrototype::method_replace(CallContext *ctx)
offset = qMax(offset + 1, matchOffsets[oldSize + 1]); offset = qMax(offset + 1, matchOffsets[oldSize + 1]);
} }
if (regExp->global()) if (regExp->global())
regExp->lastIndexProperty(ctx)->value = Primitive::fromUInt32(0); regExp->lastIndexProperty()->value = Primitive::fromUInt32(0);
numStringMatches = nMatchOffsets / (regExp->value()->captureCount() * 2); numStringMatches = nMatchOffsets / (regExp->value()->captureCount() * 2);
numCaptures = regExp->value()->captureCount(); numCaptures = regExp->value()->captureCount();
} else { } else {

View File

@ -88,8 +88,7 @@ double Value::toNumberImpl() const
if (isString()) if (isString())
return RuntimeHelpers::stringToNumber(stringValue()->toQString()); return RuntimeHelpers::stringToNumber(stringValue()->toQString());
{ {
ExecutionContext *ctx = objectValue()->internalClass()->engine->currentContext(); Scope scope(managed()->engine());
Scope scope(ctx);
ScopedValue prim(scope, RuntimeHelpers::toPrimitive(ValueRef::fromRawValue(this), NUMBER_HINT)); ScopedValue prim(scope, RuntimeHelpers::toPrimitive(ValueRef::fromRawValue(this), NUMBER_HINT));
if (scope.engine->hasException) if (scope.engine->hasException)
return 0; return 0;
@ -124,8 +123,7 @@ QString Value::toQStringNoThrow() const
if (isString()) if (isString())
return stringValue()->toQString(); return stringValue()->toQString();
{ {
ExecutionContext *ctx = objectValue()->internalClass()->engine->currentContext(); Scope scope(managed()->engine());
Scope scope(ctx);
ScopedValue ex(scope); ScopedValue ex(scope);
bool caughtException = false; bool caughtException = false;
ScopedValue prim(scope, RuntimeHelpers::toPrimitive(ValueRef::fromRawValue(this), STRING_HINT)); ScopedValue prim(scope, RuntimeHelpers::toPrimitive(ValueRef::fromRawValue(this), STRING_HINT));
@ -177,8 +175,7 @@ QString Value::toQString() const
if (isString()) if (isString())
return stringValue()->toQString(); return stringValue()->toQString();
{ {
ExecutionContext *ctx = objectValue()->internalClass()->engine->currentContext(); Scope scope(managed()->engine());
Scope scope(ctx);
ScopedValue prim(scope, RuntimeHelpers::toPrimitive(ValueRef::fromRawValue(this), STRING_HINT)); ScopedValue prim(scope, RuntimeHelpers::toPrimitive(ValueRef::fromRawValue(this), STRING_HINT));
return prim->toQString(); return prim->toQString();
} }

View File

@ -76,9 +76,9 @@ void QQmlDelayedError::setErrorObject(QObject *object)
m_error.setObject(object); m_error.setObject(object);
} }
void QQmlDelayedError::catchJavaScriptException(QV4::ExecutionContext *context) void QQmlDelayedError::catchJavaScriptException(QV4::ExecutionEngine *engine)
{ {
m_error = context->engine()->catchExceptionAsQmlError(); m_error = engine->catchExceptionAsQmlError();
} }
@ -147,10 +147,9 @@ QV4::ReturnedValue QQmlJavaScriptExpression::evaluate(QQmlContextData *context,
QV4::ExecutionEngine *v4 = QV8Engine::getV4(ep->v8engine()); QV4::ExecutionEngine *v4 = QV8Engine::getV4(ep->v8engine());
QV4::Scope scope(v4); QV4::Scope scope(v4);
QV4::ScopedValue result(scope, QV4::Primitive::undefinedValue()); QV4::ScopedValue result(scope, QV4::Primitive::undefinedValue());
QV4::ExecutionContext *ctx = v4->currentContext();
callData->thisObject = v4->globalObject; callData->thisObject = v4->globalObject;
if (scopeObject()) { if (scopeObject()) {
QV4::ScopedValue value(scope, QV4::QObjectWrapper::wrap(ctx->d()->engine, scopeObject())); QV4::ScopedValue value(scope, QV4::QObjectWrapper::wrap(v4, scopeObject()));
if (value->isObject()) if (value->isObject())
callData->thisObject = value; callData->thisObject = value;
} }
@ -160,7 +159,7 @@ QV4::ReturnedValue QQmlJavaScriptExpression::evaluate(QQmlContextData *context,
if (watcher.wasDeleted()) if (watcher.wasDeleted())
scope.engine->catchException(); // ignore exception scope.engine->catchException(); // ignore exception
else else
delayedError()->catchJavaScriptException(ctx); delayedError()->catchJavaScriptException(scope.engine);
if (isUndefined) if (isUndefined)
*isUndefined = true; *isUndefined = true;
} else { } else {

View File

@ -52,10 +52,6 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
namespace QV4 {
struct ExecutionContext;
}
class QQmlDelayedError class QQmlDelayedError
{ {
public: public:
@ -81,7 +77,7 @@ public:
void setErrorObject(QObject *object); void setErrorObject(QObject *object);
// Call only from catch(...) -- will re-throw if no JS exception // Call only from catch(...) -- will re-throw if no JS exception
void catchJavaScriptException(QV4::ExecutionContext *context); void catchJavaScriptException(QV4::ExecutionEngine *engine);
private: private:

View File

@ -1547,18 +1547,17 @@ const QByteArray &QQmlXMLHttpRequest::rawResponseBody() const
void QQmlXMLHttpRequest::dispatchCallbackImpl(const ValueRef me) void QQmlXMLHttpRequest::dispatchCallbackImpl(const ValueRef me)
{ {
ExecutionContext *ctx = v4->currentContext();
QV4::Scope scope(v4); QV4::Scope scope(v4);
Scoped<Object> o(scope, me); Scoped<Object> o(scope, me);
if (!o) { if (!o) {
ctx->engine()->throwError(QStringLiteral("QQmlXMLHttpRequest: internal error: empty ThisObject")); v4->throwError(QStringLiteral("QQmlXMLHttpRequest: internal error: empty ThisObject"));
return; return;
} }
ScopedString s(scope, v4->newString(QStringLiteral("ThisObject"))); ScopedString s(scope, v4->newString(QStringLiteral("ThisObject")));
Scoped<Object> thisObj(scope, o->get(s.getPointer())); Scoped<Object> thisObj(scope, o->get(s.getPointer()));
if (!thisObj) { if (!thisObj) {
ctx->engine()->throwError(QStringLiteral("QQmlXMLHttpRequest: internal error: empty ThisObject")); v4->throwError(QStringLiteral("QQmlXMLHttpRequest: internal error: empty ThisObject"));
return; return;
} }

View File

@ -161,6 +161,7 @@ public:
, m_time(0) , m_time(0)
, m_vsync(0) , m_vsync(0)
, m_mode(VSyncMode) , m_mode(VSyncMode)
, m_lag(0)
, m_bad(0) , m_bad(0)
, m_good(0) , m_good(0)
{ {

View File

@ -2303,8 +2303,7 @@ static inline bool evaluate_error(QV8Engine *engine, const QV4::ValueRef o, cons
QV4::Script program(QV8Engine::getV4(engine)->rootContext, functionSource); QV4::Script program(QV8Engine::getV4(engine)->rootContext, functionSource);
program.inheritContext = true; program.inheritContext = true;
QV4::ExecutionContext *ctx = QV8Engine::getV4(engine)->currentContext(); QV4::Scope scope(QV8Engine::getV4(engine));
QV4::Scope scope(ctx);
QV4::Scoped<QV4::FunctionObject> function(scope, program.run()); QV4::Scoped<QV4::FunctionObject> function(scope, program.run());
if (scope.engine->hasException) { if (scope.engine->hasException) {
@ -2331,8 +2330,7 @@ static inline bool evaluate_value(QV8Engine *engine, const QV4::ValueRef o,
QV4::Script program(QV8Engine::getV4(engine)->rootContext, functionSource); QV4::Script program(QV8Engine::getV4(engine)->rootContext, functionSource);
program.inheritContext = true; program.inheritContext = true;
QV4::ExecutionContext *ctx = QV8Engine::getV4(engine)->currentContext(); QV4::Scope scope(QV8Engine::getV4(engine));
QV4::Scope scope(ctx);
QV4::Scoped<QV4::FunctionObject> function(scope, program.run()); QV4::Scoped<QV4::FunctionObject> function(scope, program.run());
if (scope.engine->hasException) { if (scope.engine->hasException) {
@ -2360,10 +2358,9 @@ static inline QV4::ReturnedValue evaluate(QV8Engine *engine, const QV4::ValueRef
QString functionSource = QLatin1String("(function(object) { return ") + QString functionSource = QLatin1String("(function(object) { return ") +
QLatin1String(source) + QLatin1String(" })"); QLatin1String(source) + QLatin1String(" })");
QV4::ExecutionContext *ctx = QV8Engine::getV4(engine)->currentContext(); QV4::Scope scope(QV8Engine::getV4(engine));
QV4::Scope scope(ctx);
QV4::Script program(QV8Engine::getV4(engine)->rootContext, functionSource); QV4::Script program(scope.engine->rootContext, functionSource);
program.inheritContext = true; program.inheritContext = true;
QV4::Scoped<QV4::FunctionObject> function(scope, program.run()); QV4::Scoped<QV4::FunctionObject> function(scope, program.run());