From kde-commits Fri Mar 18 01:33:29 2011 From: Maks Orlovich Date: Fri, 18 Mar 2011 01:33:29 +0000 To: kde-commits Subject: =?utf-8?q?=5Bkdelibs=5D_/=3A_Get_rid_of_bogus_=7BUString=2CIdent?= Message-Id: <20110318013329.1D1A5A60BB () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=130041205925705 Git commit d739fd894ffa1725a33f19473ffc20e9beb2e541 by Maks Orlovich. Committed on 01/03/2011 at 01:01. Pushed by orlovich into branch 'master'. Get rid of bogus {UString,Identifier}::toUInt32. Despite the name, it did something different from ES's toUInt32 op, and basically every place we used it we wanted toArrayIndex/toStrictUInt32 instead. M +3 -3 khtml/ecma/kjs_binding.h M +3 -3 khtml/ecma/kjs_html.cpp M +3 -3 khtml/ecma/kjs_navigator.cpp M +3 -3 kjs/function.cpp M +0 -2 kjs/identifier.h M +0 -32 kjs/ustring.cpp M +0 -9 kjs/ustring.h http://commits.kde.org/kdelibs/d739fd894ffa1725a33f19473ffc20e9beb2e541 diff --git a/khtml/ecma/kjs_binding.h b/khtml/ecma/kjs_binding.h index 0731dd4..b967744 100644 --- a/khtml/ecma/kjs_binding.h +++ b/khtml/ecma/kjs_binding.h @@ -273,7 +273,7 @@ namespace KJS { const Identifier& propertyName, PropertySlot& slot) { bool ok; - unsigned u = propertyName.toUInt32(&ok); + unsigned u = propertyName.toArrayIndex(&ok); if (ok && u < listObj.length()) { slot.setCustomIndex(thisObj, u, indexGetterAdapter); return true; @@ -289,7 +289,7 @@ namespace KJS { const Identifier& propertyName, PropertySlot& slot) { bool ok; - unsigned u = propertyName.toUInt32(&ok); + unsigned u = propertyName.toArrayIndex(&ok); if (ok && u < lengthLimit) { slot.setCustomIndex(thisObj, u, indexGetterAdapter); return true; @@ -311,7 +311,7 @@ namespace KJS { inline bool getIndexSlot(ThisImp* thisObj, const Identifier& propertyName, PropertySlot& slot) { bool ok; - unsigned u = propertyName.toUInt32(&ok); + unsigned u = propertyName.toArrayIndex(&ok); if (ok) { slot.setCustomIndex(thisObj, u, indexGetterAdapter); return true; diff --git a/khtml/ecma/kjs_html.cpp b/khtml/ecma/kjs_html.cpp index db884a7..f73f051 100644 --- a/khtml/ecma/kjs_html.cpp +++ b/khtml/ecma/kjs_html.cpp @@ -3119,7 +3119,7 @@ JSValue* KJS::HTMLCollection::callAsFunction(ExecState *exec, JSObject *, const // support for document.all() etc. bool ok; UString s = args[0]->toString(exec); - unsigned int u = s.toUInt32(&ok, false); + unsigned int u = s.toArrayIndex(&ok); if (ok) return getDOMNode(exec, collection.item(u)); // support for document.images('') etc. @@ -3129,7 +3129,7 @@ JSValue* KJS::HTMLCollection::callAsFunction(ExecState *exec, JSObject *, const { bool ok; UString s = args[0]->toString(exec); - unsigned int u = args[1]->toString(exec).toUInt32(&ok, false); + unsigned int u = args[1]->toString(exec).toArrayIndex(&ok); if (ok) { DOM::DOMString pstr = s.domString(); @@ -3190,7 +3190,7 @@ JSValue* KJS::HTMLCollectionProtoFunc::callAsFunction(ExecState *exec, JSObject // support for item() (DOM) UString s = args[0]->toString(exec); bool ok; - unsigned int u = s.toUInt32(&ok, false); + unsigned int u = s.toArrayIndex(&ok); if (ok) { return getDOMNode(exec,coll.item(u)); } diff --git a/khtml/ecma/kjs_navigator.cpp b/khtml/ecma/kjs_navigator.cpp index 1ece78a..cc18a2b 100644 --- a/khtml/ecma/kjs_navigator.cpp +++ b/khtml/ecma/kjs_navigator.cpp @@ -431,7 +431,7 @@ bool Plugins::getOwnPropertySlot(ExecState *exec, const Identifier &propertyName if (pluginsEnabled()) { // plugins[#] bool ok; - unsigned int i = propertyName.toUInt32(&ok); + unsigned int i = propertyName.toArrayIndex(&ok); if (ok && i < static_cast(plugins->count())) { slot.setCustomIndex(this, i, indexGetter); return true; @@ -522,7 +522,7 @@ bool MimeTypes::getOwnPropertySlot(ExecState *exec, const Identifier& propertyNa if (pluginsEnabled()) { // mimeTypes[#] bool ok; - unsigned int i = propertyName.toUInt32(&ok); + unsigned int i = propertyName.toArrayIndex(&ok); if (ok && i < static_cast(mimes->count())) { slot.setCustomIndex(this, i, indexGetter); return true; @@ -624,7 +624,7 @@ bool Plugin::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, // plugin[#] bool ok; - unsigned int i = propertyName.toUInt32(&ok); + unsigned int i = propertyName.toArrayIndex(&ok); if (ok && i < static_cast(m_info->mimes.count())) { slot.setCustomIndex(this, i, indexGetter); return true; diff --git a/kjs/function.cpp b/kjs/function.cpp index f01d0d8..5f39ae6 100644 --- a/kjs/function.cpp +++ b/kjs/function.cpp @@ -372,7 +372,7 @@ IndexToNameMap::~IndexToNameMap() { bool IndexToNameMap::isMapped(const Identifier &index) const { bool indexIsNumber; - int indexAsNumber = index.toUInt32(&indexIsNumber); + int indexAsNumber = index.toStrictUInt32(&indexIsNumber); if (!indexIsNumber) return false; @@ -389,7 +389,7 @@ bool IndexToNameMap::isMapped(const Identifier &index) const void IndexToNameMap::unMap(const Identifier &index) { bool indexIsNumber; - int indexAsNumber = index.toUInt32(&indexIsNumber); + int indexAsNumber = index.toStrictUInt32(&indexIsNumber); assert(indexIsNumber && indexAsNumber < size); @@ -404,7 +404,7 @@ Identifier& IndexToNameMap::operator[](int index) Identifier& IndexToNameMap::operator[](const Identifier &index) { bool indexIsNumber; - int indexAsNumber = index.toUInt32(&indexIsNumber); + int indexAsNumber = index.toStrictUInt32(&indexIsNumber); assert(indexIsNumber && indexAsNumber < size); diff --git a/kjs/identifier.h b/kjs/identifier.h index b3c8f68..441d1a1 100644 --- a/kjs/identifier.h +++ b/kjs/identifier.h @@ -86,8 +86,6 @@ namespace KJS { */ bool isEmpty() const { return _ustring.isEmpty(); } - uint32_t toUInt32(bool* ok) const { return _ustring.toUInt32(ok); } - uint32_t toUInt32(bool* ok, bool tolerateEmptyString) const { return _ustring.toUInt32(ok, tolerateEmptyString); }; uint32_t toStrictUInt32(bool* ok) const { return _ustring.toStrictUInt32(ok); } unsigned toArrayIndex(bool* ok) const { return _ustring.toArrayIndex(ok); } double toDouble() const { return _ustring.toDouble(); } diff --git a/kjs/ustring.cpp b/kjs/ustring.cpp index 7eff52c..0d25862 100644 --- a/kjs/ustring.cpp +++ b/kjs/ustring.cpp @@ -1080,38 +1080,6 @@ double UString::toDouble() const return toDouble(false, true); } -uint32_t UString::toUInt32(bool *ok) const -{ - double d = toDouble(); - bool b = true; - - if (d != static_cast(d)) { - b = false; - d = 0; - } - - if (ok) - *ok = b; - - return static_cast(d); -} - -uint32_t UString::toUInt32(bool *ok, bool tolerateEmptyString) const -{ - double d = toDouble(false, tolerateEmptyString); - bool b = true; - - if (d != static_cast(d)) { - b = false; - d = 0; - } - - if (ok) - *ok = b; - - return static_cast(d); -} - uint32_t UString::toStrictUInt32(bool *ok) const { if (ok) diff --git a/kjs/ustring.h b/kjs/ustring.h index ec9c63b..49370ef 100644 --- a/kjs/ustring.h +++ b/kjs/ustring.h @@ -379,15 +379,6 @@ namespace KJS { * Attempts an conversion to a 32-bit integer. ok will be set * according to the success. */ - uint32_t toUInt32(bool *ok = 0) const; - /** - * Attempts an conversion to a 32-bit integer. ok will be set - * according to the success. - * - * @param tolerateEmptyString if false, toUInt32 will return false - * for *ok for an empty string. - */ - uint32_t toUInt32(bool *ok, bool tolerateEmptyString) const; uint32_t toStrictUInt32(bool *ok = 0) const; /**