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:30:16 -0400
Message-ID: <4FE32FF8.7040108@mit.edu>
To: David Bruant <bruant.d@gmail.com>
CC: public-script-coord@w3.org
On 6/21/12 4:15 AM, David Bruant wrote:
> Le 21/06/2012 07:30, Boris Zbarsky a écrit :
>> Alternately, we could try to make instanceof actually work cross-global?
> +1, but eternal web worry: won't it break the web?

It works cross-global for DOM objects in Gecko right now.  We're 
actually deliberately breaking that in the WebIDL bindings at the 
moment, so the actual web compat breakage for us is in the other 
direction: as we move to WebIDL with its stricter instanceof sites might 
break.

> Would it apply to non-DOM objects?

That's much harder, without spec-level changes....  Obviously we could 
make it work on arrays, but then people will want it for their Points or 
whatever too, right?

> I assume that by making instanceof work globally you mean breaking its
> definition based on prototype object identity?

Yes.  In Spidermonkey there is a hook that can be attached to a given 
[[Class]] that will get called if the object is the RHS of instanceof 
and can do whatever it wants.  In the case of current DOM objects it 
just checks whether the object implements the given interface, for example.

-Boris
Received on Thursday, 21 June 2012 14:30:52 UTC

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