1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#![no_std]
use js::*;

pub trait GetProperty {
    fn get_property(el: impl Into<f64>, id: &str) -> Self;
}

impl GetProperty for f64 {
    fn get_property(el: impl Into<f64>, id: &str) -> Self {
        js!("function(el,strPtr,strLen){
            el = this.getObject(el);
            return el[this.readUtf8FromMemory(strPtr,strLen)];
        }")
        .invoke_3(el.into(), id.as_ptr() as u32, id.len() as u32)
    }
}

pub fn get_property<T>(el: impl Into<f64>, id: &str) -> T
where
    T: GetProperty,
{
    T::get_property(el, id)
}