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

Add handle ownership again #876

Merged
merged 10 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions common/lib/src/realm_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ class RealmError extends Error {
String toString() => "Realm error : $message";
}

/// An error throw when operating on an object that has been closed.
/// {@category Realm}
class RealmClosedError extends RealmError {
RealmClosedError(String message) : super(message);
}

/// Thrown if the operation is not supported.
/// {@category Realm}
class RealmUnsupportedSetError extends UnsupportedError implements RealmError {
Expand All @@ -78,6 +84,7 @@ class RealmUnsupportedSetError extends UnsupportedError implements RealmError {
class RealmStateError extends StateError implements RealmError {
RealmStateError(super.message);
}

/// @nodoc
class Decimal128 {} // TODO Support decimal128 datatype https://github.com/realm/realm-dart/issues/725

Expand Down
11 changes: 9 additions & 2 deletions lib/src/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ManagedRealmList<T extends Object?> extends collection.ListBase<T> with Re
}

@override
int get length => realmCore.getListSize(_handle);
int get length => realmCore.getListSize(handle);

@override

blagoev marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -168,7 +168,14 @@ extension RealmListInternal<T extends Object?> on RealmList<T> {

ManagedRealmList<T> asManaged() => this is ManagedRealmList<T> ? this as ManagedRealmList<T> : throw RealmStateError('$this is not managed');

RealmListHandle get handle => asManaged()._handle;
RealmListHandle get handle {
final result = asManaged()._handle;
if (result.released) {
throw RealmClosedError('Cannot access a list that belongs to a closed Realm');
}

return result;
}

static RealmList<T> create<T extends Object?>(RealmListHandle handle, Realm realm, RealmObjectMetadata? metadata) => RealmList<T>._(handle, realm, metadata);

Expand Down
Loading