Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposing an interface "on all globals" #468

Closed
littledan opened this issue Oct 23, 2017 · 18 comments · Fixed by #526
Closed

Exposing an interface "on all globals" #468

littledan opened this issue Oct 23, 2017 · 18 comments · Fixed by #526

Comments

@littledan
Copy link
Collaborator

For WebAssembly, I'm using WebIDL to specify the interface between WebAssembly and JavaScript in this PR. We're trying to avoid tying this into the Web Platform. One of the few ways that the current spec does tie into the Web is, to expose the interface to global objects, it uses [Exposed=(Window,Worker)].

What we really want for Wasm is for it to be exposed on all global objects. One aspect was accidentally omitting it on Worklets, but the bigger aspect is omitting it for everything that's not the web platform. For example, Node.js is likely to eventually enable Wasm support, and so the interface should be created on its global object as well.

I imagine that a version of Exposed which is everywhere might be useful for the Web Platform as well. APIs like TextEncoder which don't do any particular I/O wouldn't need a change each time another type of global object is added--they could be like new libraries added in the JavaScript standard.

What would you think about an additional extended attribute, or mode of using [Exposed], to support this case?

@domenic
Copy link
Member

domenic commented Oct 23, 2017

+1, I think it would be good to have a carefully-considered class of APIs available everywhere. The question is what the worklets folks think, IMO: would exposing e.g. URL or TextEncoder make sense in worklets? I think so, but want to make sure there wasn't some particular reason they were excluded.

@annevk
Copy link
Member

annevk commented Oct 24, 2017

Something like [AlwaysExposed] seems reasonable. What can use it besides wasm we can discuss separately I suppose, or do you want to have at least a couple consumers?

@tobie
Copy link
Collaborator

tobie commented Oct 24, 2017

I'm not against this per se, but it seems to go against the idea of making sure editors carefully consider each place where their APIs are exposed (which I assumed we were championing when deciding to make [Exposed] mandatory). This might be mitigated by a combination of the following:

  1. requesting editors to file an issue here when they want to use it,
  2. have a checklist to make sure the API's a good fit,
  3. have Bikeshed/ReSpec add a warning for those (that can somehow be turned off).
  4. ?

@annevk
Copy link
Member

annevk commented Oct 24, 2017

I think requiring either is still good enough for that, coupled with implementer review. [AlwaysExposed] is effectively for standard library extensions.

@domenic
Copy link
Member

domenic commented Oct 24, 2017

Bikeshed: [Exposed=*]?

@tobie
Copy link
Collaborator

tobie commented Oct 24, 2017

Bikeshed: [Exposed=*]?

Yeah, that was also my initial thought. I think the grammar let's us do it, too.

@littledan
Copy link
Collaborator Author

Thanks for your support here! Should I make a PR for [Exposed=*] ?

@tobie
Copy link
Collaborator

tobie commented Oct 24, 2017

Sure. :)

@littledan
Copy link
Collaborator Author

I'm having trouble figuring out how the grammar supports [Exposed=*]. It seems like if you take a named argument, then * is not within the grammar of identifier; I'm not sure how any of the others would work either. Am I missing something? Otherwise, is it better to extend the grammar to include this, or to use [AlwaysExposed]?

@tobie
Copy link
Collaborator

tobie commented Oct 27, 2017

So you want to add a 6th non-terminal to the group of non-terminals described in Extended attributes: ExtendedAttributeWildcard, which you'd define as:

ExtendedAttributeWildcard :
    identifier "=" "*"

Note this group of non-terminals is a bit special, as it's a subset of what the grammar allows for extended attributes. So you'll still want to add "*" to the Other non-terminal to make the main grammar work.

And I think you should be fine. (That's generally when @bzbarsky shows up to tell me I'm wrong, so you might want to wait a couple of hours.)

@bzbarsky
Copy link
Collaborator

At first glance, that sounds fine to me too.

littledan added a commit to littledan/webidl that referenced this issue Feb 22, 2018
This patch adds support in WebIDL for declaring an interface available
in all contexts.

Closes whatwg#468
littledan added a commit to littledan/webidl that referenced this issue Feb 23, 2018
This patch adds support in WebIDL for declaring an interface available
in all contexts.

Closes whatwg#468
@annevk
Copy link
Member

annevk commented Feb 23, 2018

@bfgeek @padenot could you say something about #468 (comment)?

I think worklets are intentionally small in their API surface and therefore I think the preference is that nothing additional is exposed there, unless it adds sufficient utility. It's not entirely clear they need URL parsing (e.g., they don't want fetch()) or text encoding/decoding.

@littledan
Copy link
Collaborator Author

I'd be curious about feedback for a couple other things:

  • New JS features, such as ECMA-402 (Intl)
  • The WebAssembly/JS API

I was assuming that we'd want to expose these everywhere, including worklets, but this assumption was made without checking with Worklet experts.

littledan added a commit to littledan/webidl that referenced this issue Feb 23, 2018
This patch adds support in WebIDL for declaring an interface available
in all contexts.

