W3C home > Mailing lists > Public > public-script-coord@w3.org > April to June 2012

Re: Detecting the "type" of a DOM object

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Thu, 21 Jun 2012 10:58:46 -0400
Message-ID: <4FE336A6.5070206@mit.edu>
To: David Bruant <bruant.d@gmail.com>
CC: public-script-coord@w3.org
On 6/21/12 10:49 AM, David Bruant wrote:
> Really? After check, yes indeed. That's excellent. I thought it wasn't
> the case. I think what you said in your original message is what misled
> me into thinking that:
> "There's a common problem where someone has an object and they would
> like to tell whether it's a Node (or an Array or a Date or whatever).
> Right now, the way to do that is to use instanceof.... but with a huge
> caveat: you have to pull the Node or Array or whatnot off the right
> global object."
> Apparently, this sentence was inaccurate for Node objects.

I was talking about the state of things per the current ES and WebIDL 
specs.  Implementation reality is a different issue; technically what 
Gecko is doing right now is not WebIDL-compliant, and that's because the 
implementation obviously predates WebIDL.

And as I said, we're moving away from it because it makes it harder to 
support other things WebIDL requires.  For example, right now in 
Spidermonkey I can't make "n instanceof Node" work cross-global while 
still having Function.prototype.toString.call(Node) return what WebIDL 
requires it to return.  The new WebIDL bindings are making the latter 
work at the expense of the former.

> So in Firefox, instanceof can be used with browser API (DOM +
> localStorage + XHR + whatev's is built-in to the browser)

Stop right there.  ;)  XHR has been switched to WebIDL bindings already 
(to ship in Firefox 14 in a few weeks), so you _can't_ use instanceof 
there anymore.  Other things will be following.  Hence this thread....

> So it seems that the way Firefox model objects it's possible to detect
> the type of any object, WebIDL or ECMAScript-based across globals, no?

See above.

> Of course. Then +1000 for changing how instanceof is defined in WebIDL
> to adopt Gecko behavior!

The point is WebIDL can't do that on its own: there is nothing in ES5 
for it to hook into, as far as I know.  This needs coordination between 
WebIDL and the ES spec.

> Interesting. I don't know whether this can be implemented with proxies

I don't believe it can.

I also don't believe that a proxy Node can be used to satisfy the "Node 
must be a Function" requirements of WebIDL.

-Boris
Received on Thursday, 21 June 2012 14:59:18 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 May 2013 19:30:06 UTC