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 22858 - use @@hasInstance instead of [[HasInstance]]
Summary: use @@hasInstance instead of [[HasInstance]]
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
Depends on:
Reported: 2013-08-02 05:43 UTC by Cameron McCormack
Modified: 2016-09-08 20:54 UTC (History)
7 users (show)

See Also:


Description Cameron McCormack 2013-08-02 05:43:39 UTC
In ES6, there is a @@hasInstance symbol that is used to define "instanceof" behaviour.  We should use that rather than defining [[HasInstance]], since it has gone from the spec.
Comment 1 Anne 2015-01-29 17:58:32 UTC
What bug resulted in us adding an [[HasInstance]] override?

I think having this is a bad idea and is future hostile. It makes it harder to move objects from the web platform into JavaScript as they will end up having subtly different behavior. (Or JavaScript's default library will end up being subtly inconsistent.)

If we want better identity checks we should just introduce a method that can do it and not mess with default class semantics.
Comment 2 Boris Zbarsky 2015-01-29 18:06:37 UTC
Note that there was a bunch of discussion about this on the mailing list.  The idea of an isArray method or the like, whether per-interface or more generic, was strongly opposed by various people, including some TC39 folks...
Comment 3 Domenic Denicola 2015-01-29 18:11:12 UTC
While I agree that the override of [[HasInstance]] seems pretty pointless, I don't understand why it would be future-hostile. JS versions of the classes could just override their @@hasInstance, e.g.

class WebIDLThingy {
  static [Symbol.hasInstance](x) {
    return performBrandCheck(x);
Comment 4 Anne 2015-01-29 18:15:59 UTC
That did not happen for e.g. ArrayBuffer. Another example would be promises, which in Gecko are implemented in terms of IDL and therefore have this "feature".

bz, did we consider something like

  Window.ignoreGlobalInstanceOf(..., ...)

as that seems hardly different from what this magic @@hasInstance override is?
Comment 5 Boris Zbarsky 2015-01-29 19:26:08 UTC
>  Window.ignoreGlobalInstanceOf(..., ...)

Not with that name, but I think we did... I'd have to check the archives.

Anyway, I'm maybe ok with people wanting to reopen this discussion if we can finally pick something, get UAs to converge on it, and stick to it.  Though I will say that a fair amount of Firefox extension code has been written with the current Web IDL definition in mind, because _last_ time we had this conversation people were told we had finally decided something.
Comment 6 Domenic Denicola 2016-09-08 20:54:03 UTC