Re: Fwd: Re: Javascript and konq crash

Eva Brucherseifer <[email protected]>
Newsgroups gmane.comp.kde.devel.konq-e,gmane.comp.kde.devel.kfm
Organization basysKom GmbH
Message-ID <[email protected]>
Hi,

I've created the attached patch, which at least doesn't break anything visible 
to me:
- it uses UString::from(double) from the cvs version below
- I also tried to come up with replacements for the other usages of kjs_dtoa. 
I am not sure it is correct though. The conversion code didn't exist at all 
before kjs_dtoa was introduced. 
- kjs_strtod was replace by strtod

Maybe someone with more insight into kjs can have a look?

Thanks,
eva

Am Montag, 27. März 2006 18:01 schrieb Harri Porten:
> On Mon, 27 Mar 2006, Yan Seiner wrote:
> > Thanks for the pointer....  I am a complete newcomer to KDE / kfm
> > development....
> >
> > Where and how do I find earlier versions of KJS?  I am assuming there is
> > a CVS/SVN/??? archive somewhere, along with a versioning guide?  And how
> > far back do I need to go?
>
> Yes. You'll find instructions here:
>
>   http://developer.kde.org/source/anonsvn.html
>
> This one still uses the old-style conversion:
>
>  
> http://websvn.kde.org/trunk/kdelibs/kjs/ustring.cpp?rev=199142&view=markup
>
> Harri.
> _______________________________________________
> konq-e mailing list
> [email protected]
> https://mail.kde.org/mailman/listinfo/konq-e

-- 
Eva Brucherseifer
General Manager

basysKom GmbH
Robert-Bosch-Str. 7 | 64293 Darmstadt | Germany
Tel: +49 6151 3969-961 | Fax: -736 | Mobile: +49 170 5533642
[email protected] | www.basyskom.de

_______________________________________________
konq-e mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/konq-e
kjs_dtoa_arm.patch (text/x-diff, 3.5 KB)
--- dtoa.cpp	2006-01-30 16:41:59.000000000 +0100
+++ kjs.works/dtoa.cpp	2006-03-30 16:30:18.000000000 +0200
@@ -1,3 +1,4 @@
+#ifdef KONQ_EMBEDDED
 /****************************************************************
  *
  * The author of this software is David M. Gay.
@@ -3317,3 +3318,5 @@
 #ifdef __cplusplus
 }
 #endif
+
+#endif
\ No newline at end of file
--- dtoa.h	2006-01-30 16:41:59.000000000 +0100
+++ kjs.works/dtoa.h	2006-03-30 16:30:18.000000000 +0200
@@ -23,9 +23,14 @@
 #ifndef _KJS_DTOA_H_
 #define _KJS_DTOA_H_
 
+#ifdef KONQ_EMBEDDED
 extern "C" double kjs_strtod(const char *s00, char **se);
 extern "C" char *kjs_dtoa(double d, int mode, int ndigits,
 			  int *decpt, int *sign, char **rve);
 extern "C" void kjs_freedtoa(char *s);
+#else
+#include "stdlib.h"
+extern "C" double kjs_strtod(const char *s00, char **se) { strtod(s00,se); }
+#endif
 
 #endif /* _KJS_DTOA_H */
--- number_object.cpp	2006-01-30 16:41:59.000000000 +0100
+++ kjs.works/number_object.cpp	2006-03-30 16:48:27.000000000 +0200
@@ -90,6 +90,7 @@
   return true;
 }
 
+#ifdef KONQ_EMBEDDED
 static UString integer_part_noexp(double d)
 {
   int decimalPoint;
@@ -123,6 +124,7 @@
 
   return str;
 }
+#endif
 
 static UString char_sequence(char c, int count)
 {
@@ -233,6 +235,14 @@
     if (x >= 1e21)
       return String(s+UString::from(x));
 
+#ifndef KONQ_EMBEDDED
+    char buf[80];
+    char prec[10];
+    snprintf(prec,10, "%%.%ig",f);
+    snprintf(buf, 80, prec, x);
+
+    return String(UString(buf));
+#else
     double n = floor(x*pow(10.0,f));
     if (fabs(n/pow(10.0,f)-x) > fabs((n+1)/pow(10.0,f)-x))
       n++;
@@ -252,6 +262,7 @@
       return String(s+m.substr(0,k-f)+"."+m.substr(k-f));
     else
       return String(s+m.substr(0,k-f));
+#endif
   }
   case ToExponential: {
     double x = v.toNumber(exec);
@@ -270,6 +281,12 @@
       }
     }
 
+#ifndef KONQ_EMBEDDED
+    char buf[80];
+    char prec[10];
+    snprintf(prec,10, "%%.%ie",f);
+    snprintf(buf, 80, prec, x);
+#else
     int decimalAdjust = 0;
     if (!fractionDigits.isA(UndefinedType)) {
       double logx = floor(log10(x));
@@ -345,7 +362,7 @@
     assert(i <= 80);
 
     kjs_freedtoa(result);
-
+#endif
     return String(UString(buf));
   }
   case ToPrecision:
@@ -371,6 +388,12 @@
       return err;
     }
 
+#ifndef KONQ_EMBEDDED
+    char buf[80];
+    char prec[10];
+    snprintf(prec,10, "%%.%ig",p);
+    snprintf(buf, 80, prec, x);
+#else
     if (x != 0) {
       e = int(log10(x));
       double n = floor(x/pow(10.0,e-p+1));
@@ -411,6 +434,7 @@
     else {
       return String(s+"0."+char_sequence('0',-(e+1))+m);
     }
+#endif
   }
   }
 
--- ustring.cpp	2006-03-30 16:49:11.000000000 +0200
+++ kjs.works/ustring.cpp	2006-03-30 16:48:44.000000000 +0200
@@ -385,6 +383,7 @@
 
 UString UString::from(double d)
 {
+#ifndef KONQ_EMBEDDED
   char buf[80];
   int decimalPoint;
   int sign;
@@ -449,6 +448,31 @@
   kjs_freedtoa(result);
 
   return UString(buf);
+#else
+  kdDebug() << "UString::convert" << endl;
+
+  char buf[80];
+
+  if (d == -0)
+    strcpy(buf,"0");
+  else if (KJS::isNaN(d))
+    strcpy(buf,"NaN");
+  else if (KJS::isPosInf(d))
+    strcpy(buf,"Infinity");
+  else if (KJS::isNegInf(d))
+    strcpy(buf,"-Infinity");
+  else
+    sprintf(buf, "%.16g", d);   // does the right thing
+
+  // ECMA 3rd ed. 9.8.1 9 e: "with no leading zeros"
+  int buflen = strlen(buf);
+  if (buflen >= 4 && buf[buflen-4] == 'e' && buf[buflen-2] == '0') {
+    buf[buflen-2] = buf[buflen-1];
+    buf[buflen-1] = 0;
+  }
+
+  return UString(buf);
+#endif
 }
 
 UString &UString::append(const UString &t)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.