From 74878ba417e7db9fe8f68a55d69a3cc7ee804422 Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Fri, 1 Mar 2013 14:39:59 +0100 Subject: Use official V8 string manipulation methods in QML The QtJSBackend's String::GetCharacter and String::Equals methods are Qt specific and they are not supported by official V8. These methods can be replaced by more "V8-friendly" implementations in QtDeclarative. Thus the mentioned methods can be removed from QtJSBackend to reduce the difference between QtJSBackend and the official V8 source. Change-Id: I5590ca62dc667e64a7f54a7e47a02d350ba0c077 Reviewed-by: Lars Knoll --- src/qml/qml/ftw/qhashedstring_p.h | 10 +++++++--- src/qml/qml/qqmllocale.cpp | 7 +++++-- src/qml/qml/v8/qv8engine_p.h | 6 ++++-- 3 files changed, 16 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/qml/qml/ftw/qhashedstring_p.h b/src/qml/qml/ftw/qhashedstring_p.h index 5fc8443ecd..cdf0717e3a 100644 --- a/src/qml/qml/ftw/qhashedstring_p.h +++ b/src/qml/qml/ftw/qhashedstring_p.h @@ -262,8 +262,9 @@ public: inline uint16_t *utf16Data() const { return (uint16_t *)strData->data(); } inline bool equals(v8::Handle string) const { - return isQString()?string->Equals(utf16Data(), length): - string->Equals(cStrData(), length); + v8::Local data = isQString() ? v8::String::New(utf16Data(), length) + : v8::String::New(cStrData(), length); + return string->Equals(data); } inline bool symbolEquals(const QHashedV8String &string) const { @@ -1183,8 +1184,11 @@ QString QHashedV8String::toString() const QString result; result.reserve(m_hash.length); + v8::String::Value value(m_string); + Q_ASSERT(*value != NULL); + uint16_t* string = *value; for (int i = 0; i < m_hash.length; ++i) - result.append(m_string->GetCharacter(i)); + result.append(string[i]); return result; } diff --git a/src/qml/qml/qqmllocale.cpp b/src/qml/qml/qqmllocale.cpp index e1ac75f5f0..c9ce4773c3 100644 --- a/src/qml/qml/qqmllocale.cpp +++ b/src/qml/qml/qqmllocale.cpp @@ -464,8 +464,11 @@ v8::Handle QQmlNumberExtension::toLocaleString(const v8::Arguments& a if (!args[1]->IsString()) V8THROW_ERROR("Locale: Number.toLocaleString(): Invalid arguments"); v8::Local fs = args[1]->ToString(); - if (!fs.IsEmpty() && fs->Length()) - format = fs->GetCharacter(0); + if (!fs.IsEmpty() && fs->Length()) { + v8::String::Value value(fs); + Q_ASSERT(*value != NULL); + format = **value; + } } int prec = 2; if (args.Length() > 2) { diff --git a/src/qml/qml/v8/qv8engine_p.h b/src/qml/qml/v8/qv8engine_p.h index 090ffaa353..5ae0963178 100644 --- a/src/qml/qml/v8/qv8engine_p.h +++ b/src/qml/qml/v8/qv8engine_p.h @@ -629,8 +629,10 @@ v8::Handle QV8Engine::bindingFlagKey() const // unqualified name in QV8ContextWrapper. bool QV8Engine::startsWithUpper(v8::Handle string) { - uint16_t c = string->GetCharacter(0); - return (c >= 'A' && c <= 'Z') || + v8::String::Value value(string); + Q_ASSERT(*value != NULL); + uint16_t c = **value; + return (c >= 'A' && c <= 'Z') || (c > 127 && QChar::category(c) == QChar::Letter_Uppercase); } -- cgit v1.2.3