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

Commit 701d809

Browse files
committed
Implement conversion traits for Heap.
1 parent 8ac0712 commit 701d809

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/conversions.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use core::nonzero::NonZero;
3131
use error::throw_type_error;
3232
use glue::RUST_JS_NumberValue;
3333
use jsapi::{ForOfIterator, ForOfIterator_NonIterableBehavior, HandleValue};
34-
use jsapi::{JS_DefineElement, JS_GetLatin1StringCharsAndLength};
34+
use jsapi::{Heap, JS_DefineElement, JS_GetLatin1StringCharsAndLength};
3535
use jsapi::{JS_GetTwoByteStringCharsAndLength, JS_NewArrayObject1};
3636
use jsapi::{JS_NewUCStringCopyN, JSPROP_ENUMERATE, JS_StringHasLatin1Chars};
3737
use jsapi::{JSContext, JSObject, JSString, MutableHandleValue, RootedObject};
@@ -194,6 +194,16 @@ impl FromJSValConvertible for JSVal {
194194
}
195195
}
196196

197+
impl FromJSValConvertible for Heap<JSVal> {
198+
type Config = ();
199+
unsafe fn from_jsval(_cx: *mut JSContext,
200+
value: HandleValue,
201+
_option: ())
202+
-> Result<ConversionResult<Self>, ()> {
203+
Ok(ConversionResult::Success(Heap::new(value.get())))
204+
}
205+
}
206+
197207
impl ToJSValConvertible for JSVal {
198208
#[inline]
199209
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
@@ -210,6 +220,14 @@ impl ToJSValConvertible for HandleValue {
210220
}
211221
}
212222

223+
impl ToJSValConvertible for Heap<JSVal> {
224+
#[inline]
225+
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
226+
rval.set(self.get());
227+
maybe_wrap_value(cx, rval);
228+
}
229+
}
230+
213231
#[inline]
214232
unsafe fn convert_int_from_jsval<T, M>(cx: *mut JSContext, value: HandleValue,
215233
option: ConversionBehavior,
@@ -630,3 +648,12 @@ impl ToJSValConvertible for NonZero<*mut JSObject> {
630648
maybe_wrap_object_value(cx, rval);
631649
}
632650
}
651+
652+
// https://heycam.github.io/webidl/#es-object
653+
impl ToJSValConvertible for Heap<*mut JSObject> {
654+
#[inline]
655+
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
656+
rval.set(ObjectOrNullValue(self.get()));
657+
maybe_wrap_object_or_null_value(cx, rval);
658+
}
659+
}

0 commit comments

Comments
 (0)