Closed Bug 653458 Opened 14 years ago Closed 7 years ago

XML.AS3::toJSON wrongly presumes XML.prototype.toJSON is present

Categories

(Tamarin Graveyard :: Library, defect)

defect
Not set
minor

Tracking

(Not tracked)

RESOLVED WONTFIX
Future

People

(Reporter: pnkfelix, Unassigned)

References

Details

Attachments

(2 files)

XML.AS3::toJSON wrongly presumes XML.prototype.toJSON is present Bug 652200 settled on a reasonable work-around for the E4X toJSON problem: introduce a level of indirection in the form of a method in the AS3 namespace that delegates to the prototype's toJSON. (Note that the delegation happens at the time that AS3::toJSON() is invoked, *not* when the AS3::toJSON property is looked up in the class. The distinction is important below.) There are a few pathological cases that the implemented XML.AS3::toJSON() does not handle cleanly: namely, what if the user has replaced XML.prototype.toJSON with a non-callable value, or has deleted it entirely. Its hard to imagine when a user would correctly want to replace XML.prototype.toJSON with a non-callable value. But there is one scenario I have constructed where one might reasonably think that deleting the toJSON property from the prototype is sane: the case where the user wants invocations of replacer function to receive the original object as its value actual argument. (Deleting the toJSON property is *not* the only way to achieve this, but its not a ridiculous way one might think of to achieve the goal.) I made some Javascript to illustrate the technique on both Date and XML, since those are both cases where one might want to sidestep the prototype's toJSON. (The reason to look at Date as well as XML is that browsers besides Firefox provide support for Date.) I'll post the code and the results shortly.
RESULTS FROM BROWSERS: Safari 5.0.5: == DATE ILLUSTRATION == Date-A1."2011-04-28T16:31:15.377Z" Date-D1."2011-04-28T16:31:15.377Z" Date-I1."2011apr28" Date-A2."2011apr28" == (no support for E4X in this browser) == Chrome 11.0.696.57 == DATE ILLUSTRATION == Date-A1."2011-04-28T16:31:37.739Z" Date-D1."2011-04-28T16:31:37.739Z" Date-I1."2011apr28" Date-A2."2011apr28" == (no support for E4X in this browser) == Firefox 3.6.13 == DATE ILLUSTRATION == Date-A1."2011-04-28T16:32:06.957Z" Date-D1."2011apr28" Date-I1."2011apr28" Date-A2."2011apr28" == XML ILLUSTRATION == XML-A1 threw: TypeError: String.prototype.toJSON called on incompatible XML XML-D1. threw: TypeError: String.prototype.toJSON called on incompatible XML XML-I1. threw: TypeError: String.prototype.toJSON called on incompatible XML XML-A2. threw: TypeError: String.prototype.toJSON called on incompatible XML == DATE ILLUSTRATION == Date-A1."2011-04-28T16:32:42.199Z" Date-D1."2011apr28" Date-I1."2011apr28" Date-A2."2011apr28" == XML ILLUSTRATION == XML-A1 threw: TypeError: String.prototype.toJSON called on incompatible XML XML-D1. threw: TypeError: String.prototype.toJSON called on incompatible XML XML-I1. threw: TypeError: String.prototype.toJSON called on incompatible XML XML-A2. threw: TypeError: String.prototype.toJSON called on incompatible XML The important take-aways: * The case of Date-D1 is handled differently in Chrome+Safari versus Firefox. The case of Date-D1 is exactly the issue that this bug is discussing. (Firefox's handling for Date is what is specified in ECMA-262 5ed, I'm pretty sure.) * Firefox isn't handling E4X XML objects at all. That is not surprising given the investigation from Bug Bug 652200.
RESULTS FROM AVM: AVM shell 1.4 debug-debugger build 6236:bd426b64ca73 == DATE ILLUSTRATION == Date-A1."Thu Apr 28 12:36:19 GMT-0400 2011" Date-D1."2011apr28" Date-I1."2011apr28" Date-A2."2011apr28" == XML ILLUSTRATION == XML-A1"XML" XML-D1. threw: TypeError: Error #1006: value is not a function. XML-I1."World" XML-A2."World" The important take-aways: * For Date-D1, we match Firefox. That's expected since we are following ECMA-262 5ed. * For XML-D1, we are throwing an exception, because XML.AS3::toJSON() assumes XML.prototype.toJSON() is present, but in this case it has been deleted. The cases for XML-I1 and XML-A2 show that it is not hard at all to work-around this deficiency. But the principle of least surprise leads one to think that XML-D1 should be fixed to match how Date-D1 behaves.
See Also: → 652200
Flags: flashplayer-qrb+
Target Milestone: --- → Future
Tamarin is a dead project now. Mass WONTFIX.
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → WONTFIX
Tamarin isn't maintained anymore. WONTFIX remaining bugs.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: