Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
to avoid users accidentally downcasting `num`, which has different semantics
depending on whether you compile to JS or Wasm. See issue [#57][] for more
details.
- Fix an issue where some union types didn't account for typedef nullability.

[#57]: https://github.com/dart-lang/web/issues/57

Expand Down
2 changes: 1 addition & 1 deletion lib/src/dom/webgl1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1630,7 +1630,7 @@ extension type WebGLRenderingContext._(JSObject _) implements JSObject {
/// buffer object's data store.
external void bufferData(
GLenum target,
JSAny dataOrSize,
JSAny? dataOrSize,
GLenum usage,
);

Expand Down
12 changes: 6 additions & 6 deletions lib/src/dom/webgl2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,7 @@ extension type WebGL2RenderingContext._(JSObject _) implements JSObject {
GLint border,
GLenum format,
GLenum type,
JSAny pboOffsetOrSourceOrSrcData, [
JSAny? pboOffsetOrSourceOrSrcData, [
int srcOffset,
]);

Expand All @@ -1287,7 +1287,7 @@ extension type WebGL2RenderingContext._(JSObject _) implements JSObject {
GLsizei depth,
GLenum format,
GLenum type,
JSAny pboOffsetOrSourceOrSrcData, [
JSAny? pboOffsetOrSourceOrSrcData, [
int srcOffset,
]);

Expand Down Expand Up @@ -1946,7 +1946,7 @@ extension type WebGL2RenderingContext._(JSObject _) implements JSObject {
/// creates and initializes the buffer object's data store.
external void bufferData(
GLenum target,
JSAny sizeOrSrcData,
JSAny? sizeOrSrcData,
GLenum usage, [
int srcOffset,
GLuint length,
Expand All @@ -1972,7 +1972,7 @@ extension type WebGL2RenderingContext._(JSObject _) implements JSObject {
JSAny borderOrSource, [
GLenum format,
GLenum type,
JSAny pboOffsetOrPixelsOrSourceOrSrcData,
JSAny? pboOffsetOrPixelsOrSourceOrSrcData,
int srcOffset,
]);
external void texSubImage2D(
Expand All @@ -1984,7 +1984,7 @@ extension type WebGL2RenderingContext._(JSObject _) implements JSObject {
JSAny heightOrType,
JSAny formatOrSource, [
GLenum type,
JSAny pboOffsetOrPixelsOrSourceOrSrcData,
JSAny? pboOffsetOrPixelsOrSourceOrSrcData,
int srcOffset,
]);
external void compressedTexImage2D(
Expand Down Expand Up @@ -2086,7 +2086,7 @@ extension type WebGL2RenderingContext._(JSObject _) implements JSObject {
GLsizei height,
GLenum format,
GLenum type,
JSAny dstDataOrOffset, [
JSAny? dstDataOrOffset, [
int dstOffset,
]);
external JSObject get canvas;
Expand Down
11 changes: 7 additions & 4 deletions tool/generator/translator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,23 @@ class _Library {
}

/// If [rawType] corresponds to an IDL type that we declare as a typedef,
/// desugars the typedef.
/// desugars the typedef, accounting for nullability along the way.
///
/// Otherwise, returns null.
_RawType? _desugarTypedef(_RawType rawType) {
final decl = Translator.instance!._typeToDeclaration[rawType.type];
return switch (decl?.type) {
'typedef' => _getRawType((decl as idl.Typedef).idlType),
'typedef' => _getRawType((decl as idl.Typedef).idlType)
..nullable |= rawType.nullable,
// TODO(srujzs): If we ever add a generic JS function type, we should
// maybe leverage that here so we have stronger type-checking of
// callbacks.
'callback' || 'callback interface' => _RawType('JSFunction', false),
'callback' ||
'callback interface' =>
_RawType('JSFunction', rawType.nullable),
// TODO(srujzs): Enums in the WebIDL are just strings, but we could make
// them easier to work with on the Dart side.
'enum' => _RawType('JSString', false),
'enum' => _RawType('JSString', rawType.nullable),
_ => null
};
}
Expand Down