diff options
Diffstat (limited to 'src/qml/jsruntime/qv4script.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4script.cpp | 76 |
1 files changed, 22 insertions, 54 deletions
diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp index b6469ffd77..894426ce3b 100644 --- a/src/qml/jsruntime/qv4script.cpp +++ b/src/qml/jsruntime/qv4script.cpp @@ -1,51 +1,12 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtQml module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qv4script_p.h" #include <private/qv4mm_p.h> -#include "qv4functionobject_p.h" #include "qv4function_p.h" #include "qv4context_p.h" #include "qv4debugging_p.h" -#include "qv4profiling_p.h" #include "qv4scopedvalue_p.h" -#include "qv4jscall_p.h" #include <private/qqmljsengine_p.h> #include <private/qqmljslexer_p.h> @@ -65,14 +26,15 @@ using namespace QQmlJS; Script::Script(ExecutionEngine *v4, QmlContext *qml, const QQmlRefPointer<ExecutableCompilationUnit> &compilationUnit) : line(1), column(0), context(v4->rootContext()), strictMode(false), inheritContext(true), parsed(false) - , compilationUnit(compilationUnit), vmFunction(nullptr), parseAsBinding(true) + , compilationUnit(compilationUnit), parseAsBinding(true) { if (qml) qmlContext.set(v4, *qml); parsed = true; - vmFunction = compilationUnit ? compilationUnit->linkToEngine(v4) : nullptr; + vmFunction.set(v4, + compilationUnit ? compilationUnit->rootFunction() : nullptr); } Script::~Script() @@ -84,14 +46,12 @@ void Script::parse() if (parsed) return; - using namespace QV4::Compiler; - parsed = true; ExecutionEngine *v4 = context->engine(); Scope valueScope(v4); - Module module(v4->debugger() != nullptr); + QV4::Compiler::Module module(v4->debugger() != nullptr); if (sourceCode.startsWith(QLatin1String("function("))) { static const int snippetLength = 70; @@ -135,8 +95,8 @@ void Script::parse() if (v4->hasException) return; - compilationUnit = QV4::ExecutableCompilationUnit::create(cg.generateCompilationUnit()); - vmFunction = compilationUnit->linkToEngine(v4); + compilationUnit = v4->insertCompilationUnit(cg.generateCompilationUnit()); + vmFunction.set(v4, compilationUnit->rootFunction()); } if (!vmFunction) { @@ -174,7 +134,7 @@ Function *Script::function() return vmFunction; } -QV4::CompiledData::CompilationUnit Script::precompile( +QQmlRefPointer<QV4::CompiledData::CompilationUnit> Script::precompile( QV4::Compiler::Module *module, QQmlJS::Engine *jsEngine, Compiler::JSUnitGenerator *unitGenerator, const QString &fileName, const QString &finalUrl, const QString &source, QList<QQmlError> *reportedErrors, @@ -227,12 +187,20 @@ Script *Script::createFromFileOrCache(ExecutionEngine *engine, QmlContext *qmlCo error->clear(); QQmlMetaType::CachedUnitLookupError cacheError = QQmlMetaType::CachedUnitLookupError::NoError; - if (const QQmlPrivate::CachedQmlUnit *cachedUnit = engine->diskCacheEnabled() - ? QQmlMetaType::findCachedCompilationUnit(originalUrl, &cacheError) - : nullptr) { + const ExecutionEngine::DiskCacheOptions options = engine->diskCacheOptions(); + if (const QQmlPrivate::CachedQmlUnit *cachedUnit + = (options & ExecutionEngine::DiskCache::Aot) + ? QQmlMetaType::findCachedCompilationUnit( + originalUrl, + (options & ExecutionEngine::DiskCache::AotByteCode) + ? QQmlMetaType::AcceptUntyped + : QQmlMetaType::RequireFullyTyped, + &cacheError) + : nullptr) { QQmlRefPointer<QV4::ExecutableCompilationUnit> jsUnit - = QV4::ExecutableCompilationUnit::create( - QV4::CompiledData::CompilationUnit(cachedUnit->qmlData, cachedUnit->aotCompiledFunctions)); + = engine->insertCompilationUnit( + QQml::makeRefPointer<QV4::CompiledData::CompilationUnit>( + cachedUnit->qmlData, cachedUnit->aotCompiledFunctions)); return new QV4::Script(engine, qmlContext, jsUnit); } |