Fix test failures in Qt Location with string lists.
authorGlenn Watson <glenn.watson@nokia.com>
Thu, 9 Aug 2012 00:59:31 +0000 (10:59 +1000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 9 Aug 2012 03:56:32 +0000 (05:56 +0200)
Cloning the V8 prototype introduces some unexpected behaviour in
the way string lists are used in Qt Location. Instead, leave the
prototype intact and used a named property accessor to return the
sort method for sequence wrappers.

A test case will be added to declarative once a more isolated test
case has been created.

Change-Id: I533a66f60af4394a2cc8c938fdfc13bd193f0065
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>

src/qml/qml/v8/qv8sequencewrapper.cpp
src/qml/qml/v8/qv8sequencewrapper_p.h

index 6bd7238..c4b4e66 100644 (file)
@@ -75,8 +75,7 @@ void QV8SequenceWrapper::init(QV8Engine *engine)
         "})");
 
     m_sort = qPersistentNew<v8::Function>(v8::FunctionTemplate::New(Sort)->GetFunction());
-    m_arrayPrototype = qPersistentNew<v8::Object>(v8::Array::New(1)->GetPrototype()->ToObject()->Clone());
-    m_arrayPrototype->Set(v8::String::New("sort"), m_sort);
+    m_arrayPrototype = qPersistentNew<v8::Value>(v8::Array::New(1)->GetPrototype());
     v8::Local<v8::Script> defaultSortCompareScript = v8::Script::Compile(engine->toString(defaultSortString));
     m_defaultSortComparer = qPersistentNew<v8::Function>(v8::Handle<v8::Function>(v8::Function::Cast(*defaultSortCompareScript->Run())));
 
@@ -92,6 +91,9 @@ void QV8SequenceWrapper::init(QV8Engine *engine)
     ft->InstanceTemplate()->SetAccessor(v8::String::New("valueOf"), ValueOfGetter, 0,
                                         m_valueOf, v8::DEFAULT,
                                         v8::PropertyAttribute(v8::ReadOnly | v8::DontDelete | v8::DontEnum));
+    ft->InstanceTemplate()->SetAccessor(v8::String::New("sort"), SortGetter, 0,
+                                        m_sort, v8::DEFAULT,
+                                        v8::PropertyAttribute(v8::ReadOnly | v8::DontDelete | v8::DontEnum));
     ft->InstanceTemplate()->SetHasExternalResource(true);
     ft->InstanceTemplate()->MarkAsUseUserObjectComparison();
     m_constructor = qPersistentNew<v8::Function>(ft->GetFunction());
@@ -246,6 +248,12 @@ v8::Handle<v8::Value> QV8SequenceWrapper::ValueOfGetter(v8::Local<v8::String> pr
     return info.Data();
 }
 
+v8::Handle<v8::Value> QV8SequenceWrapper::SortGetter(v8::Local<v8::String> property, const v8::AccessorInfo &info)
+{
+    Q_UNUSED(property);
+    return info.Data();
+}
+
 v8::Handle<v8::Value> QV8SequenceWrapper::Sort(const v8::Arguments &args)
 {
     int argCount = args.Length();
index 08bc614..141d6f4 100644 (file)
@@ -87,7 +87,7 @@ private:
     v8::Persistent<v8::Function> m_toString;
     v8::Persistent<v8::Function> m_valueOf;
     v8::Persistent<v8::Function> m_sort;
-    v8::Persistent<v8::Object> m_arrayPrototype;
+    v8::Persistent<v8::Value> m_arrayPrototype;
     v8::Persistent<v8::Function> m_defaultSortComparer;
 
     static v8::Handle<v8::Value> IndexedGetter(quint32 index, const v8::AccessorInfo &info);
@@ -99,6 +99,7 @@ private:
     static v8::Handle<v8::Value> ToStringGetter(v8::Local<v8::String> property, const v8::AccessorInfo &info);
     static v8::Handle<v8::Value> ToString(const v8::Arguments &args);
     static v8::Handle<v8::Value> ValueOfGetter(v8::Local<v8::String> property, const v8::AccessorInfo &info);
+    static v8::Handle<v8::Value> SortGetter(v8::Local<v8::String> property, const v8::AccessorInfo &info);
     static v8::Handle<v8::Value> ValueOf(const v8::Arguments &args);
     static v8::Handle<v8::Value> Getter(v8::Local<v8::String> property, const v8::AccessorInfo &info);
     static v8::Handle<v8::Value> Setter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo &info);