Add JNI wrappers for casting and locking

RESOLVED FIXED in Firefox 55

Status

()

RESOLVED FIXED
2 years ago
2 years ago

People

(Reporter: jchen, Assigned: jchen)

Tracking

unspecified
mozilla55
All
Android
Points:
---

Firefox Tracking Flags

(firefox55 fixed)

Details

Attachments

(2 attachments)

(Assignee)

Description

2 years ago
Add wrappers for casting one type to another type, and for locking an object.
(Assignee)

Comment 1

2 years ago
Created attachment 8842204 [details] [diff] [review]
1. Add jni::Ref::Cast function (v1)

Add a Cast function to jni::Ref to cast a reference to a different type
(e.g. if ref is a jni::Object::Ref referring to a String instance, use |
ref.Cast<jni::String>()->Length() | to get the length of the string).

In MOZ_CHECK_JNI builds, Cast() checks that an instance of the source
class can indeed be cast to the target class.
Attachment #8842204 - Flags: review?(snorp)
(Assignee)

Comment 2

2 years ago
Created attachment 8842205 [details] [diff] [review]
2. Add jni::Ref::Lock function (v1)

Add a Lock function to jni::Ref to lock the referenced object akin to
the synchronized keyword in Java. It returns a Locked RAII object that
automatically unlocks the object when going out of scope.
Attachment #8842205 - Flags: review?(snorp)
Comment on attachment 8842204 [details] [diff] [review]
1. Add jni::Ref::Cast function (v1)

Review of attachment 8842204 [details] [diff] [review]:
-----------------------------------------------------------------

This is super nice.
Attachment #8842204 - Flags: review?(snorp) → review+
Comment on attachment 8842205 [details] [diff] [review]
2. Add jni::Ref::Lock function (v1)

Review of attachment 8842205 [details] [diff] [review]:
-----------------------------------------------------------------

::: widget/android/jni/Refs.h
@@ +78,5 @@
>  
>  public:
>      using JNIType = Type;
>  
> +    class Locked

AutoLock? AutoMonitor? AutoMutex? It should have Auto in it.
Attachment #8842205 - Flags: review?(snorp) → review+

Comment 5

2 years ago
Pushed by nchen@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/a97e11f9a6e2
1. Add jni::Ref::Cast function; r=snorp
https://hg.mozilla.org/integration/mozilla-inbound/rev/1af35d88e88b
2. Add jni::Ref::Lock function; r=snorp

Comment 6

2 years ago
bugherder
https://hg.mozilla.org/mozilla-central/rev/a97e11f9a6e2
https://hg.mozilla.org/mozilla-central/rev/1af35d88e88b
Status: ASSIGNED → RESOLVED
Last Resolved: 2 years ago
status-firefox55: --- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
You need to log in before you can comment on or make changes to this bug.