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

Add info on generation conventions #171

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,42 @@ void main() {
}
```

## Generation conventions

The generator scripts use a number of conventions they use consistently to
srujzs marked this conversation as resolved.
Show resolved Hide resolved
handle Web IDL definitions:

### Interfaces

- Interfaces are emitted as extension types that wrap and implement `JSObject`.
- Interface inheritance is maintained using `implements`.
srujzs marked this conversation as resolved.
Show resolved Hide resolved
- Members of partial interfaces and partial mixins are added to the interfaces
and mixins that include them, and therefore do not have separate declarations.
- Members of mixins are added to the interfaces that include them, and therefore
srujzs marked this conversation as resolved.
Show resolved Hide resolved
do not have separate declarations.

### Types

- Generic types include the generic in the case of `JSArray` and `JSPromise`.
- Enums are typedef'd to `String`.
- Callbacks and callback interfaces are typedef'd to `JSFunction`.
- In general, we prefer the Dart primitive over the JS type equivalent wherever
possible. For example, APIs use `String` instead of `JSString`.
- If a type appears in a generic position and it was typedef'd to a Dart
primitive type, it is replaced with the JS type equivalent to respect type
bounds.
srujzs marked this conversation as resolved.
Show resolved Hide resolved
- Union types are computed by picking the least upper bound of the types in the
JS type hierarchy, where every interface is equivalent to `JSObject`.

### Compatibility

- The generator uses the
[MDN compatibility data](https://github.com/mdn/browser-compat-data) to
determine what members and interfaces to emit. Currently, we only emit code
that is standards track and supported on Chrome, Firefox, and Safari to reduce
the number of breaking changes. This is currently WIP and some members may be
added or removed.

## Web IDL version

Based on:
Expand Down
2 changes: 1 addition & 1 deletion tool/generator/bcd.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ abstract class BCDItem {
}

extension BCDJsonDataExtension on Map<String, dynamic> {
/// Return keys which coorespond to symbol names (i.e., filter out non-symbol
/// Return keys which correspond to symbol names (i.e., filter out non-symbol
/// metadata (`__meta`, `__compat`, ...).
Iterable<String> get symbolNames => keys.where((key) => !key.startsWith('_'));
}