From kde-commits Tue Jul 26 21:11:25 2005 From: Harri Porten Date: Tue, 26 Jul 2005 21:11:25 +0000 To: kde-commits Subject: branches/KDE/3.5/kdelibs/kjs Message-Id: <1122412285.903356.28756.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=112241230116304 SVN commit 439011 by porten: getting the toString() and toLocaleString() behavior in line with other browsers. Didn't find it documented in the spec like that. M +6 -0 ChangeLog M +31 -9 array_object.cpp --- branches/KDE/3.5/kdelibs/kjs/ChangeLog #439010:439011 @@ -1,3 +1,9 @@ +2005-07-26 Harri Porten + + * array_object.cpp: the to*String() logic was more involved + that I originally thought. Fixes bugs of our and the JSC + implementation. + 2005-07-24 Harri Porten * array_object.cpp: harmonized toLocaleString implementation --- branches/KDE/3.5/kdelibs/kjs/array_object.cpp #439010:439011 @@ -489,17 +489,39 @@ if (element.type() == UndefinedType || element.type() == NullType) continue; - Object o = element.toObject(exec); - Object conversionFunction; + bool fallback = false; if (id == ToLocaleString) { - conversionFunction = Object::dynamicCast(o.get(exec, toLocaleStringPropertyName)); - } else { - conversionFunction = Object::dynamicCast(o.get(exec, toStringPropertyName)); + Object o = element.toObject(exec); + Object conversionFunction = + Object::dynamicCast(o.get(exec, toLocaleStringPropertyName)); + if (conversionFunction.isValid() && + conversionFunction.implementsCall()) { + str += conversionFunction.call(exec, o, List()).toString(exec); + } else { + // try toString() fallback + fallback = true; + } } - // TODO: check. Mozilla throws exception on errors... - if (conversionFunction.isValid() && conversionFunction.implementsCall()) - str += conversionFunction.call(exec, o, List()).toString(exec); - + if (id == ToString || id == Join || fallback) { + if (element.type() == ObjectType) { + Object o = Object::dynamicCast(element); + Object conversionFunction = + Object::dynamicCast(o.get(exec, toStringPropertyName)); + if (conversionFunction.isValid() && + conversionFunction.implementsCall()) { + str += conversionFunction.call(exec, o, List()).toString(exec); + } else { + UString msg = "Can't convert " + o.className() + + " object to string"; + Object error = Error::create(exec, RangeError, + msg.cstring().c_str()); + exec->setException(error); + return error; + } + } else { + str += element.toString(exec); + } + } if ( exec->hadException() ) break; }