-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Establish standard mechanism for implementing static methods in DOM IDL #3514
Comments
Why does DOMURL need to be an interface? |
It can't be a class.
We also need a typedef for the Function type for each of the fake static function objects. Otherwise the editor will not be able to make good suggestions, e.g. the correct number and types of arguments. |
I didn't really think it through when I suggested this to Lars today, but my rough idea was to have an abstract class for DOMURL and use its implied interface like this: abstract class DOMURL { class _DOMURL implements DOMURL { That should solve 1 (as long as you don't need to use the default implementation of the interface) and maybe 2 still works? As I said, I didn't really think this through. |
It's not clear to me how abstract classes would work in general. The public interfaces make a deep tree. The private implementation classes (for either Dartium or Dart2JS) make a mirror tree. Then, pairwise, the implementation class implements its corresponding interface. E.g., interfaces: CanvasElement extends Element extends Node extends EventTarget. and classes: _CanvasElementImpl extends _ElementImpl extends ... If we need to add a static method to CanvasElement, where do we put it? |
So you would have a tree of abstract "interface" classes like this: abstract class EventTarget ... and then you implement the implied interfaces for them in the parallel hierarchy: class _EventTargetImpl implements EventTarget ... The static methods go into the abstract "interface" classes and you may need to add factory methods to them as well so if you try to construct a CanvasElement you really get a _CanvasElementImpl. Still not quite sure if this works in general. |
As far as I can tell, this scheme should work just fine (unless there are further constraints that have not been mentioned). In particular, the objections raised in comment 2 do not seem to apply: Every class has an implied interface, so an abstract class can be used as an interface. Instantiating an abstract class via a factory constructor is perfectly legal, so make sure that the constructors are declared as factories and create the desired implementation classes. At the moment, I don't see why this won't work. It's growing on me, as it nicely leverages implicit interfaces and factory constructors. |
Clever! Renaming the bug title to reflect other options. :-) So, two possibilities: (1). Use operator call as sketched out in my first comment. This is blocked on implementation: It may require a level of overhead at runtime as well (i.e., singleton "function" objects). (2). Use Kasper's abstract class scheme. It looks like everything we need is implemented. It's a somewhat more significant rework, but it should be straightforward:
Any downsides to this approach? Changed the title to: "Establish standard mechanism for implementing static methods in DOM IDL". |
This comment was originally written by [email protected] The main problem is multiple inheritance which doesn't quite fit into Kasper's scheme. There is a workaround---just copy methods from other classes. |
Note, you can modify Kasper's scheme to have the abstract classes just implement each other: abstract class EventTarget ... So, I think everything works out just as it does today. We'll of course still need the copy trick for the Impl classes. |
This comment was originally written by [email protected] Yes, I know it, but the problem is with methods, the case: IDL: interface A { methodA(); } Now we generate: abstract class A implements B, C extends ? Apparently whatever you put instead of ?, you'll have to copy another method for a second class. |
Anton, why does A (actually, I think you meant C from IDL) need to extend anything? IDL: interface A { methodA(); } Generate: abstract class A { abstract class B { abstract class C implements A, B { class _AImpl extends _DOMWrapperBase implements A { class _BImpl extends _DOMWrapperBase implements B { class _CImpl extends _AImpl implements C { It's not clear to me whether the abstract C needs to redeclare methodA or methodB. If I omit them, the editor doesn't give me a warning and my sample seems to run just fine. |
This comment was originally written by [email protected] But now your abstract class doesn't implement promised interface which should trigger a warning, no? |
It currently doesn't trigger such a warning in the Dart editor & it (my simple test) works in Dartium and Dart2JS without warning or error. Surprisingly, the editor is even able to code complete methods on C that are not implemented in C (but are declared via implements and implemented in _CImpl). Gilad / Kasper: should it be a warning if an abstract class does not implement the interfaces in its implements clause? cc @gbracha. |
No. If a concrete class does not implement methods, that will cause |
This comment was originally written by [email protected] Gilad, thanks for explanations, sorry I wrongly assumed that abstract classes must implement methods. |
Changes: ``` > git log --format="%C(auto) %h %s" ac7db6c..ec35d46 https://dart.googlesource.com/pub.git/+/ec35d462 Fix null-safety warning in dart.dart (#3514) https://dart.googlesource.com/pub.git/+/7d30cf0b Allow pubspec key 'funding' (#3529) https://dart.googlesource.com/pub.git/+/8ff63a8e Fix remaining usages of path.prettyUri on git uris (#3524) https://dart.googlesource.com/pub.git/+/bc32a30e Fix typo "exitcode" (#3511) ``` Diff: https://dart.googlesource.com/pub.git/+/ac7db6c07318efa4a8712110275eaf70f96a6d00~..ec35d46261b610e558dfd0d8525ca3fc8387b4b7/ Change-Id: I535f4fab8940ee8400ef75369d35fb4c1ee3adab Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/255990 Reviewed-by: Sarah Zakarias <[email protected]> Commit-Queue: Sigurd Meldgaard <[email protected]>
This reverts commit 78636aa. Reason for revert: This breaks the google3 roll. We need to roll frontend_server_client first. Original change's description: > Bump pub to ec35d46261b610e558dfd0d8525ca3fc8387b4b7 > > Changes: > ``` > > git log --format="%C(auto) %h %s" ac7db6c..ec35d46 > https://dart.googlesource.com/pub.git/+/ec35d462 Fix null-safety warning in dart.dart (#3514) > https://dart.googlesource.com/pub.git/+/7d30cf0b Allow pubspec key 'funding' (#3529) > https://dart.googlesource.com/pub.git/+/8ff63a8e Fix remaining usages of path.prettyUri on git uris (#3524) > https://dart.googlesource.com/pub.git/+/bc32a30e Fix typo "exitcode" (#3511) > > ``` > > Diff: https://dart.googlesource.com/pub.git/+/ac7db6c07318efa4a8712110275eaf70f96a6d00~..ec35d46261b610e558dfd0d8525ca3fc8387b4b7/ > Change-Id: I535f4fab8940ee8400ef75369d35fb4c1ee3adab > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/255990 > Reviewed-by: Sarah Zakarias <[email protected]> > Commit-Queue: Sigurd Meldgaard <[email protected]> [email protected],[email protected] Change-Id: I9f46b5a63f8c3f0b11a9fe1d348696b1f988e5ca No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/256080 Reviewed-by: Sigurd Meldgaard <[email protected]> Commit-Queue: Sigurd Meldgaard <[email protected]> Reviewed-by: Jonas Jensen <[email protected]>
This is a reland of commit 78636aa Original change's description: > Bump pub to ec35d46261b610e558dfd0d8525ca3fc8387b4b7 > > Changes: > ``` > > git log --format="%C(auto) %h %s" ac7db6c..ec35d46 > https://dart.googlesource.com/pub.git/+/ec35d462 Fix null-safety warning in dart.dart (#3514) > https://dart.googlesource.com/pub.git/+/7d30cf0b Allow pubspec key 'funding' (#3529) > https://dart.googlesource.com/pub.git/+/8ff63a8e Fix remaining usages of path.prettyUri on git uris (#3524) > https://dart.googlesource.com/pub.git/+/bc32a30e Fix typo "exitcode" (#3511) > > ``` > > Diff: https://dart.googlesource.com/pub.git/+/ac7db6c07318efa4a8712110275eaf70f96a6d00~..ec35d46261b610e558dfd0d8525ca3fc8387b4b7/ > Change-Id: I535f4fab8940ee8400ef75369d35fb4c1ee3adab > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/255990 > Reviewed-by: Sarah Zakarias <[email protected]> > Commit-Queue: Sigurd Meldgaard <[email protected]> Change-Id: I9c50c7b5ea01fc24cc97b328766ad7d2b9c4b36e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/256280 Reviewed-by: Sarah Zakarias <[email protected]> Commit-Queue: Sigurd Meldgaard <[email protected]>
We have static methods popping up in upstream IDL. We need a standard way to map these. Currently, we do not expose these methods on any public interface or class by default. With operator call, we can do the following:
class _DOMURL_createObjectURL {
const _DOMURL_createObjectURL();
String operator call() => ...;
}
interface DOMURL {
static final Function createObjectURL = const _DOMURL_createObjectURL();
...
}
main() {
...
String url = DOMURL.createObjectURL(blob);
...
}
The text was updated successfully, but these errors were encountered: