Subj : Re: Error in decompiling To : netscape.public.mozilla.jseng From : Martin Honnen Date : Sun Jan 18 2004 07:29 pm Adrian Klein wrote: > Assume a function defined as: > > function do_something() { > var obj = new Object(); > > obj['name'] = 'Just a name'; > obj['if'] = false; > obj['some text'] = 'correct'; > } > > do_something.toString(), do_something.String() or uneval(do_something) > will be resolved to something like this (with varying formating): > > function do_something() { > var obj = new Object(); > > obj.name = 'Just a name'; > obj.if = false; > obj['some text'] = 'correct'; > } > > I think this seems like a bug in the decompiling part of the > Spidermonkey Engine, because it does not check if the name of a object > property is a reserved keyword, so that it should not be refered to with > the 'object.property' syntax. ECMAScript edition 3 says about the toString method of function objects: 15.3.4.2 Function.prototype.toString ( ) An implementation-dependent representation of the function is returned. This representation has the syntax of a FunctionDeclaration. so one can indeed call the above a bug as the result of toString() doesn't yield a representation fitting the production for FunctionDeclaration. When I try Rhino with a similar example it gets it right: Rhino 1.5 release 4.1 2003 04 21 js> function f () { var obj = new Object(); obj['if'] = false; } js> f.toString() function f() { var obj = new Object(); obj["if"] = false; } However if I use an object literal then Rhino gets that wrong Rhino 1.5 release 4.1 2003 04 21 js> function f () { var obj = {'if': false}; } js> f.toString() function f() { var obj = {if:false}; } You could file a bug on bugzilla (or wait what Brendan thinks about it). -- Martin Honnen http://JavaScript.FAQTs.com/ .