Merge pull request #1444 from alexcrichton/partial-eq

Add PartialEq/Eq to many `js-sys` types
This commit is contained in:
Alex Crichton 2019-04-12 11:03:05 -05:00 committed by GitHub
commit 4211fcd992
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 71 additions and 62 deletions

View File

@ -578,6 +578,16 @@ impl ToTokens for ast::ImportType {
let const_name = format!("__wbg_generated_const_{}", rust_name); let const_name = format!("__wbg_generated_const_{}", rust_name);
let const_name = Ident::new(&const_name, Span::call_site()); let const_name = Ident::new(&const_name, Span::call_site());
let instanceof_shim = Ident::new(&self.instanceof_shim, Span::call_site()); let instanceof_shim = Ident::new(&self.instanceof_shim, Span::call_site());
let internal_obj = match self.extends.first() {
Some(target) => {
quote! { #target }
}
None => {
quote! { wasm_bindgen::JsValue }
}
};
(quote! { (quote! {
#[allow(bad_style)] #[allow(bad_style)]
#(#attrs)* #(#attrs)*
@ -585,7 +595,7 @@ impl ToTokens for ast::ImportType {
#[repr(transparent)] #[repr(transparent)]
#[allow(clippy::all)] #[allow(clippy::all)]
#vis struct #rust_name { #vis struct #rust_name {
obj: wasm_bindgen::JsValue, obj: #internal_obj
} }
#[allow(bad_style)] #[allow(bad_style)]
@ -604,6 +614,15 @@ impl ToTokens for ast::ImportType {
} }
} }
impl core::ops::Deref for #rust_name {
type Target = #internal_obj;
#[inline]
fn deref(&self) -> &#internal_obj {
&self.obj
}
}
impl IntoWasmAbi for #rust_name { impl IntoWasmAbi for #rust_name {
type Abi = <JsValue as IntoWasmAbi>::Abi; type Abi = <JsValue as IntoWasmAbi>::Abi;
@ -629,7 +648,7 @@ impl ToTokens for ast::ImportType {
#[inline] #[inline]
unsafe fn from_abi(js: Self::Abi, extra: &mut Stack) -> Self { unsafe fn from_abi(js: Self::Abi, extra: &mut Stack) -> Self {
#rust_name { #rust_name {
obj: JsValue::from_abi(js, extra), obj: JsValue::from_abi(js, extra).into(),
} }
} }
} }
@ -656,7 +675,7 @@ impl ToTokens for ast::ImportType {
unsafe fn ref_from_abi(js: Self::Abi, extra: &mut Stack) -> Self::Anchor { unsafe fn ref_from_abi(js: Self::Abi, extra: &mut Stack) -> Self::Anchor {
let tmp = <JsValue as RefFromWasmAbi>::ref_from_abi(js, extra); let tmp = <JsValue as RefFromWasmAbi>::ref_from_abi(js, extra);
core::mem::ManuallyDrop::new(#rust_name { core::mem::ManuallyDrop::new(#rust_name {
obj: core::mem::ManuallyDrop::into_inner(tmp), obj: core::mem::ManuallyDrop::into_inner(tmp).into(),
}) })
} }
} }
@ -665,20 +684,20 @@ impl ToTokens for ast::ImportType {
impl From<JsValue> for #rust_name { impl From<JsValue> for #rust_name {
#[inline] #[inline]
fn from(obj: JsValue) -> #rust_name { fn from(obj: JsValue) -> #rust_name {
#rust_name { obj } #rust_name { obj: obj.into() }
} }
} }
impl AsRef<JsValue> for #rust_name { impl AsRef<JsValue> for #rust_name {
#[inline] #[inline]
fn as_ref(&self) -> &JsValue { &self.obj } fn as_ref(&self) -> &JsValue { self.obj.as_ref() }
} }
impl From<#rust_name> for JsValue { impl From<#rust_name> for JsValue {
#[inline] #[inline]
fn from(obj: #rust_name) -> JsValue { fn from(obj: #rust_name) -> JsValue {
obj.obj obj.obj.into()
} }
} }
@ -703,7 +722,7 @@ impl ToTokens for ast::ImportType {
#[inline] #[inline]
fn unchecked_from_js(val: JsValue) -> Self { fn unchecked_from_js(val: JsValue) -> Self {
#rust_name { obj: val } #rust_name { obj: val.into() }
} }
#[inline] #[inline]
@ -719,22 +738,6 @@ impl ToTokens for ast::ImportType {
}) })
.to_tokens(tokens); .to_tokens(tokens);
let deref_target = match self.extends.first() {
Some(target) => quote! { #target },
None => quote! { JsValue },
};
(quote! {
#[allow(clippy::all)]
impl core::ops::Deref for #rust_name {
type Target = #deref_target;
#[inline]
fn deref(&self) -> &#deref_target {
self.as_ref()
}
}
})
.to_tokens(tokens);
for superclass in self.extends.iter() { for superclass in self.extends.iter() {
(quote! { (quote! {
#[allow(clippy::all)] #[allow(clippy::all)]

View File

@ -127,7 +127,7 @@ extern "C" {
#[wasm_bindgen] #[wasm_bindgen]
extern "C" { extern "C" {
#[wasm_bindgen(extends = Object)] #[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type Array; pub type Array;
/// Creates a new empty array /// Creates a new empty array
@ -392,7 +392,7 @@ extern "C" {
#[wasm_bindgen] #[wasm_bindgen]
extern "C" { extern "C" {
#[wasm_bindgen(extends = Object)] #[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type ArrayBuffer; pub type ArrayBuffer;
/// The `ArrayBuffer` object is used to represent a generic, /// The `ArrayBuffer` object is used to represent a generic,
@ -467,7 +467,7 @@ extern "C" {
#[wasm_bindgen] #[wasm_bindgen]
extern "C" { extern "C" {
#[wasm_bindgen(extends = Object)] #[wasm_bindgen(extends = Object)]
#[derive(Clone, PartialEq)] #[derive(Clone, PartialEq, Eq)]
pub type Boolean; pub type Boolean;
/// The `Boolean()` constructor creates an object wrapper for a boolean value. /// The `Boolean()` constructor creates an object wrapper for a boolean value.
@ -505,8 +505,6 @@ impl PartialEq<bool> for Boolean {
} }
} }
impl Eq for Boolean {}
impl fmt::Debug for Boolean { impl fmt::Debug for Boolean {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.value_of().fmt(f) self.value_of().fmt(f)
@ -517,7 +515,7 @@ impl fmt::Debug for Boolean {
#[wasm_bindgen] #[wasm_bindgen]
extern "C" { extern "C" {
#[wasm_bindgen(extends = Object)] #[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type DataView; pub type DataView;
/// The `DataView` view provides a low-level interface for reading and /// The `DataView` view provides a low-level interface for reading and
@ -749,7 +747,7 @@ extern "C" {
#[wasm_bindgen] #[wasm_bindgen]
extern "C" { extern "C" {
#[wasm_bindgen(extends = Object)] #[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type Error; pub type Error;
/// The Error constructor creates an error object. /// The Error constructor creates an error object.
@ -788,7 +786,7 @@ extern "C" {
#[wasm_bindgen] #[wasm_bindgen]
extern "C" { extern "C" {
#[wasm_bindgen(extends = Object, extends = Error)] #[wasm_bindgen(extends = Object, extends = Error)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type EvalError; pub type EvalError;
/// The EvalError object indicates an error regarding the global eval() function. This /// The EvalError object indicates an error regarding the global eval() function. This
@ -804,7 +802,7 @@ extern "C" {
#[wasm_bindgen] #[wasm_bindgen]
extern "C" { extern "C" {
#[wasm_bindgen(extends = Object)] #[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type Function; pub type Function;
/// The `Function` constructor creates a new `Function` object. Calling the /// The `Function` constructor creates a new `Function` object. Calling the
@ -900,7 +898,7 @@ impl Function {
/// `None`. /// `None`.
pub fn try_from(val: &JsValue) -> Option<&Function> { pub fn try_from(val: &JsValue) -> Option<&Function> {
if val.is_function() { if val.is_function() {
Some(unsafe { mem::transmute(val) }) Some(val.unchecked_ref())
} else { } else {
None None
} }
@ -911,7 +909,7 @@ impl Function {
#[wasm_bindgen] #[wasm_bindgen]
extern "C" { extern "C" {
#[wasm_bindgen(extends = Object)] #[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type Generator; pub type Generator;
/// The next() method returns an object with two properties done and value. /// The next() method returns an object with two properties done and value.
@ -939,7 +937,7 @@ extern "C" {
#[wasm_bindgen] #[wasm_bindgen]
extern "C" { extern "C" {
#[wasm_bindgen(extends = Object)] #[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type Map; pub type Map;
/// The clear() method removes all elements from a Map object. /// The clear() method removes all elements from a Map object.
@ -1165,7 +1163,8 @@ extern "C" {
/// The result of calling `next()` on a JS iterator. /// The result of calling `next()` on a JS iterator.
/// ///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols)
#[derive(Clone, Debug)] #[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub type IteratorNext; pub type IteratorNext;
/// Has the value `true` if the iterator is past the end of the iterated /// Has the value `true` if the iterator is past the end of the iterated
@ -1187,8 +1186,8 @@ extern "C" {
// Math // Math
#[wasm_bindgen] #[wasm_bindgen]
extern "C" { extern "C" {
#[derive(Clone, Debug)]
#[wasm_bindgen(extends = Object)] #[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub type Math; pub type Math;
/// The Math.abs() function returns the absolute value of a number, that is /// The Math.abs() function returns the absolute value of a number, that is
@ -1567,7 +1566,7 @@ impl fmt::Debug for Number {
#[wasm_bindgen] #[wasm_bindgen]
extern "C" { extern "C" {
#[wasm_bindgen(extends = Object)] #[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type Date; pub type Date;
/// The getDate() method returns the day of the month for the /// The getDate() method returns the day of the month for the
@ -2154,13 +2153,22 @@ impl Object {
/// `None`. /// `None`.
pub fn try_from(val: &JsValue) -> Option<&Object> { pub fn try_from(val: &JsValue) -> Option<&Object> {
if val.is_object() { if val.is_object() {
Some(unsafe { mem::transmute(val) }) Some(val.unchecked_ref())
} else { } else {
None None
} }
} }
} }
impl PartialEq for Object {
#[inline]
fn eq(&self, other: &Object) -> bool {
Object::is(self.as_ref(), other.as_ref())
}
}
impl Eq for Object {}
// Proxy // Proxy
#[wasm_bindgen] #[wasm_bindgen]
extern "C" { extern "C" {
@ -2191,7 +2199,7 @@ extern "C" {
/// ///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError) /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
#[wasm_bindgen(extends = Error, extends = Object)] #[wasm_bindgen(extends = Error, extends = Object)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type RangeError; pub type RangeError;
/// The RangeError object indicates an error when a value is not in the set /// The RangeError object indicates an error when a value is not in the set
@ -2210,7 +2218,7 @@ extern "C" {
/// ///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError) /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
#[wasm_bindgen(extends = Error, extends = Object)] #[wasm_bindgen(extends = Error, extends = Object)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type ReferenceError; pub type ReferenceError;
/// The ReferenceError object represents an error when a non-existent /// The ReferenceError object represents an error when a non-existent
@ -2224,8 +2232,8 @@ extern "C" {
// Reflect // Reflect
#[wasm_bindgen] #[wasm_bindgen]
extern "C" { extern "C" {
#[derive(Clone, Debug)]
#[wasm_bindgen(extends = Object)] #[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub type Reflect; pub type Reflect;
/// The static `Reflect.apply()` method calls a target function with /// The static `Reflect.apply()` method calls a target function with
@ -2384,7 +2392,7 @@ extern "C" {
#[wasm_bindgen] #[wasm_bindgen]
extern "C" { extern "C" {
#[wasm_bindgen(extends = Object)] #[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type RegExp; pub type RegExp;
/// The exec() method executes a search for a match in a specified /// The exec() method executes a search for a match in a specified
@ -2561,7 +2569,7 @@ extern "C" {
#[wasm_bindgen] #[wasm_bindgen]
extern "C" { extern "C" {
#[wasm_bindgen(extends = Object)] #[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type Set; pub type Set;
/// The `add()` method appends a new element with a specified value to the /// The `add()` method appends a new element with a specified value to the
@ -2651,7 +2659,7 @@ extern "C" {
/// ///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError) /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
#[wasm_bindgen(extends = Error, extends = Object)] #[wasm_bindgen(extends = Error, extends = Object)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type SyntaxError; pub type SyntaxError;
/// A SyntaxError is thrown when the JavaScript engine encounters tokens or /// A SyntaxError is thrown when the JavaScript engine encounters tokens or
@ -2671,7 +2679,7 @@ extern "C" {
/// ///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)
#[wasm_bindgen(extends = Error, extends = Object)] #[wasm_bindgen(extends = Error, extends = Object)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type TypeError; pub type TypeError;
/// The TypeError object represents an error when a value is not of the /// The TypeError object represents an error when a value is not of the
@ -2690,7 +2698,7 @@ extern "C" {
/// ///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError) /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError)
#[wasm_bindgen(extends = Error, extends = Object, js_name = URIError)] #[wasm_bindgen(extends = Error, extends = Object, js_name = URIError)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type UriError; pub type UriError;
/// The URIError object represents an error when a global URI handling /// The URIError object represents an error when a global URI handling
@ -2705,7 +2713,7 @@ extern "C" {
#[wasm_bindgen] #[wasm_bindgen]
extern "C" { extern "C" {
#[wasm_bindgen(extends = Object)] #[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type WeakMap; pub type WeakMap;
/// The [`WeakMap`] object is a collection of key/value pairs in which the /// The [`WeakMap`] object is a collection of key/value pairs in which the
@ -2749,7 +2757,7 @@ extern "C" {
#[wasm_bindgen] #[wasm_bindgen]
extern "C" { extern "C" {
#[wasm_bindgen(extends = Object)] #[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type WeakSet; pub type WeakSet;
/// The `WeakSet` object lets you store weakly held objects in a collection. /// The `WeakSet` object lets you store weakly held objects in a collection.
@ -2836,7 +2844,7 @@ pub mod WebAssembly {
/// ///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError) /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError)
#[wasm_bindgen(extends = Error, js_namespace = WebAssembly)] #[wasm_bindgen(extends = Error, js_namespace = WebAssembly)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type CompileError; pub type CompileError;
/// The `WebAssembly.CompileError()` constructor creates a new /// The `WebAssembly.CompileError()` constructor creates a new
@ -2858,7 +2866,7 @@ pub mod WebAssembly {
/// ///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance) /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
#[wasm_bindgen(extends = Object, js_namespace = WebAssembly)] #[wasm_bindgen(extends = Object, js_namespace = WebAssembly)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type Instance; pub type Instance;
/// The `WebAssembly.Instance()` constructor function can be called to /// The `WebAssembly.Instance()` constructor function can be called to
@ -2889,7 +2897,7 @@ pub mod WebAssembly {
/// ///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError) /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError)
#[wasm_bindgen(extends = Error, js_namespace = WebAssembly)] #[wasm_bindgen(extends = Error, js_namespace = WebAssembly)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type LinkError; pub type LinkError;
/// The `WebAssembly.LinkError()` constructor creates a new WebAssembly /// The `WebAssembly.LinkError()` constructor creates a new WebAssembly
@ -2910,7 +2918,7 @@ pub mod WebAssembly {
/// ///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError) /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError)
#[wasm_bindgen(extends = Error, js_namespace = WebAssembly)] #[wasm_bindgen(extends = Error, js_namespace = WebAssembly)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type RuntimeError; pub type RuntimeError;
/// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly /// The `WebAssembly.RuntimeError()` constructor creates a new WebAssembly
@ -2931,7 +2939,7 @@ pub mod WebAssembly {
/// ///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module) /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module)
#[wasm_bindgen(js_namespace = WebAssembly, extends = Object)] #[wasm_bindgen(js_namespace = WebAssembly, extends = Object)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type Module; pub type Module;
/// A `WebAssembly.Module` object contains stateless WebAssembly code /// A `WebAssembly.Module` object contains stateless WebAssembly code
@ -2973,7 +2981,7 @@ pub mod WebAssembly {
/// ///
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table) /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table)
#[wasm_bindgen(js_namespace = WebAssembly, extends = Object)] #[wasm_bindgen(js_namespace = WebAssembly, extends = Object)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type Table; pub type Table;
/// The `WebAssembly.Table()` constructor creates a new `Table` object /// The `WebAssembly.Table()` constructor creates a new `Table` object
@ -3019,7 +3027,7 @@ pub mod WebAssembly {
extern "C" { extern "C" {
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory) /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory)
#[wasm_bindgen(js_namespace = WebAssembly, extends = Object)] #[wasm_bindgen(js_namespace = WebAssembly, extends = Object)]
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq, Eq)]
pub type Memory; pub type Memory;
/// The `WebAssembly.Memory()` constructor creates a new `Memory` object /// The `WebAssembly.Memory()` constructor creates a new `Memory` object
@ -3060,8 +3068,8 @@ extern "C" {
/// Notation (JSON)](https://json.org/) and converting values to JSON. It /// Notation (JSON)](https://json.org/) and converting values to JSON. It
/// can't be called or constructed, and aside from its two method /// can't be called or constructed, and aside from its two method
/// properties, it has no interesting functionality of its own. /// properties, it has no interesting functionality of its own.
#[derive(Clone, Debug)]
#[wasm_bindgen(extends = Object)] #[wasm_bindgen(extends = Object)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub type JSON; pub type JSON;
/// The `JSON.parse()` method parses a JSON string, constructing the /// The `JSON.parse()` method parses a JSON string, constructing the
@ -3120,7 +3128,7 @@ extern "C" {
#[wasm_bindgen] #[wasm_bindgen]
extern "C" { extern "C" {
#[wasm_bindgen(js_name = String, extends = Object)] #[wasm_bindgen(js_name = String, extends = Object)]
#[derive(Clone)] #[derive(Clone, PartialEq, Eq)]
pub type JsString; pub type JsString;
/// The length property of a String object indicates the length of a string, /// The length property of a String object indicates the length of a string,
@ -3580,7 +3588,7 @@ impl JsString {
/// `None`. /// `None`.
pub fn try_from(val: &JsValue) -> Option<&JsString> { pub fn try_from(val: &JsValue) -> Option<&JsString> {
if val.is_string() { if val.is_string() {
Some(unsafe { mem::transmute(val) }) Some(val.unchecked_ref())
} else { } else {
None None
} }
@ -3644,9 +3652,7 @@ impl<'a> PartialEq<&'a String> for JsString {
impl<'a> From<&'a str> for JsString { impl<'a> From<&'a str> for JsString {
fn from(s: &'a str) -> Self { fn from(s: &'a str) -> Self {
JsString { JsString::unchecked_from_js(JsValue::from_str(s))
obj: JsValue::from_str(s),
}
} }
} }