Last Comment Bug 328745 - toSource: unnecessary sharp variables
: toSource: unnecessary sharp variables
Status: RESOLVED FIXED
:
Product: Core
Classification: Components
Component: JavaScript Engine (show other bugs)
: Trunk
: All All
: -- minor with 1 vote (vote)
: ---
Assigned To: general
:
Mentors:
Depends on:
Blocks: 368267
  Show dependency treegraph
 
Reported: 2006-02-27 09:26 PST by Igor Bukanov
Modified: 2012-02-17 16:13 PST (History)
6 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments

Description Igor Bukanov 2006-02-27 09:26:33 PST
Consider the following code for js shell:

var x = []; x.foo = x;

var y = {}; y.f = function() { } y.f.bar = y.f;

print(uneval(x));
print(uneval(y));

Currently it prints:

#1=[]
({f:#1=(function () {})})

where #1 is a leftover from the fact that toSource for Object and Array consider that all enumeratable properties from the object graph would be serialized. See MarkSharpObjects from jsobj.c But this is not the case when toSource does not include all the properties as above example demonstrates.

It would be nice if unnecessary sharp variables would be avoided.
Comment 1 jfk k 2007-05-20 15:34:28 PDT
This strange behaviour has the same basis as in http://groups.google.com/group/mozilla.dev.tech.js-engine/browse_thread/thread/9146f158f3a8497f

The question is: why uneval/toSource ignore variables 'foo' and 'bar' that appear in Array and Function in above example? It is because there is no initializer that allows setting properties for Array and Function. Right now, since there is no special syntax for setting properties for Arrays or Functions, instead of using bare initializer a function constructing and returning object could be returned:

var x = []; x.foo = x;
print(uneval(x));

prints:

(function(){var a=[];a.foo=a;return a;})()

Of course this method has its drawbacks - additional function is created only to initialize object.

So, I think it would be even nicer if uneval/toString stop ignoring properties for Arrays and Functions, and start using those pretty necessary sharp variables :)
Comment 2 Gary Kwong [:gkw] [:nth10sd] 2012-02-17 16:13:39 PST
Fixed by bug 566700, the removal of sharp variables. The testcase in comment 0 no longer prints sharps.

Note You need to log in before you can comment on or make changes to this bug.