On 12/27/12 2:49 PM, Justin Dolske wrote:
Hmm. My first reaction is to gently challenge if this really has to
change
Well, it really has to change as exposed to web content (or we have to
convince every single other browser to change behavior and get the
ECMAScript spec changed and so forth).
What happens with chrome is an interesting question we can discuss;
that's what this thread is about.
If really desired, we _could_ make our chrome interface objects behave
differently from content ones and do weird instanceof magic. That would
mean that some edge cases like
Function.prototype.toString.call(HTMLAnchorElement) would do the wrong
thing in chrome (specifically, throw instead of not throwing) and that
you'd have to be very careful about what sort of window you were working
with, but it's pretty doable.
Alternately, we could do something where the proto chain of an Xray for
a content object passes through the corresponding chrome prototypes, not
through Xrays for the content window's prototypes. That would
presumably make "el instanceof
el.ownerDocument.defaultView.HTMLAnchorElement" return false and might
have other issues.
After all, if it's changing a frequently used chrome/addon pattern,
that's a pretty big incompatibility step. And I'd sort of expect an
HTMLAnchorElement to always be an HTMLAnchorElement, without the
creator's context mattering... [1]
Unfortunately, that's not how instanceof works in JS. Try it with
Object instead of HTMLAnchorElement...
One fairly easy (and mechanical?) option would be to add a global helper
function. Something roughly along the lines of:
var isIt = checkForDOMInterface(el, "HTMLAnchorElement");
Right. This would work for elements and for our chrome code. It
doesn't help with the problem on the web, but maybe I should just give
up on solving that as part of the work here. :(
A bigger shift might be to change to using existing properties
(.nodeName? .nodeType?) or add something new?
localName and namespaceURI are the relevant things. And they're a bit
of a pain to use, especially namespaceURI. And it's not quite clear to
me how they'll end up interacting with web components.
// Hello, I am chrome code adding an anchor to content
var noob = document.createElement("a");
gBrowser.contentDocument.body.appendChild(noob);
// ...later, for an arbitrary node, possibly el === noob
var isAnchor = el instanceof HTMLAnchorElement;
Right now on m-c this sets "isAnchor" to true.
If HTMLAnchorElement is switched to follow the spec, it will set
isAnchor to false, because the implicit adoptNode during the appendChild
changes the prototype chain in Gecko.
-Boris
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform