Last Comment Bug 328745 - toSource: unnecessary sharp variables
: toSource: unnecessary sharp variables
Product: Core
Classification: Components
Component: JavaScript Engine (show other bugs)
: Trunk
: All All
-- minor with 1 vote (vote)
: ---
Assigned To: general
: Jason Orendorff [:jorendorff]
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:
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


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

var x = []; = x;

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


Currently it prints:

({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 User image jfk k 2007-05-20 15:34:28 PDT
This strange behaviour has the same basis as in

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;


(function(){var 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 User image 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.