Skip to content

Commit

Permalink
Fix castTo and publish 0.10.0 (#1323)
Browse files Browse the repository at this point in the history
  • Loading branch information
HosseinYousefi authored Jul 11, 2024
1 parent c46b0cd commit 34d28f1
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 9 deletions.
6 changes: 6 additions & 0 deletions pkgs/jni/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.10.0

- Fixed an issue with `JObject.castTo` where the type checking could fail in
debug mode.
- Used `package:dart_flutter_team_lints`.

## 0.9.3

- Added lifetime event handling for the thread-local JNI env. Now
Expand Down
9 changes: 7 additions & 2 deletions pkgs/jni/lib/src/jobject.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ final class JObjectType extends JObjType<JObject> {
/// A high-level wrapper for JNI global object reference.
///
/// This is the base class for classes generated by `jnigen`.
class JObject {
class JObject implements Finalizable {
final JReference reference;

late final JObjType<JObject> $type = type;
Expand Down Expand Up @@ -83,7 +83,12 @@ class JObject {
bool releaseOriginal = false,
}) {
assert(
Jni.env.IsInstanceOf(reference.pointer, type.jClass.reference.pointer),
() {
final jClass = type.jClass.reference.toPointer();
final canBeCasted = Jni.env.IsInstanceOf(reference.pointer, jClass);
Jni.env.DeleteGlobalRef(jClass);
return canBeCasted;
}(),
'The object must be of type "${type.signature}".',
);
if (releaseOriginal) {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/jni/lib/src/jreference.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class _JFinalizable implements Finalizable {
}

@pragma('vm:deeply-immutable')
abstract final class JReference {
abstract final class JReference implements Finalizable {
final _JFinalizable _finalizable;

JReference(this._finalizable);
Expand Down
2 changes: 1 addition & 1 deletion pkgs/jni/test/exception_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void main() {
if (!caught) {
stderr.writeln('Expected HelperNotFoundException\n'
'Read exception_test.dart for details.');
exit(-1);
exit(1);
}
}
run(testRunner: test);
Expand Down
2 changes: 1 addition & 1 deletion pkgs/jni/tool/generate_ide_files.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void runCommand(String exec, List<String> args, String workingDirectory) {
stdout.writeln(process.stdout);
stderr.writeln(process.stderr);
stderr.writeln('command failed with exit code ${process.exitCode}');
exit(-1);
exit(1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ ResultWrapper getResultWrapper(String returnType) {
return ResultWrapper.forJValueField(jfields[returnType]!);
}
stderr.writeln('Unknown type $returnType for return type');
exit(-1);
exit(1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ String getCheckedGetter(Type returnType) {
return mappings[cType]!;
}
stderr.writeln('Unknown return type: $cType');
exit(-1);
exit(1);
}

String? getGlobalEnvExtensionFunction(Member field, Type? checkedReturnType) {
Expand Down
4 changes: 2 additions & 2 deletions pkgs/jnigen/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## 0.10.0-wip
## 0.10.0

- Added support for Kotlin's top-level functions and fields.
- Use `package:dart_flutter_team_lints`.
- Used `package:dart_flutter_team_lints`.

## 0.9.3

Expand Down

0 comments on commit 34d28f1

Please sign in to comment.