Closed
Bug 633278
Opened 14 years ago
Closed 14 years ago
Sharp references should only be allowed to appear directly as array and object values
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: jimb, Unassigned)
Details
Sharp references allow us to accurately print and read back structures with cycles and sharing, which is essential:
js> var a=[1]; var b=[a,a]; b
[#1=[1], #1#]
However, the current implementation allows sharp references to appear within expressions, not just directly in array and object literals. This is not necessary for them to do their essential job, and allows all sorts of ridiculous stuff like |#1={1:(#1#[1] = 2, #1#)}| (bug 633177), where objects escape into the world mid-initialization.
It is a waste of time to make sure cases like this work:
js> function p(a) { Object.defineProperty(a,0,{writable:false}); return 42; }
js> #1=[p(#1#)]
because 1) it's never needed to print and read back arbitrary object graphs, and 2) for reading, sharp variables are just shorthand for a literal with holes followed by some side effects.
The grammar should be changed so that sharp references are only recognized when they appear immediately as a value in an array literal [#1#] or object literal { x:#1# }, and are treated as errors when they occur in some deeper expression context.
Comment 1•14 years ago
|
||
I think this bug is invalid - the sharps at arbitrary positions are necessary to support custom serializes. Here is an example based on the bug 566700 comment 39:
function MyClass(arg) {
this.arg = arg;
}
MyClass.prototype.toSource = function() {
var arg_source = uneval(this.arg);
return '(new MyClass('+arg_source+'))';
}
var arg = [1,2,3];
var a = new MyClass(arg);
var b = new MyClass(arg);
print(uneval([a, b]));
print(uneval(eval(uneval([a, b]))));
Currently it prints:
[(new MyClass(#1=[1, 2, 3])), (new MyClass(#1#))]
[(new MyClass(#1=[1, 2, 3])), (new MyClass(#1#))]
where sharp as a non-initializer is essential to make this work.
Reporter | ||
Comment 2•14 years ago
|
||
(In reply to comment #1)
> I think this bug is invalid - the sharps at arbitrary positions are necessary
> to support custom serializers.
I hadn't thought about that. Since uneval calls objects' toSource methods, it's really impossible to round-trip graphs --- even if one requires well-behaved toSource functions --- under the restrictions I suggested.
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•