Skip to content

Commit

Permalink
Treat JSUndefined as nullable in _RawType
Browse files Browse the repository at this point in the history
  • Loading branch information
srujzs committed Oct 23, 2023
1 parent cbc1be1 commit 1b17163
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tool/bindings_generator/translator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ _RawType _computeRawTypeUnion(_RawType rawType1, _RawType rawType2) {
final nullable1 = rawType1.nullable;
final nullable2 = rawType2.nullable;

// Equality.
if (type1 == type2) return _RawType(type1, nullable1 || nullable2);
// This sentinel is only for nullability.
if (type1 == 'JSUndefined') return _RawType(type2, true);
if (type2 == 'JSUndefined') return _RawType(type1, true);
// Equality.
if (type1 == type2) return _RawType(type1, nullable1 || nullable2);
// If the two types are not equal, we can just use `JSNumber` as the union can
// never be `JSInteger` or `JSDouble` anyways.
if (type1 == 'JSInteger' || type1 == 'JSDouble') rawType1.type = 'JSNumber';
Expand Down Expand Up @@ -193,7 +193,11 @@ class _RawType {
String type;
bool nullable;

_RawType(this.type, this.nullable);
_RawType(this.type, this.nullable) {
// While the IDL does not define `undefined` as nullable, it is treated as
// null in interop.
if (type == 'JSUndefined') nullable = true;
}

void update(idl.IDLType idlType) {
final union =
Expand Down

0 comments on commit 1b17163

Please sign in to comment.