I was iterating over properties of document
when I ran into an interesting phenomena in Firefox, document
claims to support the property domConfig
although MDC says it isn't implemented but when I try to retrieve the property I get an exception:
Error: uncaught exception: [Exception... "Component returned failure code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED) [nsIDOM3Document.domConfig]" nsresult: "0x80004001 (NS_ERROR_NOT_IMPLEMENTED)" location: "JS frame :: javascript:alert(typeof(document.domConfig)) :: :: line 1" data: no]
The following shows the behaviour, both Chrome and IE are consistent (I haven't checked Opera) in saying that domConfig
is not a property of window but Firefox claims it is but can't retrieve it (copy paste into URL field since I can't get markdown to give a link).
/* true in FF, false in other browsers */
javascript:alert("domConfig" in document)
/* exception in FF, 'undefined' in other browsers */
javascript:alert(typeof(document.domConfig))
What's going on here?
Pointy's right, domConfig
is exposed in an interface (DOM Level 3 Core Document - in Mozilla's source it's called nsIDOM3Document), but is not implemented (see nsDocument::GetDomConfig()
). typeof
works by first getting the value, then determining its type (and not from the interface definition), so it's not surprising typeof document.domConfig
throws an exception.
As for why it's been done this way, the bug this code was added in doesn't have any discussion about that, so we can only guess.
My guess is that for specifications Mozilla intended to implement it made sense to finalize ("freeze" in Mozilla's terms) the interfaces, so that they could be used from binary code without further modifications after new properties/methods of the interface got implemented. And it didn't seem to matter much one way or another.
If you're interested in hearing from the developers, you could ask in mozilla.dev.tech.dom or mozilla.dev.platform.
User contributions licensed under CC BY-SA 3.0