Closes whatwg#468
littledan added a commit to littledan/webidl that referenced this issue Feb 23, 2018
This patch adds support in WebIDL for declaring an interface available
in all contexts.

Closes whatwg#468
@padenot
Copy link

padenot commented Feb 23, 2018

I think worklets are intentionally small in their API surface and therefore I think the preference is that nothing additional is exposed there, unless it adds sufficient utility. It's not entirely clear they need URL parsing (e.g., they don't want fetch()) or text encoding/decoding.

It is the current thinking of the Audio Working Group that indeed, we want the set of APIs available inside an AudioWorkletGlobalScope to be as minimal as possible. In particular, exposing APIs that can block execution for long periods of time or are asynchronous are not to be exposed.

In addition, my opinion is that it would be best to not expose API that would encourage mis-use of the AudioWorklet API. For example, string manipulation for internationalization or anything but executing WASM code is best done outside the worklet and transferred.

@littledan
Copy link
Collaborator Author

@padenot Currently, internationalization is being developed as an ad-on to the ECMAScript standard, and we don't even have notation for not exposing it in certain globals. Would you be interested in coming over to TC39 to explain the AudioWorkletGlobalScope requirements so we can make sure to accommodate them well? This could be through remotely attending a meeting over video conferencing, or filing an issue.

@padenot
Copy link

padenot commented Feb 23, 2018

I can certainly do both, but I will kick things off with an issue on the link you provided.

Thanks!

@padenot
Copy link

padenot commented Feb 26, 2018

I just opened tc39/ecma262#1120 for this.

@caitp
Copy link
Contributor

caitp commented Sep 30, 2021

I've put together a patch for WebCore in https://github.com/caitp/WebKit/pull/1/files, if anyone is interested in double checking my interpretation

Ms2ger pushed a commit to littledan/webidl that referenced this issue Oct 1, 2021
This patch adds support in WebIDL for declaring an interface available
in all contexts.

Closes whatwg#468
EdgarChen pushed a commit that referenced this issue Nov 2, 2021
This patch adds support in WebIDL for declaring an interface available in all contexts.

Closes #468

Co-authored-by: ExE Boss <3889017+ExE-Boss@users.noreply.github.com>
Co-authored-by: Ms2ger <Ms2ger@gmail.com>
webkit-commit-queue pushed a commit to WebKit/WebKit that referenced this issue Nov 3, 2021
https://bugs.webkit.org/show_bug.cgi?id=231082

Reviewed by Chris Dumez.

Adds a shorthand to expose interfaces/attributes on Window, Workers*,
and the forthcoming ShadowRealm global object.

See whatwg/webidl#468 and
whatwg/webidl#526 for details.

* bindings/scripts/CodeGenerator.pm:
(shouldPropertyBeExposed):
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateRuntimeEnableConditionalStringForExposed):
* bindings/scripts/IDLParser.pm:
(parseExtendedAttributeRest2):
* bindings/scripts/preprocess-idls.pl:
* bindings/scripts/test/AudioWorkletGlobalScopeConstructors.idl:
* bindings/scripts/test/DOMWindowConstructors.idl:
* bindings/scripts/test/DedicatedWorkerGlobalScopeConstructors.idl:
* bindings/scripts/test/ExposedStar.idl: Added.
* bindings/scripts/test/JS/JSDOMWindow.cpp:
(WebCore::jsDOMWindow_ExposedStarConstructorGetter):
(WebCore::JSC_DEFINE_CUSTOM_GETTER):
* bindings/scripts/test/JS/JSDedicatedWorkerGlobalScope.cpp:
(WebCore::jsDedicatedWorkerGlobalScope_ExposedStarConstructorGetter):
(WebCore::JSC_DEFINE_CUSTOM_GETTER):
* bindings/scripts/test/JS/JSExposedStar.cpp: Added.
(WebCore::JSExposedStarDOMConstructor::prototypeForStructure):
(WebCore::JSExposedStarDOMConstructor::initializeProperties):
(WebCore::JSExposedStarPrototype::finishCreation):
(WebCore::JSExposedStar::JSExposedStar):
(WebCore::JSExposedStar::finishCreation):
(WebCore::JSExposedStar::createPrototype):
(WebCore::JSExposedStar::prototype):
(WebCore::JSExposedStar::getConstructor):
(WebCore::JSC_DEFINE_CUSTOM_GETTER):
(WebCore::jsExposedStarPrototypeFunction_operationForAllContextsBody):
(WebCore::JSC_DEFINE_HOST_FUNCTION):
(WebCore::jsExposedStarPrototypeFunction_operationJustForWindowContextsBody):
(WebCore::jsExposedStarPrototypeFunction_operationJustForWorkerContextsBody):
(WebCore::JSExposedStar::subspaceForImpl):
(WebCore::JSExposedStar::analyzeHeap):
(WebCore::toJSNewlyCreated):
(WebCore::toJS):
(WebCore::JSExposedStar::toWrapped):
* bindings/scripts/test/JS/JSExposedStar.h: Added.
(WebCore::JSExposedStar::create):
(WebCore::JSExposedStar::createStructure):
(WebCore::JSExposedStar::subspaceFor):
(WebCore::JSExposedStar::wrapped const):
(WebCore::toJS):
(WebCore::toJSNewlyCreated):
* bindings/scripts/test/JS/JSPaintWorkletGlobalScope.cpp:
(WebCore::jsPaintWorkletGlobalScope_ExposedStarConstructorGetter):
(WebCore::JSC_DEFINE_CUSTOM_GETTER):
* bindings/scripts/test/JS/JSServiceWorkerGlobalScope.cpp:
(WebCore::jsServiceWorkerGlobalScope_ExposedStarConstructorGetter):
(WebCore::JSC_DEFINE_CUSTOM_GETTER):
* bindings/scripts/test/PaintWorkletGlobalScopeConstructors.idl:
* bindings/scripts/test/ServiceWorkerGlobalScopeConstructors.idl:
* bindings/scripts/test/SupplementalDependencies.dep:



