Skip to content
Open
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
2 changes: 2 additions & 0 deletions pkgs/ffigen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
change to something more sensible.
- __Breaking change__: Deleted the config option `Output.sort`. Sorting is now
always enabled.
- Fix(https://github.com/dart-lang/native/issues/2877)
such that ObjCObject `isA` now accepts a nullable `ObjCObject?` and returns `false` when called with `null`, aligning its behavior with Dart’s `is`operator.

## 20.1.1

Expand Down
12 changes: 7 additions & 5 deletions pkgs/ffigen/example/objective_c/avf_audio_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,13 @@ extension type AVAudioPlayer._(objc.ObjCObject object$)
}

/// Returns whether [obj] is an instance of [AVAudioPlayer].
static bool isA(objc.ObjCObject obj) => _objc_msgSend_19nvye5(
obj.ref.pointer,
_sel_isKindOfClass_,
_class_AVAudioPlayer,
);
static bool isA(objc.ObjCObject? obj) => obj == null
? false
: _objc_msgSend_19nvye5(
obj.ref.pointer,
_sel_isKindOfClass_,
_class_AVAudioPlayer,
);

/// alloc
static AVAudioPlayer alloc() {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/ffigen/lib/src/code_generator/objc_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ ${generateInstanceMethodBindings(w, this)}

s.write('''
/// Returns whether [obj] is an instance of [$name].
static bool isA($wrapObjType obj) => $isKindOfClass;
static bool isA($wrapObjType? obj) => obj == null ? false : $isKindOfClass;
''');

s.write(generateStaticMethodBindings(w, this));
Expand Down
6 changes: 6 additions & 0 deletions pkgs/ffigen/test/native_objc_test/is_instance_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,11 @@ void main() {
expect(IsInstanceChildClass.isA(base), isFalse);
expect(IsInstanceChildClass.isA(child), isTrue);
});

test('Null input', () {
expect(IsInstanceBaseClass.isA(null), isFalse);
expect(IsInstanceChildClass.isA(null), isFalse);
expect(IsInstanceUnrelatedClass.isA(null), isFalse);
});
});
}
3 changes: 3 additions & 0 deletions pkgs/objective_c/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 9.4.0
- Fix (https://github.com/dart-lang/native/issues/2877) such that all occurances of ObjCObject `isA` now accepts a nullable `ObjCObject?` and returns `false` when input is`null`

## 9.3.0
- `autoReleasePool` now returns the value produced by its callback.

Expand Down
Loading