This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 12295 - Make `node instanceof otherWindow.Node` evaluate to false
Summary: Make `node instanceof otherWindow.Node` evaluate to false
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: WebIDL (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Cameron McCormack
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-13 21:02 UTC by Cameron McCormack
Modified: 2011-06-20 08:30 UTC (History)
6 users (show)

See Also:


Attachments

Description Cameron McCormack 2011-03-13 21:02:01 UTC
And exceptions, too.

Test: http://people.mozilla.org/~cmccormack/tests/instanceof-other-window.html

                    | (Node, DOMException, Object)
--------------------|-----------------------------
Firefox 4 RC        | (true, true, false)
WebKit r78794       | (false, false, false)
Opera 11.01         | (false, false, false)
IE 9 RC             | (false, false, false)
Chrome 10.0.648.133 | (false, false, false)
Comment 1 Aryeh Gregor 2011-04-27 17:24:42 UTC
It would be nice if this actually evaluated to true, from an author perspective, because otherwise "foo instanceof Node" and so on are quite confusing in the edge case where you've got an iframe or something.  But I guess it's easier to make it false from an interop perspective . . .
Comment 2 Mark S. Miller 2011-04-27 18:10:22 UTC
(In reply to comment #1)
> It would be nice if this actually evaluated to true, from an author
> perspective, because otherwise "foo instanceof Node" and so on are quite
> confusing in the edge case where you've got an iframe or something.  But I
> guess it's easier to make it false from an interop perspective . . .

In judging the author perspective, you need to consider consistency with the rest of JavaScript. While it might be nice if '{ } instanceof otherWindow.Object' or '[] instanceof otherWindow.Array' were true, that's not the way JavaScript works. 

Further, some of us seek to eventually make the Dom emulatable by Proxies. While a strawman Proxy extension http://wiki.ecmascript.org/doku.php?id=strawman:proxy_instanceof could emulate the behavior you have in mind, the currently accepted proxy proposal http://wiki.ecmascript.org/doku.php?id=harmony:proxies cannot. Nor can proxies as currently implemented in FF4 through 6.0a1. (Even if the strawman above does get approved, consistency still makes me favor that all these cross-frame instanceof cases be specified to return false.)
Comment 3 Allen Wirfs-Brock 2011-04-27 22:38:49 UTC
(In reply to comment #2)

expanding upon markm's comment.  instanceof is not a reliable way to perform "is-a" testing in JavaScript. Even in situations where there is only a single frame or global context.  If there is real a  need for such tests in the context of DOM/Web APIs then the WebIDL ECMAScript binding might want to consider defining some other way to perform them.
Comment 4 Cameron McCormack 2011-05-25 04:41:40 UTC
I've added wording to the spec requiring that each ECMAScript global environment gets its own copies of interface objects, interface prototype objects, etc.  So now `node instanceof otherWindow.Object` will be false.

http://dev.w3.org/2006/webapi/WebIDL/#es-environment

The "Host object [[HasInstance]]" section is still in the spec, which does currently require `node instanceof otherWindow.Node` to be true, but that will disappear once multiple inheritance has been removed (the default [[HasInstance]] will work fine then).

(Also added wording dotted around the spec to define which global environment each DOM object is associated with, and which global environment exceptions get associated with when they are created and thrown.)
Comment 5 Cameron McCormack 2011-05-25 04:57:56 UTC
(In reply to comment #4)
> (Also added wording dotted around the spec to define which global environment
> each DOM object is associated with, and which global environment exceptions get
> associated with when they are created and thrown.)

That's not strictly true.  I defined that each "host object implementing an interface" (term to be renamed when resolving bug 12320) has an associated global environment, but that it is up to specifications using Web IDL to define interfaces to state which global environment that is.  This association is what defines which [[Prototype]] is used for the object.

I would like to avoid requiring every Web IDL using specification from doing this, but I couldn't think of a way.

If we were still using the AbstractView interface, then in the spec that defined that I'd say:

  The Document object at AbstractView::document and all of the Nodes created as
  part of that Document (that is, that have ownerDocument set to that Document)
  are associated with the ECMAScript global object on which AbstractView is
  implemented.

Or something.

Still, it's unsatisfying making other specifications include some ECMAScript-specific text like this.
Comment 6 Cameron McCormack 2011-06-20 08:30:58 UTC
The custom [[HasInstance]] is gone now, so `node instanceOf otherWindow.Node` should now be required to be false.