From 797be6d11b0bfe6c46b4e69cd6933990925b6093 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 10 Jun 2011 14:13:01 +1000 Subject: Use fast property accessors for readonly properties --- src/declarative/qml/v8/qv8qobjectwrapper.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/declarative/qml/v8/qv8qobjectwrapper.cpp b/src/declarative/qml/v8/qv8qobjectwrapper.cpp index d1bf0e399c..413a4a1181 100644 --- a/src/declarative/qml/v8/qv8qobjectwrapper.cpp +++ b/src/declarative/qml/v8/qv8qobjectwrapper.cpp @@ -633,6 +633,21 @@ static void FastValueSetter(v8::Local, v8::Local value, StoreProperty(resource->engine, object, pdata, value); } +static void FastValueSetterReadOnly(v8::Local property, v8::Local, + const v8::AccessorInfo& info) +{ + QV8QObjectResource *resource = v8_resource_cast(info.This()); + + if (!resource || resource->object.isNull()) + return; + + QV8Engine *v8engine = resource->engine; + + QString error = QLatin1String("Cannot assign to non-existent property \"") + + v8engine->toString(property) + QLatin1Char('\"'); + v8::ThrowException(v8::Exception::Error(v8engine->toString(error))); +} + static void WeakQObjectReferenceCallback(v8::Persistent handle, void *) { Q_ASSERT(handle->IsObject()); @@ -680,12 +695,15 @@ v8::Local QDeclarativePropertyCache::newQObject(QObject *object, QV8 // its not guarenteed that this is a win overall. We need to try and measure the cost. for (StringCache::ConstIterator iter = stringCache.begin(); iter != stringCache.end(); ++iter) { Data *property = *iter; - if (property->isFunction() || !property->isWritable() || + if (property->isFunction() || property->coreIndex >= 0x7FFF || property->notifyIndex >= 0x7FFF || property->coreIndex == 0) continue; v8::AccessorGetter fastgetter = 0; + v8::AccessorSetter fastsetter = FastValueSetter; + if (!property->isWritable()) + fastsetter = FastValueSetterReadOnly; if (property->isQObject()) fastgetter = QObjectValueGetter; @@ -722,7 +740,7 @@ v8::Local QDeclarativePropertyCache::newQObject(QObject *object, QV8 ft->InstanceTemplate()->SetHasExternalResource(true); } - ft->InstanceTemplate()->SetAccessor(engine->toString(name), fastgetter, FastValueSetter, + ft->InstanceTemplate()->SetAccessor(engine->toString(name), fastgetter, fastsetter, v8::Integer::NewFromUnsigned(data)); } } -- cgit v1.2.3