From 345a5ee67bf80f7c18869fe080bf7dd7cf4a0d90 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 10 Nov 2014 21:27:52 +0100 Subject: Use heap objects in the remaining managed objects Change-Id: Id6dc6e34113a287a40e0122dfbdf977f0fc1f3b3 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4regexp_p.h | 2 ++ src/qml/jsruntime/qv4regexpobject.cpp | 29 ++++++++++++------------ src/qml/jsruntime/qv4regexpobject_p.h | 4 ++-- src/qml/jsruntime/qv4stringobject.cpp | 8 ++++--- src/qml/qml/qqmlcontextwrapper.cpp | 8 ++++--- src/qml/qml/qqmlcontextwrapper_p.h | 2 +- src/qml/qml/qqmlxmlhttprequest.cpp | 39 +++++++++++++++++---------------- src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 7 +++--- src/qml/qml/v8/qqmlbuiltinfunctions_p.h | 2 +- 9 files changed, 55 insertions(+), 46 deletions(-) (limited to 'src/qml') diff --git a/src/qml/jsruntime/qv4regexp_p.h b/src/qml/jsruntime/qv4regexp_p.h index 1ac85b4ef3..a7827542ef 100644 --- a/src/qml/jsruntime/qv4regexp_p.h +++ b/src/qml/jsruntime/qv4regexp_p.h @@ -70,6 +70,8 @@ struct RegExp : Base { int subPatternCount; bool ignoreCase; bool multiLine; + + int captureCount() const { return subPatternCount + 1; } }; } diff --git a/src/qml/jsruntime/qv4regexpobject.cpp b/src/qml/jsruntime/qv4regexpobject.cpp index a1a0104d7a..44a8b3531e 100644 --- a/src/qml/jsruntime/qv4regexpobject.cpp +++ b/src/qml/jsruntime/qv4regexpobject.cpp @@ -71,14 +71,14 @@ Heap::RegExpObject::RegExpObject(InternalClass *ic) Scope scope(ic->engine); Scoped o(scope, this); - o->d()->value = QV4::RegExp::create(ic->engine, QString(), false, false)->getPointer(); + o->d()->value = QV4::RegExp::create(ic->engine, QString(), false, false)->getPointer()->d(); o->d()->global = false; o->init(ic->engine); } Heap::RegExpObject::RegExpObject(QV4::ExecutionEngine *engine, QV4::RegExp *value, bool global) : Heap::Object(engine->regExpClass) - , value(value) + , value(value->d()) , global(global) { setVTable(QV4::RegExpObject::staticVTable()); @@ -139,7 +139,7 @@ Heap::RegExpObject::RegExpObject(QV4::ExecutionEngine *engine, const QRegExp &re Scope scope(engine); Scoped o(scope, this); - o->d()->value = QV4::RegExp::create(engine, pattern, re.caseSensitivity() == Qt::CaseInsensitive, false)->getPointer(); + o->d()->value = QV4::RegExp::create(engine, pattern, re.caseSensitivity() == Qt::CaseInsensitive, false)->getPointer()->d(); o->init(engine); } @@ -155,7 +155,7 @@ void RegExpObject::init(ExecutionEngine *engine) if (!this->value()) return; - QString p = this->value()->pattern(); + QString p = this->value()->pattern; if (p.isEmpty()) { p = QStringLiteral("(?:)"); } else { @@ -165,8 +165,8 @@ void RegExpObject::init(ExecutionEngine *engine) defineReadonlyProperty(QStringLiteral("source"), (v = engine->newString(p))); defineReadonlyProperty(QStringLiteral("global"), Primitive::fromBoolean(global())); - defineReadonlyProperty(QStringLiteral("ignoreCase"), Primitive::fromBoolean(this->value()->ignoreCase())); - defineReadonlyProperty(QStringLiteral("multiline"), Primitive::fromBoolean(this->value()->multiLine())); + defineReadonlyProperty(QStringLiteral("ignoreCase"), Primitive::fromBoolean(this->value()->ignoreCase)); + defineReadonlyProperty(QStringLiteral("multiline"), Primitive::fromBoolean(this->value()->multiLine)); } @@ -190,8 +190,8 @@ Property *RegExpObject::lastIndexProperty(ExecutionContext *ctx) // have different semantics/flags, but we try to do our best. QRegExp RegExpObject::toQRegExp() const { - Qt::CaseSensitivity caseSensitivity = value()->ignoreCase() ? Qt::CaseInsensitive : Qt::CaseSensitive; - return QRegExp(value()->pattern(), caseSensitivity, QRegExp::RegExp2); + Qt::CaseSensitivity caseSensitivity = value()->ignoreCase ? Qt::CaseInsensitive : Qt::CaseSensitive; + return QRegExp(value()->pattern, caseSensitivity, QRegExp::RegExp2); } QString RegExpObject::toString() const @@ -200,9 +200,9 @@ QString RegExpObject::toString() const result += QLatin1Char('/'); if (global()) result += QLatin1Char('g'); - if (value()->ignoreCase()) + if (value()->ignoreCase) result += QLatin1Char('i'); - if (value()->multiLine()) + if (value()->multiLine) result += QLatin1Char('m'); return result; } @@ -220,9 +220,9 @@ uint RegExpObject::flags() const uint f = 0; if (global()) f |= QV4::RegExpObject::RegExp_Global; - if (value()->ignoreCase()) + if (value()->ignoreCase) f |= QV4::RegExpObject::RegExp_IgnoreCase; - if (value()->multiLine()) + if (value()->multiLine) f |= QV4::RegExpObject::RegExp_Multiline; return f; } @@ -256,7 +256,8 @@ ReturnedValue RegExpCtor::construct(Managed *m, CallData *callData) if (!f->isUndefined()) return ctx->engine()->throwTypeError(); - return Encode(ctx->d()->engine->newRegExpObject(re->value(), re->global())); + Scoped regexp(scope, re->value()); + return Encode(ctx->d()->engine->newRegExpObject(regexp, re->global())); } QString pattern; @@ -368,7 +369,7 @@ ReturnedValue RegExpPrototype::method_exec(CallContext *ctx) } uint* matchOffsets = (uint*)alloca(r->value()->captureCount() * 2 * sizeof(uint)); - const int result = r->value()->match(s, offset, matchOffsets); + const int result = Scoped(scope, r->value())->match(s, offset, matchOffsets); Scoped regExpCtor(scope, ctx->d()->engine->regExpCtor); regExpCtor->d()->clearLastMatch(); diff --git a/src/qml/jsruntime/qv4regexpobject_p.h b/src/qml/jsruntime/qv4regexpobject_p.h index e71e2c21fd..a6a5587ca5 100644 --- a/src/qml/jsruntime/qv4regexpobject_p.h +++ b/src/qml/jsruntime/qv4regexpobject_p.h @@ -62,7 +62,7 @@ struct RegExpObject : Object { RegExpObject(QV4::ExecutionEngine *engine, const QRegExp &re); RegExpObject(InternalClass *ic); - QV4::RegExp *value; + RegExp *value; bool global; }; @@ -98,7 +98,7 @@ struct RegExpObject: Object { Index_ArrayInput = Index_ArrayIndex + 1 }; - RegExp *value() const { return d()->value; } + Heap::RegExp *value() const { return d()->value; } bool global() const { return d()->global; } void init(ExecutionEngine *engine); diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp index 57c12390ff..a21f2b284a 100644 --- a/src/qml/jsruntime/qv4stringobject.cpp +++ b/src/qml/jsruntime/qv4stringobject.cpp @@ -606,8 +606,9 @@ ReturnedValue StringPrototype::method_search(CallContext *ctx) regExp = regExpValue->as(); Q_ASSERT(regExp); } + Scoped re(scope, regExp->value()); uint* matchOffsets = (uint*)alloca(regExp->value()->captureCount() * 2 * sizeof(uint)); - uint result = regExp->value()->match(string, /*offset*/0, matchOffsets); + uint result = re->match(string, /*offset*/0, matchOffsets); if (result == JSC::Yarr::offsetNoMatch) return Encode(-1); return Encode(result); @@ -670,7 +671,7 @@ ReturnedValue StringPrototype::method_split(CallContext *ctx) Scoped re(scope, separatorValue); if (re) { - if (re->value()->pattern().isEmpty()) { + if (re->value()->pattern.isEmpty()) { re = (RegExpObject *)0; separatorValue = ctx->d()->engine->newString(QString()); } @@ -681,7 +682,8 @@ ReturnedValue StringPrototype::method_split(CallContext *ctx) uint offset = 0; uint* matchOffsets = (uint*)alloca(re->value()->captureCount() * 2 * sizeof(uint)); while (true) { - uint result = re->value()->match(text, offset, matchOffsets); + Scoped regexp(scope, re->value()); + uint result = regexp->match(text, offset, matchOffsets); if (result == JSC::Yarr::offsetNoMatch) break; diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp index 115d65ab67..a7b5d58583 100644 --- a/src/qml/qml/qqmlcontextwrapper.cpp +++ b/src/qml/qml/qqmlcontextwrapper.cpp @@ -434,15 +434,17 @@ DEFINE_OBJECT_VTABLE(QQmlIdObjectsArray); Heap::QQmlIdObjectsArray::QQmlIdObjectsArray(ExecutionEngine *engine, QV4::QmlContextWrapper *contextWrapper) : Heap::Object(engine) - , contextWrapper(contextWrapper) + , contextWrapper(contextWrapper->d()) { setVTable(QV4::QQmlIdObjectsArray::staticVTable()); } ReturnedValue QQmlIdObjectsArray::getIndexed(Managed *m, uint index, bool *hasProperty) { - QQmlIdObjectsArray *This = static_cast(m); - QQmlContextData *context = This->d()->contextWrapper->getContext(); + Scope scope(m->engine()); + Scoped This(scope, static_cast(m)); + Scoped contextWrapper(scope, This->d()->contextWrapper); + QQmlContextData *context = contextWrapper->getContext(); if (!context) { if (hasProperty) *hasProperty = false; diff --git a/src/qml/qml/qqmlcontextwrapper_p.h b/src/qml/qml/qqmlcontextwrapper_p.h index a8234e9cb7..317cf4ced2 100644 --- a/src/qml/qml/qqmlcontextwrapper_p.h +++ b/src/qml/qml/qqmlcontextwrapper_p.h @@ -80,7 +80,7 @@ struct QmlContextWrapper : Object { struct QQmlIdObjectsArray : Object { QQmlIdObjectsArray(QV4::ExecutionEngine *engine, QV4::QmlContextWrapper *contextWrapper); - QV4::QmlContextWrapper *contextWrapper; + QmlContextWrapper *contextWrapper; }; } diff --git a/src/qml/qml/qqmlxmlhttprequest.cpp b/src/qml/qml/qqmlxmlhttprequest.cpp index 74f4af1d07..1566971827 100644 --- a/src/qml/qml/qqmlxmlhttprequest.cpp +++ b/src/qml/qml/qqmlxmlhttprequest.cpp @@ -1623,7 +1623,7 @@ struct QQmlXMLHttpRequestWrapper : Object { struct QQmlXMLHttpRequestCtor : FunctionObject { QQmlXMLHttpRequestCtor(ExecutionEngine *engine); - QV4::Object *proto; + Object *proto; }; } @@ -1663,7 +1663,8 @@ struct QQmlXMLHttpRequestCtor : public FunctionObject QV8Engine *engine = that->engine()->v8Engine; QQmlXMLHttpRequest *r = new QQmlXMLHttpRequest(engine, engine->networkAccessManager()); Scoped w(scope, that->engine()->memoryManager->alloc(that->engine(), r)); - w->setPrototype(ctor->d()->proto); + Scoped proto(scope, ctor->d()->proto); + w->setPrototype(proto); return w.asReturnedValue(); } @@ -1716,29 +1717,29 @@ void QQmlXMLHttpRequestCtor::setupProto() ExecutionEngine *v4 = engine(); Scope scope(v4); Scoped p(scope, v4->newObject()); - d()->proto = p.getPointer(); + d()->proto = p.getPointer()->d(); // Methods - d()->proto->defineDefaultProperty(QStringLiteral("open"), method_open); - d()->proto->defineDefaultProperty(QStringLiteral("setRequestHeader"), method_setRequestHeader); - d()->proto->defineDefaultProperty(QStringLiteral("send"), method_send); - d()->proto->defineDefaultProperty(QStringLiteral("abort"), method_abort); - d()->proto->defineDefaultProperty(QStringLiteral("getResponseHeader"), method_getResponseHeader); - d()->proto->defineDefaultProperty(QStringLiteral("getAllResponseHeaders"), method_getAllResponseHeaders); + p->defineDefaultProperty(QStringLiteral("open"), method_open); + p->defineDefaultProperty(QStringLiteral("setRequestHeader"), method_setRequestHeader); + p->defineDefaultProperty(QStringLiteral("send"), method_send); + p->defineDefaultProperty(QStringLiteral("abort"), method_abort); + p->defineDefaultProperty(QStringLiteral("getResponseHeader"), method_getResponseHeader); + p->defineDefaultProperty(QStringLiteral("getAllResponseHeaders"), method_getAllResponseHeaders); // Read-only properties - d()->proto->defineAccessorProperty(QStringLiteral("readyState"), method_get_readyState, 0); - d()->proto->defineAccessorProperty(QStringLiteral("status"),method_get_status, 0); - d()->proto->defineAccessorProperty(QStringLiteral("statusText"),method_get_statusText, 0); - d()->proto->defineAccessorProperty(QStringLiteral("responseText"),method_get_responseText, 0); - d()->proto->defineAccessorProperty(QStringLiteral("responseXML"),method_get_responseXML, 0); + p->defineAccessorProperty(QStringLiteral("readyState"), method_get_readyState, 0); + p->defineAccessorProperty(QStringLiteral("status"),method_get_status, 0); + p->defineAccessorProperty(QStringLiteral("statusText"),method_get_statusText, 0); + p->defineAccessorProperty(QStringLiteral("responseText"),method_get_responseText, 0); + p->defineAccessorProperty(QStringLiteral("responseXML"),method_get_responseXML, 0); // State values - d()->proto->defineReadonlyProperty(QStringLiteral("UNSENT"), Primitive::fromInt32(0)); - d()->proto->defineReadonlyProperty(QStringLiteral("OPENED"), Primitive::fromInt32(1)); - d()->proto->defineReadonlyProperty(QStringLiteral("HEADERS_RECEIVED"), Primitive::fromInt32(2)); - d()->proto->defineReadonlyProperty(QStringLiteral("LOADING"), Primitive::fromInt32(3)); - d()->proto->defineReadonlyProperty(QStringLiteral("DONE"), Primitive::fromInt32(4)); + p->defineReadonlyProperty(QStringLiteral("UNSENT"), Primitive::fromInt32(0)); + p->defineReadonlyProperty(QStringLiteral("OPENED"), Primitive::fromInt32(1)); + p->defineReadonlyProperty(QStringLiteral("HEADERS_RECEIVED"), Primitive::fromInt32(2)); + p->defineReadonlyProperty(QStringLiteral("LOADING"), Primitive::fromInt32(3)); + p->defineReadonlyProperty(QStringLiteral("DONE"), Primitive::fromInt32(4)); } diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp index c4bf9e44a2..cdc76e5c97 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp @@ -1168,7 +1168,7 @@ ReturnedValue QtObject::method_locale(CallContext *ctx) Heap::QQmlBindingFunction::QQmlBindingFunction(QV4::FunctionObject *originalFunction) : QV4::Heap::FunctionObject(originalFunction->scope(), originalFunction->name()) - , originalFunction(originalFunction) + , originalFunction(originalFunction->d()) { setVTable(QV4::QQmlBindingFunction::staticVTable()); bindingKeyFlag = true; @@ -1183,8 +1183,9 @@ void QQmlBindingFunction::initBindingLocation() ReturnedValue QQmlBindingFunction::call(Managed *that, CallData *callData) { - QQmlBindingFunction *This = static_cast(that); - return This->d()->originalFunction->call(callData); + Scope scope(that->engine()); + Scoped function(scope, static_cast(that)->d()->originalFunction); + return function->call(callData); } void QQmlBindingFunction::markObjects(Heap::Base *that, ExecutionEngine *e) diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions_p.h b/src/qml/qml/v8/qqmlbuiltinfunctions_p.h index 8379cbc3a0..4a50111e60 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions_p.h +++ b/src/qml/qml/v8/qqmlbuiltinfunctions_p.h @@ -69,7 +69,7 @@ struct ConsoleObject : Object { struct QQmlBindingFunction : FunctionObject { QQmlBindingFunction(QV4::FunctionObject *originalFunction); - QV4::FunctionObject *originalFunction; + FunctionObject *originalFunction; // Set when the binding is created later QQmlSourceLocation bindingLocation; }; -- cgit v1.2.3