Hi, Sorry, arriving a bit late to the party. I was about to propose something related to @@toStringTag, but reading the discussions about how it may/will work [1][2][3], i realize it may not be your preferred solution.
Maybe @@toStringTag will end up not working well enough for your need anyway. But another solution could be to define a chromeonly symbol for the brand. obj[Symbol.brand] === 'HTMLEmbedElement' (`Symbol.brand` is chromeonly. `obj[Symbol.brand]` too) No function call, no string to allocate, nothing to import (`Symbol` is a standard ECMAScript global). It might look weird because symbols are new, but maybe it's just something to get used to, hard to tell. David [1] https://github.com/heycam/webidl/issues/54 [2] https://github.com/heycam/webidl/pull/357 [3] https://github.com/heycam/webidl/issues/419 Le vendredi 1 septembre 2017 17:01:58 UTC+2, Boris Zbarsky a écrit : > Now that we control all the code that can attempt to touch > Components.interfaces.nsIDOM*, we can try to get rid of these interfaces > and their corresponding bloat. > > The main issue is that we have consumers that use these for testing what > sort of object we have, like so: > > if (obj instanceof Ci.nsIDOMWhatever) > > and we'd need to find ways to make that work. In some cases various > hacky workarounds are possible in terms of property names the object has > and maybe their values, but they can end up pretty non-intuitive and > fragile. For example, this: > > element instanceof Components.interfaces.nsIDOMHTMLEmbedElement > > becomes: > > element.localName === "embed" && > element.namespaceURI === "http://www.w3.org/1999/xhtml" > > and even that is only OK at the callsite in question because we know it > came from > http://searchfox.org/mozilla-central/rev/51b3d67a5ec1758bd2fe7d7b6e75ad6b6b5da223/dom/interfaces/xul/nsIDOMXULCommandDispatcher.idl#17 > > and hence we know it really is an Element... > > Anyway, we need a replacement. Some possible options: > > 1) Use "obj instanceof Whatever". The problem is that we'd like to > maybe kill off the cross-global instanceof behavior we have now for DOM > constructors. > > 2) Introduce chromeonly "is" methods on all DOM constructors. So > "HTMLEmbedElement.is(obj)". Possibly with some nicer but uniform name. > > 3) Introduce chromeonly "isWhatever" methods (akin to Array.isArray) on > DOM constructors. So "HTMLEmbedElement.isHTMLEmbedElement(obj)". Kinda > wordy and repetitive... > > 4) Something else? > > Thoughts? It really would be nice to get rid of some of this stuff > going forward. And since the web platform seems to be punting on > branding, there's no existing solution we can use. > > -Boris _______________________________________________ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform