Open Bug 1213792 Opened 4 years ago Updated 7 months ago

Interface objects have an own "toString" property.

Categories

(Core :: DOM: Core & HTML, defect)

40 Branch
defect
Not set

Tracking

()

UNCONFIRMED

People

(Reporter: crimsteam, Unassigned)

References

Details

(Keywords: dev-doc-needed)

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0
Build ID: 20150929144111

Steps to reproduce:

Per actual DOM spec toString() method is defined through IDL:
https://dom.spec.whatwg.org/#dom-ranges-changes
http://heycam.github.io/webidl/#es-stringifier
where we see:
"If the stringifier is unforgeable on the interface or if the interface was declared with the [Global] or [PrimaryGlobal] extended attribute, then the property exists on every object that implements the interface. Otherwise, the property exists on the interface prototype object."

Small test:
<script>

		alert(document.createRange().hasOwnProperty("toString"));
		alert(Range.hasOwnProperty("toString"));
		alert(Range.prototype.hasOwnProperty("toString"));

</script>
And results:
Firefox and Chrome: false, true, true (wrong)
IE, Opera (Presto): false, false, true (correct)
This is not specific to Range; updated the summary to match.
Summary: Expose Range.toString() only on interface prototype object → Interface objects have an own "toString" property.
Interface objects have a toString because Function.prototype.toString throws for interface objects, so we have to shadow it for stringification of interface objects to work at all.

One Function.prototype.toString is fixed to not suck, we can remove this toString bit.

I guess I'll mark this dependent on bug 1039986, just in case the patches there don't remove the toString hackery on interface objects.
Depends on: 1039986
Looks like after closing https://bugzilla.mozilla.org/show_bug.cgi?id=1039986 this bug is no longer valid, I check stringifier for Range and DOMTokenList and all worsk fine. Maybe can be close?
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.