-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
Description
This is sort of a child issue to #1367, but, because it's a bug, it seems worth it to track separately since it might be fixed independently from the more generic one.
While looking into #1087, I realised that #1367 is needed not only for prototype-less Object
s and cross-realm interaction, but also for new primitives which don't have automatic boxing.
Currently these are:
Symbol
BigInt
and for both instanceof
check will return false when used on a corresponding primitive, because they're not objects, and so dyn_ref
and dyn_into
fail to recognise them too.
Example:
#[wasm_bindgen]
pub fn symbol_to_string_1(s: Symbol) -> JsString {
s.to_string()
}
#[wasm_bindgen]
pub fn symbol_to_string_2(s: JsValue) -> JsString {
s.dyn_into::<Symbol>().unwrap().to_string()
}
#[wasm_bindgen]
pub fn symbol_to_string_3(s: JsValue) -> JsString {
if s.is_symbol() {
s.unchecked_into::<Symbol>().to_string()
} else {
panic!("Not a symbol")
}
}
Results:
> require('./pkg').symbol_to_string_1(Symbol('x'))
'Symbol(x)'
> require('./pkg').symbol_to_string_2(Symbol('x'))
panicked at 'called `Result::unwrap()` on an `Err` value: JsValue(Symbol(x))', src/libcore/result.rs:997:5
> require('./pkg').symbol_to_string_3(Symbol('x'))
'Symbol(x)'