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

[feat] LegacyNamespace extended attributes support on IDL interfaces (Resolves #283) #297

Merged
merged 7 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
1 change: 1 addition & 0 deletions web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
`getter`s and `setter`s, respectively.
- Exposed constants with primitive values as non-`external` so they can be
`switch`ed over.
- 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')
kevmoo marked this conversation as resolved.
Show resolved Hide resolved
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`.
srujzs marked this conversation as resolved.
Show resolved Hide resolved
- 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.


14 changes: 13 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';
kevmoo marked this conversation as resolved.
Show resolved Hide resolved

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,9 @@ 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 +1272,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 +1310,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 +1338,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
Loading