@@ -89,39 +89,44 @@ impl private::Sealed for JsBuffer {}
8989impl TypedArray for JsBuffer {
9090 type Item = u8 ;
9191
92- fn as_slice < ' a : ' b , ' b , C > ( & ' b self , cx : & ' b C ) -> & ' b [ Self :: Item ]
92+ fn as_slice < ' cx , ' a , C > ( & self , cx : & ' a C ) -> & ' a [ Self :: Item ]
9393 where
94- C : Context < ' a > ,
94+ C : Context < ' cx > ,
9595 {
96+ // # Safety
97+ // Only the `Context` with the *most* narrow scope is accessible because `compute_scoped`
98+ // and `execute_scope` take an exclusive reference to `Context`. A handle is always
99+ // associated with a `Context` and the value will not be garbage collected while that
100+ // `Context` is in scope. This means that the referenced data is valid *at least* as long
101+ // as `Context`, even if the `Handle` is dropped.
96102 unsafe { neon_runtime:: buffer:: as_mut_slice ( cx. env ( ) . to_raw ( ) , self . to_raw ( ) ) }
97103 }
98104
99- fn as_mut_slice < ' a : ' b , ' b , C > ( & ' b mut self , cx : & ' b mut C ) -> & ' b mut [ Self :: Item ]
105+ fn as_mut_slice < ' cx , ' a , C > ( & mut self , cx : & ' a mut C ) -> & ' a mut [ Self :: Item ]
100106 where
101- C : Context < ' a > ,
107+ C : Context < ' cx > ,
102108 {
109+ // # Safety
110+ // See `as_slice`
103111 unsafe { neon_runtime:: buffer:: as_mut_slice ( cx. env ( ) . to_raw ( ) , self . to_raw ( ) ) }
104112 }
105113
106- fn try_borrow < ' a : ' b , ' b , C > (
107- & self ,
108- lock : & ' b Lock < ' b , C > ,
109- ) -> Result < Ref < ' b , Self :: Item > , BorrowError >
114+ fn try_borrow < ' cx , ' a , C > ( & self , lock : & ' a Lock < C > ) -> Result < Ref < ' a , Self :: Item > , BorrowError >
110115 where
111- C : Context < ' a > ,
116+ C : Context < ' cx > ,
112117 {
113118 // The borrowed data must be guarded by `Ledger` before returning
114119 Ledger :: try_borrow ( & lock. ledger , unsafe {
115120 neon_runtime:: buffer:: as_mut_slice ( lock. cx . env ( ) . to_raw ( ) , self . to_raw ( ) )
116121 } )
117122 }
118123
119- fn try_borrow_mut < ' a : ' b , ' b , C > (
124+ fn try_borrow_mut < ' cx , ' a , C > (
120125 & mut self ,
121- lock : & ' b Lock < ' b , C > ,
122- ) -> Result < RefMut < ' b , Self :: Item > , BorrowError >
126+ lock : & ' a Lock < C > ,
127+ ) -> Result < RefMut < ' a , Self :: Item > , BorrowError >
123128 where
124- C : Context < ' a > ,
129+ C : Context < ' cx > ,
125130 {
126131 // The borrowed data must be guarded by `Ledger` before returning
127132 Ledger :: try_borrow_mut ( & lock. ledger , unsafe {
@@ -197,39 +202,36 @@ impl private::Sealed for JsArrayBuffer {}
197202impl TypedArray for JsArrayBuffer {
198203 type Item = u8 ;
199204
200- fn as_slice < ' a : ' b , ' b , C > ( & ' b self , cx : & ' b C ) -> & ' b [ Self :: Item ]
205+ fn as_slice < ' cx , ' a , C > ( & self , cx : & ' a C ) -> & ' a [ Self :: Item ]
201206 where
202- C : Context < ' a > ,
207+ C : Context < ' cx > ,
203208 {
204209 unsafe { neon_runtime:: arraybuffer:: as_mut_slice ( cx. env ( ) . to_raw ( ) , self . to_raw ( ) ) }
205210 }
206211
207- fn as_mut_slice < ' a : ' b , ' b , C > ( & ' b mut self , cx : & ' b mut C ) -> & ' b mut [ Self :: Item ]
212+ fn as_mut_slice < ' cx , ' a , C > ( & mut self , cx : & ' a mut C ) -> & ' a mut [ Self :: Item ]
208213 where
209- C : Context < ' a > ,
214+ C : Context < ' cx > ,
210215 {
211216 unsafe { neon_runtime:: arraybuffer:: as_mut_slice ( cx. env ( ) . to_raw ( ) , self . to_raw ( ) ) }
212217 }
213218
214- fn try_borrow < ' a : ' b , ' b , C > (
215- & self ,
216- lock : & ' b Lock < ' b , C > ,
217- ) -> Result < Ref < ' b , Self :: Item > , BorrowError >
219+ fn try_borrow < ' cx , ' a , C > ( & self , lock : & ' a Lock < C > ) -> Result < Ref < ' a , Self :: Item > , BorrowError >
218220 where
219- C : Context < ' a > ,
221+ C : Context < ' cx > ,
220222 {
221223 // The borrowed data must be guarded by `Ledger` before returning
222224 Ledger :: try_borrow ( & lock. ledger , unsafe {
223225 neon_runtime:: arraybuffer:: as_mut_slice ( lock. cx . env ( ) . to_raw ( ) , self . to_raw ( ) )
224226 } )
225227 }
226228
227- fn try_borrow_mut < ' a : ' b , ' b , C > (
229+ fn try_borrow_mut < ' cx , ' a , C > (
228230 & mut self ,
229- lock : & ' b Lock < ' b , C > ,
230- ) -> Result < RefMut < ' b , Self :: Item > , BorrowError >
231+ lock : & ' a Lock < C > ,
232+ ) -> Result < RefMut < ' a , Self :: Item > , BorrowError >
231233 where
232- C : Context < ' a > ,
234+ C : Context < ' cx > ,
233235 {
234236 // The borrowed data must be guarded by `Ledger` before returning
235237 Ledger :: try_borrow_mut ( & lock. ledger , unsafe {
@@ -272,9 +274,9 @@ impl<T> Managed for JsTypedArray<T> {
272274impl < T : Copy > TypedArray for JsTypedArray < T > {
273275 type Item = T ;
274276
275- fn as_slice < ' a : ' b , ' b , C > ( & ' b self , cx : & ' b C ) -> & ' b [ Self :: Item ]
277+ fn as_slice < ' cx , ' a , C > ( & self , cx : & ' a C ) -> & ' a [ Self :: Item ]
276278 where
277- C : Context < ' a > ,
279+ C : Context < ' cx > ,
278280 {
279281 unsafe {
280282 let env = cx. env ( ) . to_raw ( ) ;
@@ -285,9 +287,9 @@ impl<T: Copy> TypedArray for JsTypedArray<T> {
285287 }
286288 }
287289
288- fn as_mut_slice < ' a : ' b , ' b , C > ( & ' b mut self , cx : & ' b mut C ) -> & ' b mut [ Self :: Item ]
290+ fn as_mut_slice < ' cx , ' a , C > ( & mut self , cx : & ' a mut C ) -> & ' a mut [ Self :: Item ]
289291 where
290- C : Context < ' a > ,
292+ C : Context < ' cx > ,
291293 {
292294 unsafe {
293295 let env = cx. env ( ) . to_raw ( ) ;
@@ -298,12 +300,12 @@ impl<T: Copy> TypedArray for JsTypedArray<T> {
298300 }
299301 }
300302
301- fn try_borrow < ' a : ' b , ' b , C > (
303+ fn try_borrow < ' cx , ' b , C > (
302304 & self ,
303305 lock : & ' b Lock < ' b , C > ,
304306 ) -> Result < Ref < ' b , Self :: Item > , BorrowError >
305307 where
306- C : Context < ' a > ,
308+ C : Context < ' cx > ,
307309 {
308310 unsafe {
309311 let env = lock. cx . env ( ) . to_raw ( ) ;
@@ -318,12 +320,12 @@ impl<T: Copy> TypedArray for JsTypedArray<T> {
318320 }
319321 }
320322
321- fn try_borrow_mut < ' a : ' b , ' b , C > (
323+ fn try_borrow_mut < ' cx , ' a , C > (
322324 & mut self ,
323- lock : & ' b Lock < ' b , C > ,
324- ) -> Result < RefMut < ' b , Self :: Item > , BorrowError >
325+ lock : & ' a Lock < ' a , C > ,
326+ ) -> Result < RefMut < ' a , Self :: Item > , BorrowError >
325327 where
326- C : Context < ' a > ,
328+ C : Context < ' cx > ,
327329 {
328330 unsafe {
329331 let env = lock. cx . env ( ) . to_raw ( ) ;
0 commit comments