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

Commit 7c9ea6d

Browse files
committed
Implement FromJSValConvertible for HandleValue
1 parent 7f380ab commit 7c9ea6d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/conversions.rs

+17
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use core::nonzero::NonZero;
3131
use error::throw_type_error;
3232
use glue::RUST_JS_NumberValue;
33+
use jsapi::AssertSameCompartment;
3334
use jsapi::{ForOfIterator, ForOfIterator_NonIterableBehavior, HandleValue};
3435
use jsapi::{Heap, JS_DefineElement, JS_GetLatin1StringCharsAndLength};
3536
use jsapi::{JS_GetTwoByteStringCharsAndLength, JS_NewArrayObject1};
@@ -184,6 +185,22 @@ impl ToJSValConvertible for () {
184185
}
185186
}
186187

188+
impl FromJSValConvertible for HandleValue {
189+
type Config = ();
190+
#[inline]
191+
unsafe fn from_jsval(cx: *mut JSContext,
192+
value: HandleValue,
193+
_option: ())
194+
-> Result<ConversionResult<HandleValue>, ()> {
195+
unsafe {
196+
if value.is_object() {
197+
AssertSameCompartment(cx, value.to_object());
198+
}
199+
}
200+
Ok(ConversionResult::Success(value))
201+
}
202+
}
203+
187204
impl FromJSValConvertible for JSVal {
188205
type Config = ();
189206
unsafe fn from_jsval(_cx: *mut JSContext,

0 commit comments

Comments
 (0)