diff options
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 30 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4engine_p.h | 10 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4mathobject.cpp | 1 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4qmlcontext.cpp | 9 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4qmlcontext_p.h | 13 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4qobjectwrapper.cpp | 8 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4regexp.cpp | 9 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4regexp_p.h | 13 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4regexpobject.cpp | 13 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4regexpobject_p.h | 8 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4runtime.cpp | 7 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4stringobject.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4vme_moth.cpp | 7 |
13 files changed, 60 insertions, 70 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 8ca6b03950..a5fc37b91b 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -142,10 +142,6 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory) , m_engineId(engineSerial.fetchAndAddOrdered(1)) , regExpCache(0) , m_multiplyWrappedQObjects(0) -#ifndef QT_NO_QML_DEBUGGER - , m_debugger(0) - , m_profiler(0) -#endif { memoryManager = new QV4::MemoryManager(this); @@ -501,12 +497,6 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory) ExecutionEngine::~ExecutionEngine() { -#ifndef QT_NO_QML_DEBUGGER - delete m_debugger; - m_debugger = 0; - delete m_profiler; - m_profiler = 0; -#endif delete m_multiplyWrappedQObjects; m_multiplyWrappedQObjects = 0; delete identifierTable; @@ -534,13 +524,13 @@ ExecutionEngine::~ExecutionEngine() void ExecutionEngine::setDebugger(Debugging::Debugger *debugger) { Q_ASSERT(!m_debugger); - m_debugger = debugger; + m_debugger.reset(debugger); } void ExecutionEngine::setProfiler(Profiling::Profiler *profiler) { Q_ASSERT(!m_profiler); - m_profiler = profiler; + m_profiler.reset(profiler); } #endif // QT_NO_QML_DEBUGGER @@ -698,21 +688,17 @@ Heap::DateObject *ExecutionEngine::newDateObjectFromTime(const QTime &t) Heap::RegExpObject *ExecutionEngine::newRegExpObject(const QString &pattern, int flags) { bool global = (flags & IR::RegExp::RegExp_Global); - bool ignoreCase = false; - bool multiline = false; - if (flags & IR::RegExp::RegExp_IgnoreCase) - ignoreCase = true; - if (flags & IR::RegExp::RegExp_Multiline) - multiline = true; + bool ignoreCase = (flags & IR::RegExp::RegExp_IgnoreCase); + bool multiline = (flags & IR::RegExp::RegExp_Multiline); Scope scope(this); - Scoped<RegExp> re(scope, RegExp::create(this, pattern, ignoreCase, multiline)); - return newRegExpObject(re, global); + Scoped<RegExp> re(scope, RegExp::create(this, pattern, ignoreCase, multiline, global)); + return newRegExpObject(re); } -Heap::RegExpObject *ExecutionEngine::newRegExpObject(RegExp *re, bool global) +Heap::RegExpObject *ExecutionEngine::newRegExpObject(RegExp *re) { - return memoryManager->allocObject<RegExpObject>(re, global); + return memoryManager->allocObject<RegExpObject>(re); } Heap::RegExpObject *ExecutionEngine::newRegExpObject(const QRegExp &re) diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index 16a043dda5..3b4212020d 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -349,8 +349,8 @@ public: void setDebugger(Debugging::Debugger *) {} void setProfiler(Profiling::Profiler *) {} #else - QV4::Debugging::Debugger *debugger() const { return m_debugger; } - QV4::Profiling::Profiler *profiler() const { return m_profiler; } + QV4::Debugging::Debugger *debugger() const { return m_debugger.data(); } + QV4::Profiling::Profiler *profiler() const { return m_profiler.data(); } void setDebugger(Debugging::Debugger *debugger); void setProfiler(Profiling::Profiler *profiler); @@ -387,7 +387,7 @@ public: Heap::DateObject *newDateObjectFromTime(const QTime &t); Heap::RegExpObject *newRegExpObject(const QString &pattern, int flags); - Heap::RegExpObject *newRegExpObject(RegExp *re, bool global); + Heap::RegExpObject *newRegExpObject(RegExp *re); Heap::RegExpObject *newRegExpObject(const QRegExp &re); Heap::Object *newErrorObject(const Value &value); @@ -458,8 +458,8 @@ private: void failStackLimitCheck(Scope &scope); #ifndef QT_NO_QML_DEBUGGER - QV4::Debugging::Debugger *m_debugger; - QV4::Profiling::Profiler *m_profiler; + QScopedPointer<QV4::Debugging::Debugger> m_debugger; + QScopedPointer<QV4::Profiling::Profiler> m_profiler; #endif }; diff --git a/src/qml/jsruntime/qv4mathobject.cpp b/src/qml/jsruntime/qv4mathobject.cpp index 6fd1509d77..46230b5bc1 100644 --- a/src/qml/jsruntime/qv4mathobject.cpp +++ b/src/qml/jsruntime/qv4mathobject.cpp @@ -46,6 +46,7 @@ #include <QtCore/private/qnumeric_p.h> #include <QtCore/qthreadstorage.h> +#include <math.h> #include <cmath> using namespace QV4; diff --git a/src/qml/jsruntime/qv4qmlcontext.cpp b/src/qml/jsruntime/qv4qmlcontext.cpp index c483fdb7e7..8b9ef149d6 100644 --- a/src/qml/jsruntime/qv4qmlcontext.cpp +++ b/src/qml/jsruntime/qv4qmlcontext.cpp @@ -62,20 +62,17 @@ using namespace QV4; DEFINE_OBJECT_VTABLE(QQmlContextWrapper); DEFINE_MANAGED_VTABLE(QmlContext); -void Heap::QQmlContextWrapper::init(QQmlContextData *context, QObject *scopeObject, bool ownsContext) +void Heap::QQmlContextWrapper::init(QQmlContextData *context, QObject *scopeObject) { Object::init(); readOnly = true; - this->ownsContext = ownsContext; isNullWrapper = false; - this->context = new QQmlGuardedContextData(context); + this->context = new QQmlContextDataRef(context); this->scopeObject.init(scopeObject); } void Heap::QQmlContextWrapper::destroy() { - if (*context && ownsContext) - (*context)->destroy(); delete context; scopeObject.destroy(); Object::destroy(); @@ -318,7 +315,7 @@ Heap::QmlContext *QmlContext::createWorkerContext(ExecutionContext *parent, cons context->isInternal = true; context->isJSContext = true; - Scoped<QQmlContextWrapper> qml(scope, scope.engine->memoryManager->allocObject<QQmlContextWrapper>(context, (QObject*)0, true)); + Scoped<QQmlContextWrapper> qml(scope, scope.engine->memoryManager->allocObject<QQmlContextWrapper>(context, (QObject*)0)); qml->d()->isNullWrapper = true; qml->setReadOnly(false); diff --git a/src/qml/jsruntime/qv4qmlcontext_p.h b/src/qml/jsruntime/qv4qmlcontext_p.h index 2f1dbabaf2..48c9ee2c36 100644 --- a/src/qml/jsruntime/qv4qmlcontext_p.h +++ b/src/qml/jsruntime/qv4qmlcontext_p.h @@ -67,13 +67,12 @@ struct QQmlContextWrapper; namespace Heap { struct QQmlContextWrapper : Object { - void init(QQmlContextData *context, QObject *scopeObject, bool ownsContext = false); + void init(QQmlContextData *context, QObject *scopeObject); void destroy(); bool readOnly; - bool ownsContext; bool isNullWrapper; - QQmlGuardedContextData *context; + QQmlContextDataRef *context; QQmlQPointer<QObject> scopeObject; }; @@ -93,10 +92,6 @@ struct Q_QML_EXPORT QQmlContextWrapper : Object V4_OBJECT2(QQmlContextWrapper, Object) V4_NEEDS_DESTROY - void takeContextOwnership() { - d()->ownsContext = true; - } - inline QObject *getScopeObject() const { return d()->scopeObject; } inline QQmlContextData *getContext() const { return *d()->context; } @@ -119,10 +114,6 @@ struct Q_QML_EXPORT QmlContext : public ExecutionContext QQmlContextData *qmlContext() const { return *d()->qml->context; } - - void takeContextOwnership() { - d()->qml->ownsContext = true; - } }; } diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index 72ad0ce7b7..fb3aa47d1b 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -1040,8 +1040,12 @@ void QObjectWrapper::destroyObject(bool lastCall) QQmlData *ddata = QQmlData::get(h->object(), false); if (ddata) { if (!h->object()->parent() && !ddata->indestructible) { - if (ddata && ddata->ownContext && ddata->context) - ddata->context->emitDestruction(); + if (ddata && ddata->ownContext) { + Q_ASSERT(ddata->ownContext == ddata->context); + ddata->ownContext->emitDestruction(); + ddata->ownContext = 0; + ddata->context = 0; + } // This object is notionally destroyed now ddata->isQueuedForDeletion = true; if (lastCall) diff --git a/src/qml/jsruntime/qv4regexp.cpp b/src/qml/jsruntime/qv4regexp.cpp index 6778145ff1..162f0fba57 100644 --- a/src/qml/jsruntime/qv4regexp.cpp +++ b/src/qml/jsruntime/qv4regexp.cpp @@ -69,9 +69,9 @@ uint RegExp::match(const QString &string, int start, uint *matchOffsets) return JSC::Yarr::interpret(byteCode(), s.characters16(), string.length(), start, matchOffsets); } -Heap::RegExp *RegExp::create(ExecutionEngine* engine, const QString& pattern, bool ignoreCase, bool multiline) +Heap::RegExp *RegExp::create(ExecutionEngine* engine, const QString& pattern, bool ignoreCase, bool multiline, bool global) { - RegExpCacheKey key(pattern, ignoreCase, multiline); + RegExpCacheKey key(pattern, ignoreCase, multiline, global); RegExpCache *cache = engine->regExpCache; if (!cache) @@ -82,7 +82,7 @@ Heap::RegExp *RegExp::create(ExecutionEngine* engine, const QString& pattern, bo return result->d(); Scope scope(engine); - Scoped<RegExp> result(scope, engine->memoryManager->alloc<RegExp>(engine, pattern, ignoreCase, multiline)); + Scoped<RegExp> result(scope, engine->memoryManager->alloc<RegExp>(engine, pattern, ignoreCase, multiline, global)); result->d()->cache = cache; cachedValue.set(engine, result); @@ -90,12 +90,13 @@ Heap::RegExp *RegExp::create(ExecutionEngine* engine, const QString& pattern, bo return result->d(); } -void Heap::RegExp::init(ExecutionEngine* engine, const QString &pattern, bool ignoreCase, bool multiline) +void Heap::RegExp::init(ExecutionEngine* engine, const QString &pattern, bool ignoreCase, bool multiline, bool global) { Base::init(); this->pattern = new QString(pattern); this->ignoreCase = ignoreCase; this->multiLine = multiline; + this->global = global; const char* error = 0; JSC::Yarr::YarrPattern yarrPattern(WTF::String(pattern), ignoreCase, multiline, &error); diff --git a/src/qml/jsruntime/qv4regexp_p.h b/src/qml/jsruntime/qv4regexp_p.h index 7ab12fe245..998f6e3da3 100644 --- a/src/qml/jsruntime/qv4regexp_p.h +++ b/src/qml/jsruntime/qv4regexp_p.h @@ -76,7 +76,7 @@ struct RegExpCacheKey; namespace Heap { struct RegExp : Base { - void init(ExecutionEngine* engine, const QString& pattern, bool ignoreCase, bool multiline); + void init(ExecutionEngine* engine, const QString& pattern, bool ignoreCase, bool multiline, bool global); void destroy(); QString *pattern; @@ -88,6 +88,7 @@ struct RegExp : Base { int subPatternCount; bool ignoreCase; bool multiLine; + bool global; int captureCount() const { return subPatternCount + 1; } }; @@ -111,8 +112,9 @@ struct RegExp : public Managed int subPatternCount() const { return d()->subPatternCount; } bool ignoreCase() const { return d()->ignoreCase; } bool multiLine() const { return d()->multiLine; } + bool global() const { return d()->global; } - static Heap::RegExp *create(ExecutionEngine* engine, const QString& pattern, bool ignoreCase = false, bool multiline = false); + static Heap::RegExp *create(ExecutionEngine* engine, const QString& pattern, bool ignoreCase = false, bool multiline = false, bool global = false); bool isValid() const { return d()->byteCode; } @@ -125,27 +127,30 @@ struct RegExp : public Managed struct RegExpCacheKey { - RegExpCacheKey(const QString &pattern, bool ignoreCase, bool multiLine) + RegExpCacheKey(const QString &pattern, bool ignoreCase, bool multiLine, bool global) : pattern(pattern) , ignoreCase(ignoreCase) , multiLine(multiLine) + , global(global) { } explicit inline RegExpCacheKey(const RegExp::Data *re); bool operator==(const RegExpCacheKey &other) const - { return pattern == other.pattern && ignoreCase == other.ignoreCase && multiLine == other.multiLine; } + { return pattern == other.pattern && ignoreCase == other.ignoreCase && multiLine == other.multiLine && global == other.global; } bool operator!=(const RegExpCacheKey &other) const { return !operator==(other); } QString pattern; uint ignoreCase : 1; uint multiLine : 1; + uint global : 1; }; inline RegExpCacheKey::RegExpCacheKey(const RegExp::Data *re) : pattern(*re->pattern) , ignoreCase(re->ignoreCase) , multiLine(re->multiLine) + , global(re->global) {} inline uint qHash(const RegExpCacheKey& key, uint seed = 0) Q_DECL_NOTHROW diff --git a/src/qml/jsruntime/qv4regexpobject.cpp b/src/qml/jsruntime/qv4regexpobject.cpp index 735951e085..83bfe21c67 100644 --- a/src/qml/jsruntime/qv4regexpobject.cpp +++ b/src/qml/jsruntime/qv4regexpobject.cpp @@ -75,15 +75,13 @@ void Heap::RegExpObject::init() Scope scope(internalClass->engine); Scoped<QV4::RegExpObject> o(scope, this); value.set(scope.engine, QV4::RegExp::create(scope.engine, QString(), false, false)); - global = false; o->initProperties(); } -void Heap::RegExpObject::init(QV4::RegExp *value, bool global) +void Heap::RegExpObject::init(QV4::RegExp *value) { Object::init(); Scope scope(internalClass->engine); - this->global = global; this->value.set(scope.engine, value->d()); Scoped<QV4::RegExpObject> o(scope, this); o->initProperties(); @@ -95,7 +93,6 @@ void Heap::RegExpObject::init(QV4::RegExp *value, bool global) void Heap::RegExpObject::init(const QRegExp &re) { Object::init(); - global = false; // Convert the pattern to a ECMAScript pattern. QString pattern = QT_PREPEND_NAMESPACE(qt_regexp_toCanonical)(re.pattern(), re.patternSyntax()); @@ -232,7 +229,7 @@ void RegExpCtor::construct(const Managed *, Scope &scope, CallData *callData) } Scoped<RegExp> regexp(scope, re->value()); - scope.result = Encode(scope.engine->newRegExpObject(regexp, re->global())); + scope.result = Encode(scope.engine->newRegExpObject(regexp)); return; } @@ -268,13 +265,13 @@ void RegExpCtor::construct(const Managed *, Scope &scope, CallData *callData) } } - Scoped<RegExp> regexp(scope, RegExp::create(scope.engine, pattern, ignoreCase, multiLine)); + Scoped<RegExp> regexp(scope, RegExp::create(scope.engine, pattern, ignoreCase, multiLine, global)); if (!regexp->isValid()) { scope.result = scope.engine->throwSyntaxError(QStringLiteral("Invalid regular expression")); return; } - scope.result = Encode(scope.engine->newRegExpObject(regexp, global)); + scope.result = Encode(scope.engine->newRegExpObject(regexp)); } void RegExpCtor::call(const Managed *that, Scope &scope, CallData *callData) @@ -410,8 +407,6 @@ void RegExpPrototype::method_compile(const BuiltinFunction *, Scope &scope, Call Scoped<RegExpObject> re(scope, scope.result.asReturnedValue()); r->d()->value.set(scope.engine, re->value()); - r->d()->global = re->global(); - RETURN_UNDEFINED(); } template <int index> diff --git a/src/qml/jsruntime/qv4regexpobject_p.h b/src/qml/jsruntime/qv4regexpobject_p.h index 6f54a4ab92..cb2bcbab2d 100644 --- a/src/qml/jsruntime/qv4regexpobject_p.h +++ b/src/qml/jsruntime/qv4regexpobject_p.h @@ -60,6 +60,7 @@ #include "qv4managed_p.h" #include "qv4property_p.h" #include "qv4objectiterator_p.h" +#include "qv4regexp_p.h" #include <QtCore/QString> #include <QtCore/QHash> @@ -74,14 +75,13 @@ namespace QV4 { namespace Heap { #define RegExpObjectMembers(class, Member) \ - Member(class, Pointer, RegExp *, value) \ - Member(class, NoMark, bool, global) + Member(class, Pointer, RegExp *, value) DECLARE_HEAP_OBJECT(RegExpObject, Object) { DECLARE_MARK_TABLE(RegExpObject); void init(); - void init(QV4::RegExp *value, bool global); + void init(QV4::RegExp *value); void init(const QRegExp &re); }; @@ -124,7 +124,7 @@ struct RegExpObject: Object { }; Heap::RegExp *value() const { return d()->value; } - bool global() const { return d()->global; } + bool global() const { return d()->value->global; } void initProperties(); diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index 9737a18812..4b952bcbbc 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -51,6 +51,8 @@ #include "qv4lookup_p.h" #include "qv4function_p.h" #include "qv4numberobject_p.h" +#include "qv4regexp_p.h" +#include "qv4regexpobject_p.h" #include "private/qlocale_tools_p.h" #include "qv4scopedvalue_p.h" #include <private/qv4qmlcontext_p.h> @@ -1477,7 +1479,10 @@ ReturnedValue Runtime::method_getQmlContext(NoThrowEngine *engine) ReturnedValue Runtime::method_regexpLiteral(ExecutionEngine *engine, int id) { - return static_cast<CompiledData::CompilationUnit*>(engine->current->compilationUnit)->runtimeRegularExpressions[id].asReturnedValue(); + Heap::RegExpObject *ro = engine->newRegExpObject( + static_cast<CompiledData::CompilationUnit*>(engine->current->compilationUnit) + ->runtimeRegularExpressions[id].as<RegExp>()); + return ro->asReturnedValue(); } ReturnedValue Runtime::method_getQmlQObjectProperty(ExecutionEngine *engine, const Value &object, int propertyIndex, bool captureRequired) diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp index 81f5c3566c..7c65c97d73 100644 --- a/src/qml/jsruntime/qv4stringobject.cpp +++ b/src/qml/jsruntime/qv4stringobject.cpp @@ -551,7 +551,7 @@ void StringPrototype::method_replace(const BuiltinFunction *, Scope &scope, Call break; } nMatchOffsets += re->captureCount() * 2; - if (!regExp->d()->global) + if (!regExp->global()) break; offset = qMax(offset + 1, matchOffsets[oldSize + 1]); } diff --git a/src/qml/jsruntime/qv4vme_moth.cpp b/src/qml/jsruntime/qv4vme_moth.cpp index 7293630924..5749d0aef3 100644 --- a/src/qml/jsruntime/qv4vme_moth.cpp +++ b/src/qml/jsruntime/qv4vme_moth.cpp @@ -50,6 +50,8 @@ #include <private/qv4math_p.h> #include <private/qv4scopedvalue_p.h> #include <private/qv4lookup_p.h> +#include <private/qv4regexp_p.h> +#include <private/qv4regexpobject_p.h> #include <private/qv4string_p.h> #include <iostream> @@ -457,7 +459,10 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code) MOTH_BEGIN_INSTR(LoadRegExp) // TRACE(value, "%s", instr.value.toString(context)->toQString().toUtf8().constData()); - VALUE(instr.result) = static_cast<CompiledData::CompilationUnit*>(engine->current->compilationUnit)->runtimeRegularExpressions[instr.regExpId]; + Heap::RegExpObject *ro = engine->newRegExpObject( + static_cast<CompiledData::CompilationUnit*>(engine->current->compilationUnit) + ->runtimeRegularExpressions[instr.regExpId].as<RegExp>()); + VALUE(instr.result) = ro; MOTH_END_INSTR(LoadRegExp) MOTH_BEGIN_INSTR(LoadClosure) |