web
web copied to clipboard
Generate static properties for `const` IDL entries
It would be useful to expose all const properties from the IDL. For example, currently we are missing about ~300 GLenum values in WebGLRenderingContext
, such as WebGLRenderingContext.DEPTH_BUFFER_BIT
I just noticed that the current package exposes these values under WebGLRenderingContextBase
. However, this type is not exposed by browsers, so they are not accessible with the current API (instead you get an error if you try to access them).
I think this is a bug in how we handle interface mixin
s. While the solution of generating a Dart interface for these mixins and having interfaces that include those mixins implement
the Dart interface works for instance members, it doesn't work for static members, as they are tied to the interface they are defined in.
It might be better to instead always add the members of the interface mixin
s to the interfaces that include them and not generate an interface for the mixin at all.
Each member of M is considered to be a member of each interface I, J, K, … that includes M, as if a copy of each member had been made. So for a given member m of M, interface I is considered to have a member mI, interface J is considered to have a member mJ, interface K is considered to have a member mK, and so on. The host interfaces of mI, mJ, and mK, are I, J, and K respectively.
https://webidl.spec.whatwg.org/#include
Just hit this with https://html.spec.whatwg.org/multipage/media.html#error-codes on https://github.com/flutter/packages/pull/7012#discussion_r1702435508
Now that we're using extension types, could we do
diff --git a/lib/src/dom/html.dart b/lib/src/dom/html.dart
index 556e65f..475e7cb 100644
--- a/lib/src/dom/html.dart
+++ b/lib/src/dom/html.dart
@@ -3693,10 +3693,10 @@ extension type HTMLMediaElement._(JSObject _) implements HTMLElement, JSObject {
/// API documentation sourced from
/// [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/API/MediaError).
extension type MediaError._(JSObject _) implements JSObject {
- external static int get MEDIA_ERR_ABORTED;
- external static int get MEDIA_ERR_NETWORK;
- external static int get MEDIA_ERR_DECODE;
- external static int get MEDIA_ERR_SRC_NOT_SUPPORTED;
+ static const int MEDIA_ERR_ABORTED = 1;
+ static const int MEDIA_ERR_NETWORK = 2;
+ static const int MEDIA_ERR_DECODE = 3;
+ static const int MEDIA_ERR_SRC_NOT_SUPPORTED = 4;
/// The read-only property **`MediaError.code`** returns a numeric
/// value which represents the kind of error that occurred on a media element.
I guess we're breaking the pure abstraction a tiny bit, because we're trusting the IDL more than the browser. 🤷
The original bug is different (we used to not emit any members for these properties), but also similar. I do like the idea for exhaustiveness, even if it does avoid fetching from the browser. The code
here is what really matter anyways.