Skip to content
This repository was archived by the owner on Nov 12, 2022. It is now read-only.

Commit c534a12

Browse files
committed
Add lifetimes for MutableHandle
1 parent b90c4ba commit c534a12

File tree

2 files changed

+106
-43
lines changed

2 files changed

+106
-43
lines changed

src/conversions.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ use jsapi::{ForOfIterator, ForOfIterator_NonIterableBehavior};
3434
use jsapi::{Heap, JS_DefineElement, JS_GetLatin1StringCharsAndLength};
3535
use jsapi::{JS_GetTwoByteStringCharsAndLength, JS_NewArrayObject1};
3636
use jsapi::{JS_NewUCStringCopyN, JSPROP_ENUMERATE, JS_StringHasLatin1Chars};
37-
use jsapi::{JSContext, JSObject, JSString, MutableHandleValue, RootedObject};
37+
use jsapi::{JSContext, JSObject, JSString, RootedObject};
3838
use jsval::{BooleanValue, Int32Value, NullValue, UInt32Value, UndefinedValue};
3939
use jsval::{JSVal, ObjectValue, ObjectOrNullValue, StringValue};
4040
use rust::{ToBoolean, ToInt32, ToInt64, ToNumber, ToUint16, ToUint32, ToUint64};
4141
use rust::{ToString, maybe_wrap_object_or_null_value, maybe_wrap_object_value};
42-
use rust::{HandleValue};
42+
use rust::{HandleValue, MutableHandleValue};
4343
use rust::maybe_wrap_value;
4444
use libc;
4545
use num_traits::{Bounded, Zero};
@@ -181,7 +181,7 @@ fn clamp_to<D>(d: f64) -> D
181181
// https://heycam.github.io/webidl/#es-void
182182
impl ToJSValConvertible for () {
183183
#[inline]
184-
unsafe fn to_jsval(&self, _cx: *mut JSContext, rval: MutableHandleValue) {
184+
unsafe fn to_jsval(&self, _cx: *mut JSContext, mut rval: MutableHandleValue) {
185185
rval.set(UndefinedValue());
186186
}
187187
}
@@ -208,23 +208,23 @@ impl FromJSValConvertible for Heap<JSVal> {
208208

209209
impl ToJSValConvertible for JSVal {
210210
#[inline]
211-
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
211+
unsafe fn to_jsval(&self, cx: *mut JSContext, mut rval: MutableHandleValue) {
212212
rval.set(*self);
213213
maybe_wrap_value(cx, rval);
214214
}
215215
}
216216

217217
impl<'a> ToJSValConvertible for HandleValue<'a> {
218218
#[inline]
219-
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
219+
unsafe fn to_jsval(&self, cx: *mut JSContext, mut rval: MutableHandleValue) {
220220
rval.set(self.get());
221221
maybe_wrap_value(cx, rval);
222222
}
223223
}
224224

225225
impl ToJSValConvertible for Heap<JSVal> {
226226
#[inline]
227-
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
227+
unsafe fn to_jsval(&self, cx: *mut JSContext, mut rval: MutableHandleValue) {
228228
rval.set(self.get());
229229
maybe_wrap_value(cx, rval);
230230
}
@@ -249,7 +249,7 @@ unsafe fn convert_int_from_jsval<T, M>(cx: *mut JSContext, value: HandleValue,
249249
// https://heycam.github.io/webidl/#es-boolean
250250
impl ToJSValConvertible for bool {
251251
#[inline]
252-
unsafe fn to_jsval(&self, _cx: *mut JSContext, rval: MutableHandleValue) {
252+
unsafe fn to_jsval(&self, _cx: *mut JSContext, mut rval: MutableHandleValue) {
253253
rval.set(BooleanValue(*self));
254254
}
255255
}
@@ -265,7 +265,7 @@ impl FromJSValConvertible for bool {
265265
// https://heycam.github.io/webidl/#es-byte
266266
impl ToJSValConvertible for i8 {
267267
#[inline]
268-
unsafe fn to_jsval(&self, _cx: *mut JSContext, rval: MutableHandleValue) {
268+
unsafe fn to_jsval(&self, _cx: *mut JSContext, mut rval: MutableHandleValue) {
269269
rval.set(Int32Value(*self as i32));
270270
}
271271
}
@@ -284,7 +284,7 @@ impl FromJSValConvertible for i8 {
284284
// https://heycam.github.io/webidl/#es-octet
285285
impl ToJSValConvertible for u8 {
286286
#[inline]
287-
unsafe fn to_jsval(&self, _cx: *mut JSContext, rval: MutableHandleValue) {
287+
unsafe fn to_jsval(&self, _cx: *mut JSContext, mut rval: MutableHandleValue) {
288288
rval.set(Int32Value(*self as i32));
289289
}
290290
}
@@ -303,7 +303,7 @@ impl FromJSValConvertible for u8 {
303303
// https://heycam.github.io/webidl/#es-short
304304
impl ToJSValConvertible for i16 {
305305
#[inline]
306-
unsafe fn to_jsval(&self, _cx: *mut JSContext, rval: MutableHandleValue) {
306+
unsafe fn to_jsval(&self, _cx: *mut JSContext, mut rval: MutableHandleValue) {
307307
rval.set(Int32Value(*self as i32));
308308
}
309309
}
@@ -322,7 +322,7 @@ impl FromJSValConvertible for i16 {
322322
// https://heycam.github.io/webidl/#es-unsigned-short
323323
impl ToJSValConvertible for u16 {
324324
#[inline]
325-
unsafe fn to_jsval(&self, _cx: *mut JSContext, rval: MutableHandleValue) {
325+
unsafe fn to_jsval(&self, _cx: *mut JSContext, mut rval: MutableHandleValue) {
326326
rval.set(Int32Value(*self as i32));
327327
}
328328
}
@@ -341,7 +341,7 @@ impl FromJSValConvertible for u16 {
341341
// https://heycam.github.io/webidl/#es-long
342342
impl ToJSValConvertible for i32 {
343343
#[inline]
344-
unsafe fn to_jsval(&self, _cx: *mut JSContext, rval: MutableHandleValue) {
344+
unsafe fn to_jsval(&self, _cx: *mut JSContext, mut rval: MutableHandleValue) {
345345
rval.set(Int32Value(*self));
346346
}
347347
}
@@ -360,7 +360,7 @@ impl FromJSValConvertible for i32 {
360360
// https://heycam.github.io/webidl/#es-unsigned-long
361361
impl ToJSValConvertible for u32 {
362362
#[inline]
363-
unsafe fn to_jsval(&self, _cx: *mut JSContext, rval: MutableHandleValue) {
363+
unsafe fn to_jsval(&self, _cx: *mut JSContext, mut rval: MutableHandleValue) {
364364
rval.set(UInt32Value(*self));
365365
}
366366
}
@@ -379,7 +379,7 @@ impl FromJSValConvertible for u32 {
379379
// https://heycam.github.io/webidl/#es-long-long
380380
impl ToJSValConvertible for i64 {
381381
#[inline]
382-
unsafe fn to_jsval(&self, _cx: *mut JSContext, rval: MutableHandleValue) {
382+
unsafe fn to_jsval(&self, _cx: *mut JSContext, mut rval: MutableHandleValue) {
383383
rval.set(RUST_JS_NumberValue(*self as f64));
384384
}
385385
}
@@ -398,7 +398,7 @@ impl FromJSValConvertible for i64 {
398398
// https://heycam.github.io/webidl/#es-unsigned-long-long
399399
impl ToJSValConvertible for u64 {
400400
#[inline]
401-
unsafe fn to_jsval(&self, _cx: *mut JSContext, rval: MutableHandleValue) {
401+
unsafe fn to_jsval(&self, _cx: *mut JSContext, mut rval: MutableHandleValue) {
402402
rval.set(RUST_JS_NumberValue(*self as f64));
403403
}
404404
}
@@ -417,7 +417,7 @@ impl FromJSValConvertible for u64 {
417417
// https://heycam.github.io/webidl/#es-float
418418
impl ToJSValConvertible for f32 {
419419
#[inline]
420-
unsafe fn to_jsval(&self, _cx: *mut JSContext, rval: MutableHandleValue) {
420+
unsafe fn to_jsval(&self, _cx: *mut JSContext, mut rval: MutableHandleValue) {
421421
rval.set(RUST_JS_NumberValue(*self as f64));
422422
}
423423
}
@@ -434,7 +434,7 @@ impl FromJSValConvertible for f32 {
434434
// https://heycam.github.io/webidl/#es-double
435435
impl ToJSValConvertible for f64 {
436436
#[inline]
437-
unsafe fn to_jsval(&self, _cx: *mut JSContext, rval: MutableHandleValue) {
437+
unsafe fn to_jsval(&self, _cx: *mut JSContext, mut rval: MutableHandleValue) {
438438
rval.set(RUST_JS_NumberValue(*self));
439439
}
440440
}
@@ -478,7 +478,7 @@ pub unsafe fn jsstr_to_string(cx: *mut JSContext, jsstr: *mut JSString) -> Strin
478478
// https://heycam.github.io/webidl/#es-USVString
479479
impl ToJSValConvertible for str {
480480
#[inline]
481-
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
481+
unsafe fn to_jsval(&self, cx: *mut JSContext, mut rval: MutableHandleValue) {
482482
let mut string_utf16: Vec<u16> = Vec::with_capacity(self.len());
483483
string_utf16.extend(self.encode_utf16());
484484
let jsstr = JS_NewUCStringCopyN(cx,
@@ -514,7 +514,7 @@ impl FromJSValConvertible for String {
514514

515515
impl<T: ToJSValConvertible> ToJSValConvertible for Option<T> {
516516
#[inline]
517-
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
517+
unsafe fn to_jsval(&self, cx: *mut JSContext, mut rval: MutableHandleValue) {
518518
match self {
519519
&Some(ref value) => value.to_jsval(cx, rval),
520520
&None => rval.set(NullValue()),
@@ -549,7 +549,7 @@ impl<T: FromJSValConvertible> FromJSValConvertible for Option<T> {
549549
// https://heycam.github.io/webidl/#es-sequence
550550
impl<T: ToJSValConvertible> ToJSValConvertible for Vec<T> {
551551
#[inline]
552-
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
552+
unsafe fn to_jsval(&self, cx: *mut JSContext, mut rval: MutableHandleValue) {
553553
rooted!(in(cx) let js_array = JS_NewArrayObject1(cx, self.len() as libc::size_t));
554554
assert!(!js_array.handle().is_null());
555555

@@ -620,7 +620,7 @@ impl<C: Clone, T: FromJSValConvertible<Config=C>> FromJSValConvertible for Vec<T
620620
loop {
621621
let mut done = false;
622622
rooted!(in(cx) let mut val = UndefinedValue());
623-
if !iterator.next(val.handle_mut(), &mut done) {
623+
if !iterator.next(val.handle_mut().into(), &mut done) {
624624
return Err(())
625625
}
626626

@@ -641,7 +641,7 @@ impl<C: Clone, T: FromJSValConvertible<Config=C>> FromJSValConvertible for Vec<T
641641
// https://heycam.github.io/webidl/#es-object
642642
impl ToJSValConvertible for *mut JSObject {
643643
#[inline]
644-
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
644+
unsafe fn to_jsval(&self, cx: *mut JSContext, mut rval: MutableHandleValue) {
645645
rval.set(ObjectOrNullValue(*self));
646646
maybe_wrap_object_or_null_value(cx, rval);
647647
}
@@ -650,7 +650,7 @@ impl ToJSValConvertible for *mut JSObject {
650650
// https://heycam.github.io/webidl/#es-object
651651
impl ToJSValConvertible for ptr::NonNull<JSObject> {
652652
#[inline]
653-
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
653+
unsafe fn to_jsval(&self, cx: *mut JSContext, mut rval: MutableHandleValue) {
654654
rval.set(ObjectValue(self.as_ptr()));
655655
maybe_wrap_object_value(cx, rval);
656656
}
@@ -659,7 +659,7 @@ impl ToJSValConvertible for ptr::NonNull<JSObject> {
659659
// https://heycam.github.io/webidl/#es-object
660660
impl ToJSValConvertible for Heap<*mut JSObject> {
661661
#[inline]
662-
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
662+
unsafe fn to_jsval(&self, cx: *mut JSContext, mut rval: MutableHandleValue) {
663663
rval.set(ObjectOrNullValue(self.get()));
664664
maybe_wrap_object_or_null_value(cx, rval);
665665
}

0 commit comments

Comments
 (0)