WICG / digital-goods

Other
50 stars 28 forks source link

Invalid Web IDL: DigitalGoodsService needs an "[Exposed]" extended attribute #46

Closed tidoust closed 2 years ago

tidoust commented 2 years ago

The Web IDL definition of the DigitalGoodsService interface is currently invalid because interfaces must have an [Exposed] extended attribute. Something like:

[Exposed=Window, SecureContext] interface DigitalGoodsService { ... }
rsolomakhin commented 2 years ago

Thank you for the report. Fixed in commit https://github.com/WICG/digital-goods/commit/e712065dd43a1cc273753171e27e54df2499a7b7.

rsolomakhin commented 2 years ago

Hi @tidoust , if we don't want to expose DigitalGoodsService as window.DigitalGoodsService, what is the valid Web IDL definition for that?

So far we have been asking web developers to use if (window.getDigitalGoodsService) for feature detection. Adding ability for if (window.DigitalGoodsService) seems redundant.

tidoust commented 2 years ago

That is essentially not possible. Or rather, Web IDL defines a [LegacyNoInterfaceObject] extended attribute for that but, as the name suggests, it only exists for legacy purpose and should not be used in specifications.

Without that legacy extended attribute, interfaces always create a property on the global object.

rsolomakhin commented 2 years ago

That is very interesting. Do you know what is the reasoning for this?

tidoust commented 2 years ago

Sorry, I don't know the history of the why and how. One possible reason is that this allows developers to override prototype methods, which you cannot do if you don't have access to the interface object.

The only remaining users of [LegacyNoInterfaceObject] today are WebGL extensions, and I note an ongoing discussion thread on removing the extended attribute, which mentions feature detection considerations (and prototype method overrides) at https://github.com/KhronosGroup/WebGL/issues/3366

rsolomakhin commented 2 years ago

Great! Thank you for the link 😆