diff options
author | Liang Qi <liang.qi@theqtcompany.com> | 2015-09-25 20:56:51 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@theqtcompany.com> | 2015-09-25 20:56:51 +0200 |
commit | f9ef039ad955db67dc3ab6e9056afc4a325aa9a3 (patch) | |
tree | 4928ff85fb630639e306ea4eb7137a2064a80c8b /src/qml/qml/v8 | |
parent | 0238c739f81911f0963cf2c40b27dcfc8e3d38b7 (diff) | |
parent | 52fb4685e95e5b44e54d2d0f8ea27dea866c75e9 (diff) |
Merge remote-tracking branch 'origin/5.6' into dev
Conflicts:
src/qml/debugger/qqmldebug.cpp
Change-Id: I93de5a81b18cdece475870cf7cfba1b9baef2304
Diffstat (limited to 'src/qml/qml/v8')
-rw-r--r-- | src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 30 | ||||
-rw-r--r-- | src/qml/qml/v8/qqmlbuiltinfunctions_p.h | 4 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8engine.cpp | 62 | ||||
-rw-r--r-- | src/qml/qml/v8/qv8engine_p.h | 4 |
4 files changed, 50 insertions, 50 deletions
diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp index 239bc53f0a..5986fdbdfa 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp @@ -80,10 +80,9 @@ struct StaticQtMetaObject : public QObject { return &staticQtMetaObject; } }; -Heap::QtObject::QtObject(ExecutionEngine *v4, QQmlEngine *qmlEngine) - : Heap::Object(v4) +Heap::QtObject::QtObject(QQmlEngine *qmlEngine) { - Scope scope(v4); + Scope scope(internalClass->engine); ScopedObject o(scope, this); // Set all the enums from the "Qt" namespace @@ -93,11 +92,11 @@ Heap::QtObject::QtObject(ExecutionEngine *v4, QQmlEngine *qmlEngine) for (int ii = 0; ii < qtMetaObject->enumeratorCount(); ++ii) { QMetaEnum enumerator = qtMetaObject->enumerator(ii); for (int jj = 0; jj < enumerator.keyCount(); ++jj) { - o->put((str = v4->newString(QString::fromUtf8(enumerator.key(jj)))), (v = QV4::Primitive::fromInt32(enumerator.value(jj)))); + o->put((str = scope.engine->newString(QString::fromUtf8(enumerator.key(jj)))), (v = QV4::Primitive::fromInt32(enumerator.value(jj)))); } } - o->put((str = v4->newString(QStringLiteral("Asynchronous"))), (v = QV4::Primitive::fromInt32(0))); - o->put((str = v4->newString(QStringLiteral("Synchronous"))), (v = QV4::Primitive::fromInt32(1))); + o->put((str = scope.engine->newString(QStringLiteral("Asynchronous"))), (v = QV4::Primitive::fromInt32(0))); + o->put((str = scope.engine->newString(QStringLiteral("Synchronous"))), (v = QV4::Primitive::fromInt32(1))); o->defineDefaultProperty(QStringLiteral("include"), QV4Include::method_include); o->defineDefaultProperty(QStringLiteral("isQtObject"), QV4::QtObject::method_isQtObject); @@ -1262,7 +1261,7 @@ ReturnedValue QtObject::method_binding(CallContext *ctx) if (!f) V4THROW_TYPE("binding(): argument (binding expression) must be a function"); - return (ctx->d()->engine->memoryManager->alloc<QQmlBindingFunction>(f))->asReturnedValue(); + return (ctx->d()->engine->memoryManager->allocObject<QQmlBindingFunction>(f))->asReturnedValue(); } @@ -1315,10 +1314,9 @@ ReturnedValue QtObject::method_get_styleHints(CallContext *ctx) } -QV4::Heap::ConsoleObject::ConsoleObject(ExecutionEngine *v4) - : Heap::Object(v4) +QV4::Heap::ConsoleObject::ConsoleObject() { - QV4::Scope scope(v4); + QV4::Scope scope(internalClass->engine); QV4::ScopedObject o(scope, this); o->defineDefaultProperty(QStringLiteral("debug"), QV4::ConsoleObject::method_log); @@ -1609,10 +1607,10 @@ void QV4::GlobalExtensions::init(QQmlEngine *qmlEngine, Object *globalObject) globalObject->defineDefaultProperty(QStringLiteral("print"), ConsoleObject::method_log); globalObject->defineDefaultProperty(QStringLiteral("gc"), method_gc); - ScopedObject console(scope, v4->memoryManager->alloc<QV4::ConsoleObject>(v4)); + ScopedObject console(scope, v4->memoryManager->allocObject<QV4::ConsoleObject>()); globalObject->defineDefaultProperty(QStringLiteral("console"), console); - ScopedObject qt(scope, v4->memoryManager->alloc<QV4::QtObject>(v4, qmlEngine)); + ScopedObject qt(scope, v4->memoryManager->allocObject<QV4::QtObject>(qmlEngine)); globalObject->defineDefaultProperty(QStringLiteral("Qt"), qt); // string prototype extension @@ -1737,10 +1735,10 @@ ReturnedValue GlobalExtensions::method_qsTr(CallContext *ctx) int lastDot = path.lastIndexOf(QLatin1Char('.')); int length = lastDot - (lastSlash + 1); context = (lastSlash > -1) ? path.mid(lastSlash + 1, (length > -1) ? length : -1) : QString(); - } else if (ctx->d()->parent) { - ScopedContext parentCtx(scope, ctx->d()->parent); + } else { + ExecutionContext *parentCtx = scope.engine->parentContext(ctx); // The first non-empty source URL in the call stack determines the translation context. - while (parentCtx && context.isEmpty()) { + while (!!parentCtx && context.isEmpty()) { if (QV4::CompiledData::CompilationUnit *unit = parentCtx->d()->compilationUnit) { QString fileName = unit->fileName(); QUrl url(unit->fileName()); @@ -1753,7 +1751,7 @@ ReturnedValue GlobalExtensions::method_qsTr(CallContext *ctx) } context = QFileInfo(context).baseName(); } - parentCtx = parentCtx->d()->parent; + parentCtx = scope.engine->parentContext(parentCtx); } } diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions_p.h b/src/qml/qml/v8/qqmlbuiltinfunctions_p.h index bdd53fe601..bb05376fc0 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions_p.h +++ b/src/qml/qml/v8/qqmlbuiltinfunctions_p.h @@ -58,13 +58,13 @@ namespace QV4 { namespace Heap { struct QtObject : Object { - QtObject(ExecutionEngine *v4, QQmlEngine *qmlEngine); + QtObject(QQmlEngine *qmlEngine); QObject *platform; QObject *application; }; struct ConsoleObject : Object { - ConsoleObject(ExecutionEngine *engine); + ConsoleObject(); }; struct QQmlBindingFunction : FunctionObject { diff --git a/src/qml/qml/v8/qv8engine.cpp b/src/qml/qml/v8/qv8engine.cpp index 6cb316ce9f..effc37a0eb 100644 --- a/src/qml/qml/v8/qv8engine.cpp +++ b/src/qml/qml/v8/qv8engine.cpp @@ -191,41 +191,47 @@ void QV8Engine::initializeGlobal() m_illegalNames.insert(m_v4Engine->globalObject->internalClass()->nameMap.at(i)->string); } } +} - { -#define FREEZE_SOURCE "(function freeze_recur(obj) { "\ - " if (Qt.isQtObject(obj)) return;"\ - " if (obj != Function.connect && obj != Function.disconnect && "\ - " obj instanceof Object) {"\ - " var properties = Object.getOwnPropertyNames(obj);"\ - " for (var prop in properties) { "\ - " if (prop == \"connect\" || prop == \"disconnect\") {"\ - " Object.freeze(obj[prop]); "\ - " continue;"\ - " }"\ - " freeze_recur(obj[prop]);"\ - " }"\ - " }"\ - " if (obj instanceof Object) {"\ - " Object.freeze(obj);"\ - " }"\ - "})" - - QV4::ScopedFunctionObject result(scope, QV4::Script::evaluate(m_v4Engine, QString::fromUtf8(FREEZE_SOURCE), 0)); - Q_ASSERT(!!result); - m_freezeObject.set(scope.engine, result); -#undef FREEZE_SOURCE +static void freeze_recursive(QV4::ExecutionEngine *v4, QV4::Object *object) +{ + if (object->as<QV4::QObjectWrapper>()) + return; + + QV4::Scope scope(v4); + + bool instanceOfObject = false; + QV4::ScopedObject p(scope, object->prototype()); + while (p) { + if (p->d() == v4->objectPrototype()->d()) { + instanceOfObject = true; + break; + } + p = p->prototype(); + } + if (!instanceOfObject) + return; + + QV4::InternalClass *frozen = object->internalClass()->propertiesFrozen(); + if (object->internalClass() == frozen) + return; + object->setInternalClass(frozen); + + QV4::ScopedObject o(scope); + for (uint i = 0; i < frozen->size; ++i) { + if (!frozen->nameMap.at(i)) + continue; + o = *object->propertyData(i); + if (o) + freeze_recursive(v4, o); } } void QV8Engine::freezeObject(const QV4::Value &value) { QV4::Scope scope(m_v4Engine); - QV4::ScopedFunctionObject f(scope, m_freezeObject.value()); - QV4::ScopedCallData callData(scope, 1); - callData->args[0] = value; - callData->thisObject = m_v4Engine->globalObject; - f->call(callData); + QV4::ScopedObject o(scope, value); + freeze_recursive(m_v4Engine, o); } struct QV8EngineRegistrationData diff --git a/src/qml/qml/v8/qv8engine_p.h b/src/qml/qml/v8/qv8engine_p.h index 08bbbb8548..552470c88c 100644 --- a/src/qml/qml/v8/qv8engine_p.h +++ b/src/qml/qml/v8/qv8engine_p.h @@ -120,8 +120,6 @@ class QQmlV4Function public: int length() const { return callData->argc; } QV4::ReturnedValue operator[](int idx) { return (idx < callData->argc ? callData->args[idx].asReturnedValue() : QV4::Encode::undefined()); } - QQmlContextData *context() { return e->qmlContextObject()->context.contextData(); } - QV4::ReturnedValue qmlGlobal() { return e->qmlContextObject()->asReturnedValue(); } void setReturnValue(QV4::ReturnedValue rv) { *retVal = rv; } QV4::ExecutionEngine *v4engine() const { return e; } private: @@ -219,8 +217,6 @@ protected: QV4::ExecutionEngine *m_v4Engine; - QV4::PersistentValue m_freezeObject; - void *m_xmlHttpRequestData; QVector<Deletable *> m_extensionData; |