Subj : Re: Proper behavior of uneval(-0.0) ? To : Igor Bukanov From : Brendan Eich Date : Wed Nov 12 2003 02:22 pm This is a multi-part message in MIME format. --------------070003010801060606080603 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Igor Bukanov wrote: > while uneval(f) produces > > function f(i) {while (i < 10) {++i;}return 1;} f.toSource() produces that, of course. Try f.toSource(0) for fun. In order to keep eval'able strings short, avoid problems with newlines embedded in strings passing through other layers of code, and keep lambdas concise when pretty-printed, I made a small (in implementation code size) difference from toString to toSource. As I wrote, I'm not averse to a similarly small special case difference for -0, but it didn't seem important from a pretty-printing or newline-avoidance point of view, and I didn't have any use-cases motivating it. Now that you mention it, though, I'm all for it. See the attached patch, let me know what you think. /be --------------070003010801060606080603 Content-Type: text/plain; name="sd" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="sd" Index: jsstr.c =================================================================== RCS file: /cvsroot/mozilla/js/src/jsstr.c,v retrieving revision 3.82 diff -p -u -8 -r3.82 jsstr.c --- jsstr.c 11 Nov 2003 17:59:54 -0000 3.82 +++ jsstr.c 12 Nov 2003 22:20:53 -0000 @@ -2666,16 +2666,20 @@ js_ValueToSource(JSContext *cx, jsval v) if (JSVAL_IS_STRING(v)) return js_QuoteString(cx, JSVAL_TO_STRING(v), '"'); if (!JSVAL_IS_PRIMITIVE(v)) { if (!js_TryMethod(cx, JSVAL_TO_OBJECT(v), cx->runtime->atomState.toSourceAtom, 0, NULL, &v)) { return NULL; } + } else if (JSVAL_IS_DOUBLE(v) && JSDOUBLE_IS_NEGZERO(*JSVAL_TO_DOUBLE(v))) { + static const jschar js_negzero_ucstr[] = {'-', '0'}; + + return js_NewStringCopyN(cx, js_negzero_ucstr, 2, 0); } return js_ValueToString(cx, v); } JSHashNumber js_HashString(JSString *str) { JSHashNumber h; --------------070003010801060606080603-- .