Closed Bug 328745 Opened 18 years ago Closed 12 years ago

toSource: unnecessary sharp variables

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
minor

Tracking

()

RESOLVED FIXED

People

(Reporter: igor, Unassigned)

References

Details

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.
Blocks: 368267
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 :)
Fixed by bug 566700, the removal of sharp variables. The testcase in comment 0 no longer prints sharps.
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.