- From: Allen Wirfs-Brock <allen@wirfs-brock.com>
- Date: Thu, 21 Jun 2012 11:56:00 -0700
- To: David Bruant <bruant.d@gmail.com>
- Cc: Brendan Eich <brendan@mozilla.org>, Boris Zbarsky <bzbarsky@MIT.EDU>, public-script-coord@w3.org
On Jun 21, 2012, at 8:41 AM, David Bruant wrote: > Le 21/06/2012 17:05, Brendan Eich a écrit : >> Boris Zbarsky wrote: >>>> 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.... >> >> Seems better to discuss and possibly revise WebIDL (and ES6, but see below -- it may be ready!) first, then change Gecko, but sounds like time is short to undo the change. >> >>>> 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. >> >> See [[NativeBrand]] in ES6 drafts including latest at >> >> http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts > I don't think a naive use of [[NativeBrand]] will be enough. First, [[NativeBrand]] is unused in instanceof. Then, a document will certainly have a [[NativeBrand]] of 'HTMLDocument' and returning 'true' for "document instanceof Node" is a bit far off. Just to clarify, in the ES6 spec. [[NativeBrand]] is not an ECMAScript host object extension point. The only valid [[NativeBrand]] values are those explicitly defined in the ES6 specification. If you start talking about other [[NativeBrand]] values you are now outside the world for the standard specification. There is no reason you can expect standard ECMAScript semantics that use [[NativeBrand]], such as those for Object.prototype.toString, to behave correctly in the presences of non-standard [[NativeBrand]] values because as far as the specification is concern there are none.. Of course, an implementation can do what ever non-standard things it feels it can get away with. You might cast your discussion in terms of new [[NativeBrand]] values, but in reality you are making up new ECMAScript semantics that simply are not part of the standard specification unless/until they are adopted as part of the ES standard. > > But certainly that by making instanceof use [[NativeBrand]] and allowing WebIDL to hook something to make the connection between different [[NativeBrand]]s could do the trick. > I'll try to think about it and come up with an actual proposal. For ES<=5.1 [[HasInstance]] is the appropriate host object extension point. For ES>=6 we don't know for sure yet. We really would like to eliminate the whole concept of host objects and replace them with a more controlled set of extensions points including the use of Proxy. Allen
Received on Thursday, 21 June 2012 18:56:34 UTC