toSource: unnecessary sharp variables

RESOLVED FIXED

Status

()

Core
JavaScript Engine
--
minor
RESOLVED FIXED
11 years ago
5 years ago

People

(Reporter: Igor Bukanov, Unassigned)

Tracking

Trunk
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

11 years ago
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.

Updated

10 years ago
Blocks: 368267

Comment 1

10 years ago
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
Last Resolved: 5 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.