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

Commit 365143f

Browse files
committed
Added Support for Symbols
1 parent 992ad49 commit 365143f

File tree

3 files changed

+28
-197
lines changed

3 files changed

+28
-197
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ lazy_static = "1"
6060
libc = "0.2"
6161
log = "0.4"
6262
num-traits = "0.2"
63-
mozjs_sys = { git = "https://github.com/servo/mozjs", rev="062d3dc473b66e2c4053b690ce1df45083351519" }
63+
mozjs_sys = { git = "https://github.com/Redfire75369/mozjs", rev="05579b56fb4c7911271f3ca1688033b21b022918" }

src/conversions.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
//! | double | `Finite<f64>` |
2323
//! | USVString | `String` |
2424
//! | object | `*mut JSObject` |
25+
//! | symbol | `*mut Symbol` |
2526
//! | nullable types | `Option<T>` |
2627
//! | sequences | `Vec<T>` |
2728
@@ -30,13 +31,14 @@
3031
use error::throw_type_error;
3132
use glue::RUST_JS_NumberValue;
3233
use jsapi::AssertSameCompartment;
34+
use jsapi::JS;
3335
use jsapi::{ForOfIterator, ForOfIterator_NonIterableBehavior};
3436
use jsapi::{Heap, JS_DefineElement, JS_GetLatin1StringCharsAndLength};
3537
use jsapi::{JSContext, JSObject, JSString, RootedObject, RootedValue};
3638
use jsapi::{JS_DeprecatedStringHasLatin1Chars, JS_NewUCStringCopyN, JSPROP_ENUMERATE};
3739
use jsapi::{JS_GetTwoByteStringCharsAndLength, NewArrayObject1};
3840
use jsval::{BooleanValue, Int32Value, NullValue, UInt32Value, UndefinedValue};
39-
use jsval::{JSVal, ObjectOrNullValue, ObjectValue, StringValue};
41+
use jsval::{JSVal, ObjectOrNullValue, ObjectValue, StringValue, SymbolValue};
4042
use libc;
4143
use num_traits::{Bounded, Zero};
4244
use rust::maybe_wrap_value;
@@ -752,3 +754,27 @@ impl FromJSValConvertible for *mut JSObject {
752754
Ok(ConversionResult::Success(value.to_object()))
753755
}
754756
}
757+
758+
impl ToJSValConvertible for *mut JS::Symbol {
759+
#[inline]
760+
unsafe fn to_jsval(&self, _: *mut JSContext, mut rval: MutableHandleValue) {
761+
rval.set(SymbolValue(&**self));
762+
}
763+
}
764+
765+
impl FromJSValConvertible for *mut JS::Symbol {
766+
type Config = ();
767+
#[inline]
768+
unsafe fn from_jsval(
769+
cx: *mut JSContext,
770+
value: HandleValue,
771+
_option: (),
772+
) -> Result<ConversionResult<*mut JS::Symbol>, ()> {
773+
if !value.is_symbol() {
774+
throw_type_error(cx, "value is not a symbol");
775+
return Err(());
776+
}
777+
778+
Ok(ConversionResult::Success(value.to_symbol()))
779+
}
780+
}

src/jsval.rs

Lines changed: 0 additions & 195 deletions
This file was deleted.

0 commit comments

Comments
 (0)