Canonical link: https://commits.webkit.org/243822@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@285196 268f45cc-cd09-0410-ab3c-d52691b4dbfc
philn pushed a commit to philn/old-webkit that referenced this issue Nov 3, 2021
https://bugs.webkit.org/show_bug.cgi?id=231082

Reviewed by Chris Dumez.

Adds a shorthand to expose interfaces/attributes on Window, Workers*,
and the forthcoming ShadowRealm global object.

See whatwg/webidl#468 and
whatwg/webidl#526 for details.

* bindings/scripts/CodeGenerator.pm:
(shouldPropertyBeExposed):
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateRuntimeEnableConditionalStringForExposed):
* bindings/scripts/IDLParser.pm:
(parseExtendedAttributeRest2):
* bindings/scripts/preprocess-idls.pl:
* bindings/scripts/test/AudioWorkletGlobalScopeConstructors.idl:
* bindings/scripts/test/DOMWindowConstructors.idl:
* bindings/scripts/test/DedicatedWorkerGlobalScopeConstructors.idl:
* bindings/scripts/test/ExposedStar.idl: Added.
* bindings/scripts/test/JS/JSDOMWindow.cpp:
(WebCore::jsDOMWindow_ExposedStarConstructorGetter):
(WebCore::JSC_DEFINE_CUSTOM_GETTER):
* bindings/scripts/test/JS/JSDedicatedWorkerGlobalScope.cpp:
(WebCore::jsDedicatedWorkerGlobalScope_ExposedStarConstructorGetter):
(WebCore::JSC_DEFINE_CUSTOM_GETTER):
* bindings/scripts/test/JS/JSExposedStar.cpp: Added.
(WebCore::JSExposedStarDOMConstructor::prototypeForStructure):
(WebCore::JSExposedStarDOMConstructor::initializeProperties):
(WebCore::JSExposedStarPrototype::finishCreation):
(WebCore::JSExposedStar::JSExposedStar):
(WebCore::JSExposedStar::finishCreation):
(WebCore::JSExposedStar::createPrototype):
(WebCore::JSExposedStar::prototype):
(WebCore::JSExposedStar::getConstructor):
(WebCore::JSC_DEFINE_CUSTOM_GETTER):
(WebCore::jsExposedStarPrototypeFunction_operationForAllContextsBody):
(WebCore::JSC_DEFINE_HOST_FUNCTION):
(WebCore::jsExposedStarPrototypeFunction_operationJustForWindowContextsBody):
(WebCore::jsExposedStarPrototypeFunction_operationJustForWorkerContextsBody):
(WebCore::JSExposedStar::subspaceForImpl):
(WebCore::JSExposedStar::analyzeHeap):
(WebCore::toJSNewlyCreated):
(WebCore::toJS):
(WebCore::JSExposedStar::toWrapped):
* bindings/scripts/test/JS/JSExposedStar.h: Added.
(WebCore::JSExposedStar::create):
(WebCore::JSExposedStar::createStructure):
(WebCore::JSExposedStar::subspaceFor):
(WebCore::JSExposedStar::wrapped const):
(WebCore::toJS):
(WebCore::toJSNewlyCreated):
* bindings/scripts/test/JS/JSPaintWorkletGlobalScope.cpp:
(WebCore::jsPaintWorkletGlobalScope_ExposedStarConstructorGetter):
(WebCore::JSC_DEFINE_CUSTOM_GETTER):
* bindings/scripts/test/JS/JSServiceWorkerGlobalScope.cpp:
(WebCore::jsServiceWorkerGlobalScope_ExposedStarConstructorGetter):
(WebCore::JSC_DEFINE_CUSTOM_GETTER):
* bindings/scripts/test/PaintWorkletGlobalScopeConstructors.idl:
* bindings/scripts/test/ServiceWorkerGlobalScopeConstructors.idl:
* bindings/scripts/test/SupplementalDependencies.dep:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@285196 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

7 participants