From 9c2ab7af355d0132af771f8784e42c13d1f49183 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Thu, 9 Aug 2012 10:59:31 +1000 Subject: [PATCH] Fix test failures in Qt Location with string lists. 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 --- src/qml/qml/v8/qv8sequencewrapper.cpp | 12 ++++++++++-- src/qml/qml/v8/qv8sequencewrapper_p.h | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/qml/qml/v8/qv8sequencewrapper.cpp b/src/qml/qml/v8/qv8sequencewrapper.cpp index 6bd7238..c4b4e66 100644 --- a/src/qml/qml/v8/qv8sequencewrapper.cpp +++ b/src/qml/qml/v8/qv8sequencewrapper.cpp @@ -75,8 +75,7 @@ void QV8SequenceWrapper::init(QV8Engine *engine) "})"); m_sort = qPersistentNew(v8::FunctionTemplate::New(Sort)->GetFunction()); - m_arrayPrototype = qPersistentNew(v8::Array::New(1)->GetPrototype()->ToObject()->Clone()); - m_arrayPrototype->Set(v8::String::New("sort"), m_sort); + m_arrayPrototype = qPersistentNew(v8::Array::New(1)->GetPrototype()); v8::Local defaultSortCompareScript = v8::Script::Compile(engine->toString(defaultSortString)); m_defaultSortComparer = qPersistentNew(v8::Handle(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(ft->GetFunction()); @@ -246,6 +248,12 @@ v8::Handle QV8SequenceWrapper::ValueOfGetter(v8::Local pr return info.Data(); } +v8::Handle QV8SequenceWrapper::SortGetter(v8::Local property, const v8::AccessorInfo &info) +{ + Q_UNUSED(property); + return info.Data(); +} + v8::Handle QV8SequenceWrapper::Sort(const v8::Arguments &args) { int argCount = args.Length(); diff --git a/src/qml/qml/v8/qv8sequencewrapper_p.h b/src/qml/qml/v8/qv8sequencewrapper_p.h index 08bc614..141d6f4 100644 --- a/src/qml/qml/v8/qv8sequencewrapper_p.h +++ b/src/qml/qml/v8/qv8sequencewrapper_p.h @@ -87,7 +87,7 @@ private: v8::Persistent m_toString; v8::Persistent m_valueOf; v8::Persistent m_sort; - v8::Persistent m_arrayPrototype; + v8::Persistent m_arrayPrototype; v8::Persistent m_defaultSortComparer; static v8::Handle IndexedGetter(quint32 index, const v8::AccessorInfo &info); @@ -99,6 +99,7 @@ private: static v8::Handle ToStringGetter(v8::Local property, const v8::AccessorInfo &info); static v8::Handle ToString(const v8::Arguments &args); static v8::Handle ValueOfGetter(v8::Local property, const v8::AccessorInfo &info); + static v8::Handle SortGetter(v8::Local property, const v8::AccessorInfo &info); static v8::Handle ValueOf(const v8::Arguments &args); static v8::Handle Getter(v8::Local property, const v8::AccessorInfo &info); static v8::Handle Setter(v8::Local property, v8::Local value, const v8::AccessorInfo &info); -- 1.7.2.5