diff options
author | Glenn Watson <glenn.watson@nokia.com> | 2012-08-09 10:59:31 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-09 05:56:32 +0200 |
commit | 9c2ab7af355d0132af771f8784e42c13d1f49183 (patch) | |
tree | becee7b0b07997d3e056d0a1c31adb63d5a22737 | |
parent | 409d25b659bde31c26ebd3366a57f770c158e19f (diff) |
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 <michael.brasser@nokia.com>
-rw-r--r-- | src/qml/qml/v8/qv8sequencewrapper.cpp | 12 | ||||
-rw-r--r-- | 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 6bd72387b5..c4b4e662f5 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::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(); diff --git a/src/qml/qml/v8/qv8sequencewrapper_p.h b/src/qml/qml/v8/qv8sequencewrapper_p.h index 08bc6146f7..141d6f4428 100644 --- a/src/qml/qml/v8/qv8sequencewrapper_p.h +++ b/src/qml/qml/v8/qv8sequencewrapper_p.h @@ -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); |