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 22646 - So if we want to say on a per-object basis whether it ought to be exposed to workers (which I think is useful) lets introduce "exposed to document environments", "exposed to worker environments", and [...]
Summary: So if we want to say on a per-object basis whether it ought to be exposed to ...
Status: RESOLVED WORKSFORME
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: WebIDL (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: ---
Assignee: Cameron McCormack
QA Contact: public-webapps-bugzilla
URL:
Whiteboard: [v1]
Keywords:
Depends on:
Blocks: 22705 23780 24218
  Show dependency treegraph
 
Reported: 2013-07-11 20:33 UTC by contributor
Modified: 2017-12-06 11:29 UTC (History)
8 users (show)

See Also:


Attachments

Description contributor 2013-07-11 20:33:48 UTC
Specification: http://www.whatwg.org/specs/web-apps/current-work/
Multipage: http://www.whatwg.org/C#exposed-to-javascript
Complete: http://www.whatwg.org/c#exposed-to-javascript
Referrer: 

Comment:
So if we want to say on a per-object basis whether it ought to be exposed to
workers (which I think is useful) lets introduce "exposed to document
environments", "exposed to worker environments", and "exposed to document and
worker environments" as shorthands.

Posted from: 66.207.208.98
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.3 Safari/537.36
Comment 1 Marcos Caceres 2013-07-11 20:37:36 UTC
sounds useful.
Comment 2 Ian 'Hixie' Hickson 2013-07-11 21:29:17 UTC
we could just have [Exposed=Worker], [Exposed=Window] (default), [Exposed=Window,Worker]
Comment 3 Ian 'Hixie' Hickson 2013-07-23 22:54:52 UTC
Reassigning to heycam for consideration in WebIDL. Please reassign to me once either there is WebIDL syntax for this or it's been decided to only do this in prose, not WebIDL. Thanks!
Comment 4 Anne 2013-07-23 23:06:32 UTC
Comment 2 can be tied with the new [Global] extended attribute I think.
Comment 5 Anne 2013-11-21 12:48:51 UTC
This should also support having a class exposed on both and then have a partial class supported on just one.
Comment 6 Cameron McCormack 2014-01-23 03:35:49 UTC
Just looking at this again now.  Would [Exposed] only control whether an interface object is visible or not?
Comment 7 Anne 2014-01-23 15:43:16 UTC
What I have been wanting to do is things like this:

[Exposed=Window,Worker] interface XMLHttpRequest { ... }

[Exposed=Window] partial interface XMLHttpRequest { ... responseXML ... }

So it would be more than that if I had my way.
Comment 8 Travis Leithead [MSFT] 2014-01-23 19:29:03 UTC
Do we need more fine-grained management? For example, the Web Perf WG asked about including only _some_ APIs on their window.performance object, but not others (e.g., performance.now() everywhere, but not necessarily the statistics objects...)
Comment 9 Cameron McCormack 2014-01-23 21:01:20 UTC
It should be fine to allow [Exposed] on partial interfaces, as well as on individual interface members if that's needed.  But in terms of actual concrete effects, is hiding/exposing the interface object property on the global the only thing that needs to be done?
Comment 10 Anne 2014-01-23 21:18:53 UTC
Yeah I think so. That's all that interface XMLHttpRequest {} does after all. This is just a way to scope that to particular globals.
Comment 11 Cameron McCormack 2014-01-24 07:05:18 UTC
https://github.com/heycam/webidl/commit/b38006ce3682fc07c1be52a49130bea5e42e7c78

Summary:
  * Window should change its [Global] to [PrimaryGlobal]
  * the [Global] on SharedWorkerGlobalScope and DedicatedWorkerGlobalScope
    should become [Global=Worker]
  * you can use [Exposed=Worker] or [Exposed=Window,Worker] as appropriate
    on interfaces, interface members, partial interfaces, and dictionaries
    that have constructors.
Comment 12 Anne 2014-01-24 18:05:54 UTC
Cameron, can we tag [Global=Worker,DedicatedWorker]? It seems we need granularity like that for certain features. Especially with the new ServiceWorkerGlobalScope.
Comment 14 Ian 'Hixie' Hickson 2014-01-27 19:45:18 UTC
heycam: Why do you have this restriction?:

# If [Exposed] appears on an overloaded operation, then it must appear on all 
# overloads, with the same identifier list.

Consider e.g. APIs that in workers take a string or an integer, but in Windows take a string, an integer, or a DOM node.
Comment 15 Cameron McCormack 2014-01-27 21:19:38 UTC
It would have been a bigger change to allow the set of operations that are involved in overloading to be different, so I decided to disallow it until we're sure we need it.  Do we need it? :)
Comment 16 contributor 2014-01-27 23:09:08 UTC
Checked in as WHATWG revision r8425.
Check-in comment: Update the spec to say what's exposed to workers: take 1
http://html5.org/tools/web-apps-tracker?from=8424&to=8425
Comment 17 Ian 'Hixie' Hickson 2014-01-27 23:14:48 UTC
Ok, I welcome review of the above. I'm especially interested in how I used it here, where there's an attribute with a different definition for workers than it has for Window:

   http://whatwg.org/html/#the-messageevent-interfaces
Comment 18 Cameron McCormack 2014-01-28 00:44:05 UTC
(In reply to Ian 'Hixie' Hickson from comment #17)
> Ok, I welcome review of the above. I'm especially interested in how I used
> it here, where there's an attribute with a different definition for workers
> than it has for Window:
> 
>    http://whatwg.org/html/#the-messageevent-interfaces

Ah so that is a problem, I guess.  Currently I disallow any duplicate attribute names on an interface, not looking at [Exposed].  Given that the dictionary still has the union, and that as with XHR.send() still having Document in the types is OK, do you need to split the attribute in two here?
Comment 19 Ian 'Hixie' Hickson 2014-01-28 20:34:22 UTC
I guess not? But shouldn't it be non-conforming for me to have an attribute that returns an interface type that isn't exposed?

The dictionary is fine because the interface isn't exposed so you can't possibly set the dictionary to a value that uses the interface. But the attribute in theory could be used by a user agent in a way that returns that interface even in a worker, despite the interface not being exposed... I dunno, it just seemed like something that should be done for completeness.

How about this, is this ok?:
Comment 20 contributor 2014-01-28 20:34:34 UTC
Checked in as WHATWG revision r8430.
Check-in comment: Try doing this a different way (MessageEvent.source exposure)
http://html5.org/tools/web-apps-tracker?from=8429&to=8430
Comment 21 Anne 2014-01-28 20:38:26 UTC
That approach does not work for FormData of which the constructor takes a HTMLFormElement. Given that FormData is exposed in Window and Worker I think it should be okay if HTMLFormElement ends up being impossible in the Worker context.
Comment 22 Ian 'Hixie' Hickson 2014-01-28 21:35:46 UTC
For arguments, I don't think there's a problem with just exposing them everywhere. It's black-box indistinguishable from not exposing them (unless it's a constructor that only takes unexposed types, since then it'd be uncallable, but I'm not aware of any such cases). It's return values I'm more worried about.
Comment 23 Cameron McCormack 2014-01-29 00:56:01 UTC
(In reply to contributor from comment #20)
> Checked in as WHATWG revision r8430.
> Check-in comment: Try doing this a different way (MessageEvent.source
> exposure)
> http://html5.org/tools/web-apps-tracker?from=8429&to=8430

This has the same problems; the checking of duplicate attribute (and operation) identifiers is done on the whole set of members, not looking at [Exposed].

How about I just add a conformance requirement that says for an object associated with a global with a particular global name, only objects with interfaces that are exposed in that global may be returned?
Comment 24 Ian 'Hixie' Hickson 2014-01-29 17:55:37 UTC
That would work.
Comment 25 Ian 'Hixie' Hickson 2014-01-30 02:41:43 UTC
Ok, I've moved MessageEvent.source back. I think that concludes everything that I need to do for this bug. Sending back to heycam for the comment 23 update.
Comment 26 contributor 2014-01-30 02:41:55 UTC
Checked in as WHATWG revision r8444.
Check-in comment: Ok, go back to exposing MessageEvent.source in one form everywhere, relying on WebIDL for the rest of the logic here
http://html5.org/tools/web-apps-tracker?from=8443&to=8444
Comment 27 Anne 2017-12-06 11:29:20 UTC
The way we do this is by checking the current global object, defined in HTML. See https://xhr.spec.whatwg.org/ for an example if you need this.