[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/KDE/3.5/kdelibs/kjs
From:       Harri Porten <porten () kde ! org>
Date:       2005-07-26 21:11:25
Message-ID: 1122412285.903356.28756.nullmailer () svn ! kde ! org
[Download RAW message or body]

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  <porten@kde.org>
+
+	* 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  <porten@kde.org>
 
 	* 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;
     }
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic