Skip to content

Commit

Permalink
[feat] LegacyNamespace extended attributes support on IDL interfaces (R…
Browse files Browse the repository at this point in the history
…esolves #283) (#297)

* updates

* changelog updated

* package changelog updated

* dart formatting updates

* Update web/CHANGELOG.md

Co-authored-by: Kevin Moore <kevmoo@users.noreply.github.com>

* formatting updates

---------

Co-authored-by: Kevin Moore <kevmoo@users.noreply.github.com>
  • Loading branch information
rutvik110 and kevmoo authored Sep 4, 2024
1 parent 6a8c3c5 commit fb30192
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Exposed constants with primitive values as non-`external` so they can be
`switch`ed over.
- Add an extension `responseHeaders` to `XMLHttpRequest`.
- Correctly namespace `WebAssembly` types.

## 1.0.0

Expand Down
5 changes: 5 additions & 0 deletions web/lib/src/dom/wasm_js_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ extension type ModuleImportDescriptor._(JSObject _) implements JSObject {
external ImportExportKind get kind;
external set kind(ImportExportKind value);
}
@JS('WebAssembly.Module')
extension type Module._(JSObject _) implements JSObject {
external factory Module(BufferSource bytes);

Expand All @@ -83,6 +84,7 @@ extension type Module._(JSObject _) implements JSObject {
String sectionName,
);
}
@JS('WebAssembly.Instance')
extension type Instance._(JSObject _) implements JSObject {
external factory Instance(
Module module, [
Expand All @@ -102,6 +104,7 @@ extension type MemoryDescriptor._(JSObject _) implements JSObject {
external int get maximum;
external set maximum(int value);
}
@JS('WebAssembly.Memory')
extension type Memory._(JSObject _) implements JSObject {
external factory Memory(MemoryDescriptor descriptor);

Expand All @@ -122,6 +125,7 @@ extension type TableDescriptor._(JSObject _) implements JSObject {
external int get maximum;
external set maximum(int value);
}
@JS('WebAssembly.Table')
extension type Table._(JSObject _) implements JSObject {
external factory Table(
TableDescriptor descriptor, [
Expand Down Expand Up @@ -150,6 +154,7 @@ extension type GlobalDescriptor._(JSObject _) implements JSObject {
external bool get mutable;
external set mutable(bool value);
}
@JS('WebAssembly.Global')
extension type Global._(JSObject _) implements JSObject {
external factory Global(
GlobalDescriptor descriptor, [
Expand Down
10 changes: 9 additions & 1 deletion web_generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 1.0.0-wip

- Initial separation of `web_generator` from `web`.
- Initial separation of `web_generator` from `web`.
- New IDL interface `RHL` added. `ExtendedAttribute` idl interface updated to
expose its `rhs` property and `Interfacelike` idl interface updated to expose
`extAttrs` property. The generator now adds a
`JS(LegacyNamespace.$extensionTypeName)` annotation on `JS` objects if
they've an IDL extended attribute `[LegacyNamespace=Foo]` defined in their IDL
description.


17 changes: 16 additions & 1 deletion web_generator/lib/src/translator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'dart:js_interop';

import 'package:code_builder/code_builder.dart' as code;
import 'package:collection/collection.dart';
import 'package:path/path.dart' as p;

import 'banned_names.dart';
Expand Down Expand Up @@ -1244,6 +1245,7 @@ class Translator {
code.ExtensionType _extensionType({
required String jsName,
required String dartClassName,
required List<idl.ExtendedAttribute> extendedAttributes,
required MdnInterface? mdnInterface,
required BCDInterfaceStatus? interfaceStatus,
required List<String> implements,
Expand All @@ -1257,6 +1259,12 @@ class Translator {

final jsObject = _typeReference(_RawType('JSObject', false));
const representationFieldName = '_';
final legacyNameSpace = extendedAttributes
.firstWhereOrNull(
(extendedAttribute) => extendedAttribute.name == 'LegacyNamespace',
)
?.rhs
.value;
final instancePropertyMethods = <code.Method>[];
final staticPropertyMethods = <code.Method>[];
final propertySpecs = _properties(properties, mdnInterface);
Expand All @@ -1267,7 +1275,12 @@ class Translator {
return code.ExtensionType((b) => b
..docs.addAll(docs)
..annotations.addAll(
_jsOverride(isObjectLiteral || jsName == dartClassName ? '' : jsName))
_jsOverride(
legacyNameSpace != null
? '$legacyNameSpace.$jsName'
: (isObjectLiteral || jsName == dartClassName ? '' : jsName),
),
)
..name = dartClassName
..primaryConstructorName = '_'
..representationDeclaration = code.RepresentationDeclaration((b) => b
Expand Down Expand Up @@ -1300,6 +1313,7 @@ class Translator {
final type = interfacelike.type;
final isNamespace = type == 'namespace';
final isDictionary = type == 'dictionary';
final extendedAttributes = idlInterfacelike.extAttrs.toDart;

final mdnInterface = docProvider.interfaceFor(jsName);

Expand Down Expand Up @@ -1327,6 +1341,7 @@ class Translator {
_extensionType(
jsName: jsName,
dartClassName: dartClassName,
extendedAttributes: extendedAttributes,
mdnInterface: mdnInterface,
interfaceStatus: interfaceStatus,
implements: implements,
Expand Down
7 changes: 7 additions & 0 deletions web_generator/lib/src/webidl_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ extension type Interfacelike._(JSObject _) implements Named {
external bool get partial;
external JSArray<Member> get members;
external String? get inheritance;
external JSArray<ExtendedAttribute> get extAttrs;
}

extension type Callback._(JSObject _) implements Named {
Expand Down Expand Up @@ -66,6 +67,12 @@ extension type Member._(JSObject _) implements JSObject {

extension type ExtendedAttribute._(JSObject _) implements JSObject {
external String get name;
external RHS get rhs;
}

extension type RHS._(JSObject _) implements JSObject {
external String get type;
external String get value;
}

extension type Argument._(JSObject _) implements JSObject {
Expand Down

0 comments on commit fb30192

Please sign in to comment.