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 25495 - Behavior of no [Exposed] on interface members is weird
Summary: Behavior of no [Exposed] on interface members is weird
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: 2014-04-29 04:01 UTC by Boris Zbarsky
Modified: 2017-10-11 21:18 UTC (History)
7 users (show)

See Also:


Attachments

Description Boris Zbarsky 2014-04-29 04:01:46 UTC
The behavior of interface members with no explicit annotation is:

  the interface member – or a partial interface definition the interface member
  was declared on – was not declared with an [Exposed] extended attribute, and
  the ECMAScript global object implements the primary global interface.

That means that if some interface is exposed in workers, all its members _also_ need to be annotated with [Exposed=Workers] (or be in a partial interface thus annotated).  It would make more sense to me to make exposure be true by default for interface members, so you only need to annotate the ones that shouldn't be exposed somewhere, no?
Comment 1 Ehsan Akhgari [:ehsan] 2014-05-30 03:34:50 UTC
I agree with Boris here, I think the current prose results in a weird behavior.
Comment 2 Boris Zbarsky 2014-05-30 04:32:32 UTC
Also, note that we disallow [Exposed] on both a partial interface and one of its members, but do allow it on both an interface and one of its members.

That seems fine to me, for what it's worth; it means we can expose an interface on both Window and Worker but restrict some of the members to one or the other, while for partial interfaces that sort of thing is not needed because we can just use separate partials for different [Exposed] values.
Comment 3 Boris Zbarsky 2014-05-30 04:44:37 UTC
https://github.com/heycam/webidl/pull/12
Comment 4 Boris Zbarsky 2014-07-25 20:05:14 UTC
Also, it probably makes no sense to support this:

  [Exposed=Worker]
  interface Foo {
    [Exposed=Window]
    void method();
  };

in that the [Exposed] on interface members should be a subset of the [Exposed] of the interface itself, I believe.  Similarly for:

  [Exposed=Worker]
  interface Foo {};

  [Exposed=Window]
  partial interface Foo {
    void method();
  };
Comment 5 Boris Zbarsky 2014-07-28 18:25:38 UTC
Also, how should this stuff interact with "implements"?  See NavigatorOnLine.
Comment 6 Ian 'Hixie' Hickson 2014-07-28 20:27:19 UTC
My preference for this would be that [Exposed] on an interface applies to the interface, that everything on an interface that isn't annotated with its own [Exposed] is always visible on that interface, and that the UA additionally adds any "implements" and "partial" interfaces that are themselves Exposed appropriately.

So:

  [Exposed=A,B]
  interface Foo {
    void f1();
  };
  Foo implements Bar;

  [Exposed=A]
  partial interface Foo {
    void F2();
  };

  [Exposed=B]
  partial interface Foo {
    void F3();
  };

  [Exposed=A]
  interface Bar {
    void f4();
  };

...would result in an interface Foo in contexts A and B but not C, and in A it would have f1, f2, and f4, while in B it would have f2 and f3.
Comment 7 Boris Zbarsky 2014-07-29 02:48:21 UTC
The simplest way to describe that is probably as follows:

1)  Every interface member has a set of globals where it's exposed.  If it has an [Exposed] extended attribute this is the set specified in that extended attribute.  Otherwise, if the interface or partial interface it was originally defined on has an [Exposed] extended attribute it is the set specified in that extended attribute.  Otherwise, this set is { "Window" } (though I think ms2ger would prefer to nix this defaulting behavior and just make it an error to not have [Exposed] on an interface).

2)  Every interface that is not [NoInterfaceObject] has a set of globals where it its interface object is a property of the global.  This is given by the [Exposed] extended attribute on the interface, or { "Window" } if there is no such extended attribute.

3)  Optionally, make it an error to have a member of an interface, or one of its consequential interfaces, that is exposed in a global the interface itself is not exposed in.
Comment 8 Cameron McCormack 2014-07-29 07:22:40 UTC
That all sounds good.  How does this look?

https://github.com/heycam/webidl/commit/71a44ff9e1dcb1f467656f71b78f77abbf9427bf
http://heycam.github.io/webidl/#Exposed

The name "exposure set" sounds a bit silly but oh well.
Comment 9 Boris Zbarsky 2014-07-29 15:50:04 UTC
"exposure set" seems fine.

The new setup looks great with two caveats:

1)  This bit:

  If [Exposed] appears on both an interface and one of its interface
  members, then the interface member's exposure set MUST be a subset of
  the interface's exposure set.

should not require [Exposed] to appear on the interface itself.  In other words, this:

  interface Foo {
    [Exposed=Worker] void method();
  };

should be invalid.

2)  Would it makes sense to require that if A inherits from B then the exposure set of A is a subset of the one for B?  This is not covered by the consequential interfaces bit, since B is not a consequential interface of A.
Comment 10 Tobie Langel 2017-10-11 21:18:03 UTC
This should be fixed in https://github.com/heycam/webidl/pull/433/commits/8900c39