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/qv4identifier.cpp | 2 | ||||
-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 | 10 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4regexp_p.h | 13 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4regexpobject.cpp | 14 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4regexpobject_p.h | 8 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4runtime.cpp | 8 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4runtimeapi_p.h | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4stringobject.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4value_p.h | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4vme_moth.cpp | 4 |
16 files changed, 65 insertions, 71 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index d10fd78973..d63320b595 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -134,10 +134,6 @@ ExecutionEngine::ExecutionEngine() , 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); @@ -469,12 +465,6 @@ ExecutionEngine::ExecutionEngine() 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; @@ -502,13 +492,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 @@ -650,21 +640,17 @@ Heap::DateObject *ExecutionEngine::newDateObjectFromTime(const QTime &t) Heap::RegExpObject *ExecutionEngine::newRegExpObject(const QString &pattern, int flags) { bool global = (flags & QV4::CompiledData::RegExp::RegExp_Global); - bool ignoreCase = false; - bool multiline = false; - if (flags & QV4::CompiledData::RegExp::RegExp_IgnoreCase) - ignoreCase = true; - if (flags & QV4::CompiledData::RegExp::RegExp_Multiline) - multiline = true; + bool ignoreCase = (flags & QV4::CompiledData::RegExp::RegExp_IgnoreCase); + bool multiline = (flags & QV4::CompiledData::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 fcadf57508..0f9027ea5f 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -371,8 +371,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); @@ -408,7 +408,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); @@ -476,8 +476,8 @@ public: private: #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/qv4identifier.cpp b/src/qml/jsruntime/qv4identifier.cpp index 6260fd0cc8..e35f72b820 100644 --- a/src/qml/jsruntime/qv4identifier.cpp +++ b/src/qml/jsruntime/qv4identifier.cpp @@ -152,7 +152,7 @@ const IdentifierHashEntry *IdentifierHashBase::lookup(const QString &str) const return 0; Q_ASSERT(d->entries); - uint hash = String::createHashValue(str.constData(), str.length(), Q_NULLPTR); + uint hash = String::createHashValue(str.constData(), str.length(), nullptr); uint idx = hash % d->alloc; while (1) { if (!d->entries[idx].identifier) diff --git a/src/qml/jsruntime/qv4mathobject.cpp b/src/qml/jsruntime/qv4mathobject.cpp index 5419e45038..0c94c1ac43 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 b182e3ab83..ce0c89be57 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(); @@ -314,7 +311,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 9faf58d496..f0782c7ee1 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 400d0f8cb2..5bd3bcb439 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -1045,8 +1045,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 3032363cb4..fb49def317 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>(pattern, ignoreCase, multiline)); + Scoped<RegExp> result(scope, engine->memoryManager->alloc<RegExp>(pattern, ignoreCase, multiline, global)); result->d()->cache = cache; cachedValue.set(engine, result); @@ -90,12 +90,14 @@ Heap::RegExp *RegExp::create(ExecutionEngine* engine, const QString& pattern, bo return result->d(); } -void Heap::RegExp::init(const QString &pattern, bool ignoreCase, bool multiline) +void Heap::RegExp::init(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; + valid = false; const char* error = 0; diff --git a/src/qml/jsruntime/qv4regexp_p.h b/src/qml/jsruntime/qv4regexp_p.h index 59277ca3cd..498468e165 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(const QString& pattern, bool ignoreCase, bool multiline); + void init(const QString& pattern, bool ignoreCase, bool multiline, bool global); void destroy(); QString *pattern; @@ -95,6 +95,7 @@ struct RegExp : Base { int subPatternCount; bool ignoreCase; bool multiLine; + bool global; bool valid; int captureCount() const { return subPatternCount + 1; } @@ -119,8 +120,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()->valid; } @@ -133,27 +135,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 d4d646be3f..c42c018f9d 100644 --- a/src/qml/jsruntime/qv4regexpobject.cpp +++ b/src/qml/jsruntime/qv4regexpobject.cpp @@ -72,15 +72,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(); @@ -92,7 +90,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()); @@ -228,7 +225,7 @@ ReturnedValue RegExpCtor::construct(const Managed *m, CallData *callData) return scope.engine->throwTypeError(); Scoped<RegExp> regexp(scope, re->value()); - return Encode(scope.engine->newRegExpObject(regexp, re->global())); + return Encode(scope.engine->newRegExpObject(regexp)); } QString pattern; @@ -258,12 +255,12 @@ ReturnedValue RegExpCtor::construct(const Managed *m, 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()) { return scope.engine->throwSyntaxError(QStringLiteral("Invalid regular expression")); } - return Encode(scope.engine->newRegExpObject(regexp, global)); + return Encode(scope.engine->newRegExpObject(regexp)); } ReturnedValue RegExpCtor::call(const Managed *that, CallData *callData) @@ -445,8 +442,7 @@ ReturnedValue RegExpPrototype::method_compile(const BuiltinFunction *b, CallData Scoped<RegExpObject> re(scope, jsCall.callAsConstructor()); r->d()->value.set(scope.engine, re->value()); - r->d()->global = re->global(); - RETURN_UNDEFINED(); + return Encode::undefined(); } template <int index> diff --git a/src/qml/jsruntime/qv4regexpobject_p.h b/src/qml/jsruntime/qv4regexpobject_p.h index b808ec38cf..7432840fcd 100644 --- a/src/qml/jsruntime/qv4regexpobject_p.h +++ b/src/qml/jsruntime/qv4regexpobject_p.h @@ -58,6 +58,7 @@ #include "qv4managed_p.h" #include "qv4property_p.h" #include "qv4objectiterator_p.h" +#include "qv4regexp_p.h" #include <QtCore/QString> #include <QtCore/QHash> @@ -72,14 +73,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); }; @@ -122,7 +122,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 5d0c91d9ef..2e97d8074a 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 "qv4jscall_p.h" @@ -1239,6 +1241,12 @@ ReturnedValue Runtime::method_loadQmlContext(NoThrowEngine *engine) return engine->qmlContext()->asReturnedValue(); } +ReturnedValue Runtime::method_regexpLiteral(ExecutionEngine *engine, int id) +{ + Heap::RegExpObject *ro = engine->newRegExpObject(engine->currentStackFrame->v4Function->compilationUnit->runtimeRegularExpressions[id].as<RegExp>()); + return ro->asReturnedValue(); +} + ReturnedValue Runtime::method_loadQmlScopeObjectProperty(ExecutionEngine *engine, const Value &context, int propertyIndex, bool captureRequired) { const QmlContext &c = static_cast<const QmlContext &>(context); diff --git a/src/qml/jsruntime/qv4runtimeapi_p.h b/src/qml/jsruntime/qv4runtimeapi_p.h index d5814abf36..7d32a81bc2 100644 --- a/src/qml/jsruntime/qv4runtimeapi_p.h +++ b/src/qml/jsruntime/qv4runtimeapi_p.h @@ -179,6 +179,8 @@ struct ExceptionCheck<void (*)(QV4::NoThrowEngine *, A, B, C)> { F(Bool, compareInstanceof, (ExecutionEngine *engine, const Value &left, const Value &right)) \ F(Bool, compareIn, (ExecutionEngine *engine, const Value &left, const Value &right)) \ \ + F(ReturnedValue, regexpLiteral, (ExecutionEngine *engine, int id)) \ + \ /* qml */ \ F(ReturnedValue, loadQmlContext, (NoThrowEngine *engine)) \ F(ReturnedValue, loadQmlImportedScripts, (NoThrowEngine *engine)) \ diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp index d6dbeacb2d..9e03913730 100644 --- a/src/qml/jsruntime/qv4stringobject.cpp +++ b/src/qml/jsruntime/qv4stringobject.cpp @@ -554,7 +554,7 @@ ReturnedValue StringPrototype::method_replace(const BuiltinFunction *b, CallData 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/qv4value_p.h b/src/qml/jsruntime/qv4value_p.h index 17aea4e022..63433b7955 100644 --- a/src/qml/jsruntime/qv4value_p.h +++ b/src/qml/jsruntime/qv4value_p.h @@ -608,7 +608,7 @@ struct Q_QML_PRIVATE_EXPORT Primitive : public Value inline Primitive Primitive::undefinedValue() { Primitive v; - v.setM(Q_NULLPTR); + v.setM(nullptr); return v; } diff --git a/src/qml/jsruntime/qv4vme_moth.cpp b/src/qml/jsruntime/qv4vme_moth.cpp index b3b8d7363f..f27a7d452c 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 <private/qv4profiling_p.h> #include <private/qqmljavascriptexpression_p.h> @@ -605,7 +607,7 @@ QV4::ReturnedValue VME::exec(CallData *callData, QV4::Function *function) MOTH_END_INSTR(LoadRuntimeString) MOTH_BEGIN_INSTR(LoadRegExp) - acc = function->compilationUnit->runtimeRegularExpressions[regExpId].asReturnedValue(); + acc = Runtime::method_regexpLiteral(engine, regExpId); MOTH_END_INSTR(LoadRegExp) MOTH_BEGIN_INSTR(LoadClosure) |