diff options
author | Lars Knoll <lars.knoll@digia.com> | 2014-11-21 09:17:01 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2014-12-11 08:40:41 +0100 |
commit | ddfe9defa803fdbfab10ab58b77df242cdb4cedd (patch) | |
tree | b13af2424e8ea466a9de9fece8f2fbb6415ce8b6 /src/qml/jsruntime | |
parent | 254cf16ed4c6007a59a7cd5d64bb621430b3c01d (diff) |
Encapsulate accesses to the root context
Change-Id: I668cef1363a5c1a5c5b9a7e138f3bd0338712eea
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 58 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4engine_p.h | 3 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4functionobject.cpp | 6 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4object.cpp | 8 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4objectproto.cpp | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4qobjectwrapper.cpp | 6 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4script.cpp | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4script_p.h | 2 |
8 files changed, 46 insertions, 45 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 89df57037a..a2fd33bc3c 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -283,6 +283,8 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory) Q_ASSERT(argumentsObjectClass->vtable == ArgumentsObject::staticVTable()); Q_ASSERT(strictArgumentsObjectClass->vtable == ArgumentsObject::staticVTable()); + ScopedObject global(scope, newObject()); + globalObject = global; initRootContext(); ScopedObject stringPrototype(scope, memoryManager->alloc<StringPrototype>(InternalClass::create(this, StringPrototype::staticVTable(), objectPrototype))); @@ -337,21 +339,21 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory) sequencePrototype = ScopedValue(scope, memoryManager->alloc<SequencePrototype>(arrayClass)); - objectCtor = memoryManager->alloc<ObjectCtor>(rootContext); - stringCtor = memoryManager->alloc<StringCtor>(rootContext); - numberCtor = memoryManager->alloc<NumberCtor>(rootContext); - booleanCtor = memoryManager->alloc<BooleanCtor>(rootContext); - arrayCtor = memoryManager->alloc<ArrayCtor>(rootContext); - functionCtor = memoryManager->alloc<FunctionCtor>(rootContext); - dateCtor = memoryManager->alloc<DateCtor>(rootContext); - regExpCtor = memoryManager->alloc<RegExpCtor>(rootContext); - errorCtor = memoryManager->alloc<ErrorCtor>(rootContext); - evalErrorCtor = memoryManager->alloc<EvalErrorCtor>(rootContext); - rangeErrorCtor = memoryManager->alloc<RangeErrorCtor>(rootContext); - referenceErrorCtor = memoryManager->alloc<ReferenceErrorCtor>(rootContext); - syntaxErrorCtor = memoryManager->alloc<SyntaxErrorCtor>(rootContext); - typeErrorCtor = memoryManager->alloc<TypeErrorCtor>(rootContext); - uRIErrorCtor = memoryManager->alloc<URIErrorCtor>(rootContext); + objectCtor = memoryManager->alloc<ObjectCtor>(rootContext()); + stringCtor = memoryManager->alloc<StringCtor>(rootContext()); + numberCtor = memoryManager->alloc<NumberCtor>(rootContext()); + booleanCtor = memoryManager->alloc<BooleanCtor>(rootContext()); + arrayCtor = memoryManager->alloc<ArrayCtor>(rootContext()); + functionCtor = memoryManager->alloc<FunctionCtor>(rootContext()); + dateCtor = memoryManager->alloc<DateCtor>(rootContext()); + regExpCtor = memoryManager->alloc<RegExpCtor>(rootContext()); + errorCtor = memoryManager->alloc<ErrorCtor>(rootContext()); + evalErrorCtor = memoryManager->alloc<EvalErrorCtor>(rootContext()); + rangeErrorCtor = memoryManager->alloc<RangeErrorCtor>(rootContext()); + referenceErrorCtor = memoryManager->alloc<ReferenceErrorCtor>(rootContext()); + syntaxErrorCtor = memoryManager->alloc<SyntaxErrorCtor>(rootContext()); + typeErrorCtor = memoryManager->alloc<TypeErrorCtor>(rootContext()); + uRIErrorCtor = memoryManager->alloc<URIErrorCtor>(rootContext()); static_cast<ObjectPrototype *>(objectPrototype.getPointer())->init(this, objectCtor.asObject()); static_cast<StringPrototype *>(stringPrototype.getPointer())->init(this, stringCtor.asObject()); @@ -375,18 +377,18 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory) // typed arrays - arrayBufferCtor = memoryManager->alloc<ArrayBufferCtor>(rootContext); + arrayBufferCtor = memoryManager->alloc<ArrayBufferCtor>(rootContext()); Scoped<ArrayBufferPrototype> arrayBufferPrototype(scope, memoryManager->alloc<ArrayBufferPrototype>(objectClass)); arrayBufferPrototype->init(this, arrayBufferCtor.asObject()); arrayBufferClass = InternalClass::create(this, ArrayBuffer::staticVTable(), arrayBufferPrototype); - dataViewCtor = memoryManager->alloc<DataViewCtor>(rootContext); + dataViewCtor = memoryManager->alloc<DataViewCtor>(rootContext()); Scoped<DataViewPrototype> dataViewPrototype(scope, memoryManager->alloc<DataViewPrototype>(objectClass)); dataViewPrototype->init(this, dataViewCtor.asObject()); dataViewClass = InternalClass::create(this, DataView::staticVTable(), dataViewPrototype); for (int i = 0; i < Heap::TypedArray::NTypes; ++i) { - typedArrayCtors[i] = memoryManager->alloc<TypedArrayCtor>(rootContext, Heap::TypedArray::Type(i)); + typedArrayCtors[i] = memoryManager->alloc<TypedArrayCtor>(rootContext(), Heap::TypedArray::Type(i)); Scoped<TypedArrayPrototype> typedArrayPrototype(scope, memoryManager->alloc<TypedArrayPrototype>(this, Heap::TypedArray::Type(i))); typedArrayPrototype->init(this, static_cast<TypedArrayCtor *>(typedArrayCtors[i].asObject())); typedArrayClasses[i] = InternalClass::create(this, TypedArray::staticVTable(), typedArrayPrototype); @@ -395,10 +397,8 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory) // // set up the global object // - ScopedObject global(scope, newObject()); - globalObject = global; - rootContext->d()->global = globalObject->d(); - rootContext->d()->callData->thisObject = globalObject; + rootContext()->d()->global = globalObject->d(); + rootContext()->d()->callData->thisObject = globalObject; Q_ASSERT(globalObject->internalClass()->vtable); globalObject->defineDefaultProperty(QStringLiteral("Object"), objectCtor); @@ -431,7 +431,7 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory) globalObject->defineReadonlyProperty(QStringLiteral("Infinity"), Primitive::fromDouble(Q_INFINITY)); - evalFunction = Scoped<EvalFunction>(scope, memoryManager->alloc<EvalFunction>(rootContext)); + evalFunction = Scoped<EvalFunction>(scope, memoryManager->alloc<EvalFunction>(rootContext())); globalObject->defineDefaultProperty(QStringLiteral("eval"), (o = evalFunction)); globalObject->defineDefaultProperty(QStringLiteral("parseInt"), GlobalFunctions::method_parseInt, 2); @@ -446,7 +446,7 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory) globalObject->defineDefaultProperty(QStringLiteral("unescape"), GlobalFunctions::method_unescape, 1); Scoped<String> name(scope, newString(QStringLiteral("thrower"))); - thrower = ScopedFunctionObject(scope, BuiltinFunction::create(rootContext, name.getPointer(), ::throwTypeError)).getPointer(); + thrower = ScopedFunctionObject(scope, BuiltinFunction::create(rootContext(), name.getPointer(), ::throwTypeError)).getPointer(); } ExecutionEngine::~ExecutionEngine() @@ -501,7 +501,7 @@ void ExecutionEngine::initRootContext() r->d()->callData->thisObject = globalObject; r->d()->callData->args[0] = Encode::undefined(); - rootContext = r; + m_rootContext = r; } InternalClass *ExecutionEngine::newClass(const InternalClass &other) @@ -513,7 +513,7 @@ ExecutionContext *ExecutionEngine::pushGlobalContext() { Scope scope(this); Scoped<GlobalContext> g(scope, memoryManager->alloc<GlobalContext>(this)); - g->d()->callData = rootContext->d()->callData; + g->d()->callData = rootContext()->d()->callData; Q_ASSERT(currentContext() == g.getPointer()); return g.getPointer(); @@ -764,7 +764,7 @@ QVector<StackFrame> ExecutionEngine::stackTrace(int frameLimit) const StackFrame frame; frame.source = globalCode->sourceFile(); frame.function = globalCode->name()->toQString(); - frame.line = rootContext->d()->lineNumber; + frame.line = rootContext()->d()->lineNumber; frame.column = -1; @@ -866,8 +866,8 @@ void ExecutionEngine::requireArgumentsAccessors(int n) delete [] oldAccessors; } for (int i = oldSize; i < nArgumentsAccessors; ++i) { - argumentsAccessors[i].value = ScopedValue(scope, memoryManager->alloc<ArgumentsGetterFunction>(rootContext, i)); - argumentsAccessors[i].set = ScopedValue(scope, memoryManager->alloc<ArgumentsSetterFunction>(rootContext, i)); + argumentsAccessors[i].value = ScopedValue(scope, memoryManager->alloc<ArgumentsGetterFunction>(rootContext(), i)); + argumentsAccessors[i].set = ScopedValue(scope, memoryManager->alloc<ArgumentsSetterFunction>(rootContext(), i)); } } } diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index f07448b4a2..57fe7eb9bf 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -78,7 +78,8 @@ public: Value *jsStackTop; quint32 hasException; - GlobalContext *rootContext; + GlobalContext *m_rootContext; + GlobalContext *rootContext() const { return m_rootContext; } MemoryManager *memoryManager; ExecutableAllocator *executableAllocator; diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index 8833d675d5..22ed62cf18 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -123,7 +123,7 @@ Heap::FunctionObject::FunctionObject(ExecutionContext *scope, const ReturnedValu Heap::FunctionObject::FunctionObject(InternalClass *ic) : Heap::Object(ic) - , scope(ic->engine->rootContext->d()) + , scope(ic->engine->rootContext()->d()) { Scope scope(ic->engine); ScopedObject o(scope, this); @@ -257,7 +257,7 @@ ReturnedValue FunctionCtor::construct(Managed *that, CallData *callData) QQmlRefPointer<QV4::CompiledData::CompilationUnit> compilationUnit = isel->compile(); QV4::Function *vmf = compilationUnit->linkToEngine(v4); - return FunctionObject::createScriptFunction(v4->rootContext, vmf)->asReturnedValue(); + return FunctionObject::createScriptFunction(v4->rootContext(), vmf)->asReturnedValue(); } // 15.3.1: This is equivalent to new Function(...) @@ -372,7 +372,7 @@ ReturnedValue FunctionPrototype::method_bind(CallContext *ctx) memcpy(boundArgs->data(), ctx->d()->callData->args + 1, (ctx->d()->callData->argc - 1)*sizeof(Value)); } - return BoundFunction::create(ctx->d()->engine->rootContext, target, boundThis, boundArgs)->asReturnedValue(); + return BoundFunction::create(ctx->d()->engine->rootContext(), target, boundThis, boundArgs)->asReturnedValue(); } DEFINE_OBJECT_VTABLE(ScriptFunction); diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index 1160e2c1c1..a9ce9b42f2 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -134,7 +134,7 @@ void Object::defineDefaultProperty(const QString &name, ReturnedValue (*code)(Ca ExecutionEngine *e = engine(); Scope scope(e); ScopedString s(scope, e->newIdentifier(name)); - Scoped<FunctionObject> function(scope, BuiltinFunction::create(e->rootContext, s.getPointer(), code)); + Scoped<FunctionObject> function(scope, BuiltinFunction::create(e->rootContext(), s.getPointer(), code)); function->defineReadonlyProperty(e->id_length, Primitive::fromInt32(argumentCount)); defineDefaultProperty(s.getPointer(), function); } @@ -143,7 +143,7 @@ void Object::defineDefaultProperty(String *name, ReturnedValue (*code)(CallConte { ExecutionEngine *e = engine(); Scope scope(e); - Scoped<FunctionObject> function(scope, BuiltinFunction::create(e->rootContext, name, code)); + Scoped<FunctionObject> function(scope, BuiltinFunction::create(e->rootContext(), name, code)); function->defineReadonlyProperty(e->id_length, Primitive::fromInt32(argumentCount)); defineDefaultProperty(name, function); } @@ -161,8 +161,8 @@ void Object::defineAccessorProperty(String *name, ReturnedValue (*getter)(CallCo ExecutionEngine *v4 = engine(); QV4::Scope scope(v4); ScopedProperty p(scope); - p->setGetter(getter ? ScopedFunctionObject(scope, BuiltinFunction::create(v4->rootContext, name, getter)).getPointer() : 0); - p->setSetter(setter ? ScopedFunctionObject(scope, BuiltinFunction::create(v4->rootContext, name, setter)).getPointer() : 0); + p->setGetter(getter ? ScopedFunctionObject(scope, BuiltinFunction::create(v4->rootContext(), name, getter)).getPointer() : 0); + p->setSetter(setter ? ScopedFunctionObject(scope, BuiltinFunction::create(v4->rootContext(), name, setter)).getPointer() : 0); insertMember(name, p, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); } diff --git a/src/qml/jsruntime/qv4objectproto.cpp b/src/qml/jsruntime/qv4objectproto.cpp index 46116cb707..962d9bbee5 100644 --- a/src/qml/jsruntime/qv4objectproto.cpp +++ b/src/qml/jsruntime/qv4objectproto.cpp @@ -108,8 +108,8 @@ void ObjectPrototype::init(ExecutionEngine *v4, Object *ctor) defineDefaultProperty(QStringLiteral("__defineGetter__"), method_defineGetter, 2); defineDefaultProperty(QStringLiteral("__defineSetter__"), method_defineSetter, 2); - Property p(ScopedFunctionObject(scope, BuiltinFunction::create(v4->rootContext, v4->id___proto__, method_get_proto)).getPointer(), - ScopedFunctionObject(scope, BuiltinFunction::create(v4->rootContext, v4->id___proto__, method_set_proto)).getPointer()); + Property p(ScopedFunctionObject(scope, BuiltinFunction::create(v4->rootContext(), v4->id___proto__, method_get_proto)).getPointer(), + ScopedFunctionObject(scope, BuiltinFunction::create(v4->rootContext(), v4->id___proto__, method_set_proto)).getPointer()); insertMember(v4->id___proto__, p, Attr_Accessor|Attr_NotEnumerable); } diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index 4a671f3219..9b08e89ffb 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -275,7 +275,7 @@ ReturnedValue QObjectWrapper::getQmlProperty(QQmlContextData *qmlContext, String if (name->equals(scope.engine->id_destroy) || name->equals(scope.engine->id_toString)) { int index = name->equals(scope.engine->id_destroy) ? QV4::QObjectMethod::DestroyMethod : QV4::QObjectMethod::ToStringMethod; - QV4::ScopedValue method(scope, QV4::QObjectMethod::create(scope.engine->rootContext, d()->object, index)); + QV4::ScopedValue method(scope, QV4::QObjectMethod::create(scope.engine->rootContext(), d()->object, index)); if (hasProperty) *hasProperty = true; return method.asReturnedValue(); @@ -339,7 +339,7 @@ ReturnedValue QObjectWrapper::getProperty(QObject *object, ExecutionContext *ctx return vmemo->vmeMethod(property->coreIndex); } else if (property->isV4Function()) { QV4::Scoped<QV4::Object> qmlcontextobject(scope, ctx->d()->engine->qmlContextObject()); - return QV4::QObjectMethod::create(ctx->d()->engine->rootContext, object, property->coreIndex, qmlcontextobject); + return QV4::QObjectMethod::create(ctx->d()->engine->rootContext(), object, property->coreIndex, qmlcontextobject); } else if (property->isSignalHandler()) { QV4::Scoped<QV4::QmlSignalHandler> handler(scope, scope.engine->memoryManager->alloc<QV4::QmlSignalHandler>(ctx->d()->engine, object, property->coreIndex)); @@ -350,7 +350,7 @@ ReturnedValue QObjectWrapper::getProperty(QObject *object, ExecutionContext *ctx return handler.asReturnedValue(); } else { - return QV4::QObjectMethod::create(ctx->d()->engine->rootContext, object, property->coreIndex); + return QV4::QObjectMethod::create(ctx->d()->engine->rootContext(), object, property->coreIndex); } } diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index a838b23d9d..3c68cdd433 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -168,7 +168,7 @@ Heap::FunctionObject *QmlBindingWrapper::createQmlCallableForFunction(QQmlContex ExecutionEngine *engine = QQmlEnginePrivate::getV4Engine(qmlContext->engine); QV4::Scope valueScope(engine); QV4::ScopedObject qmlScopeObject(valueScope, QV4::QmlContextWrapper::qmlScope(engine->v8Engine, qmlContext, scopeObject)); - QV4::Scoped<QV4::QmlBindingWrapper> wrapper(valueScope, engine->memoryManager->alloc<QV4::QmlBindingWrapper>(engine->rootContext, qmlScopeObject)); + QV4::Scoped<QV4::QmlBindingWrapper> wrapper(valueScope, engine->memoryManager->alloc<QV4::QmlBindingWrapper>(engine->rootContext(), qmlScopeObject)); QV4::Scoped<CallContext> wrapperContext(valueScope, wrapper->context()); if (!signalParameters.isEmpty()) { @@ -191,7 +191,7 @@ Heap::FunctionObject *QmlBindingWrapper::createQmlCallableForFunction(QQmlContex } Script::Script(ExecutionEngine *v4, Object *qml, CompiledData::CompilationUnit *compilationUnit) - : line(0), column(0), scope(v4->rootContext), strictMode(false), inheritContext(true), parsed(false) + : line(0), column(0), scope(v4->rootContext()), strictMode(false), inheritContext(true), parsed(false) , qml(qml->asReturnedValue()), vmFunction(0), parseAsBinding(true) { parsed = true; diff --git a/src/qml/jsruntime/qv4script_p.h b/src/qml/jsruntime/qv4script_p.h index 14c617b554..a3cbcf4912 100644 --- a/src/qml/jsruntime/qv4script_p.h +++ b/src/qml/jsruntime/qv4script_p.h @@ -101,7 +101,7 @@ struct Q_QML_EXPORT Script { , vmFunction(0), parseAsBinding(false) {} Script(ExecutionEngine *engine, Object *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) + , scope(engine->rootContext()), strictMode(false), inheritContext(true), parsed(false) , qml(qml->asReturnedValue()), vmFunction(0), parseAsBinding(true) {} Script(ExecutionEngine *engine, Object *qml, CompiledData::CompilationUnit *compilationUnit); ~Script(); |