javascript 0.3.0

A JavaScript engine implementation in Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use javascript::*;

#[test]
fn compare_proto_and_instanceof() -> Result<(), JSError> {
    let script = r#"
        const n = Object(123);
        const protoEq = (n.__proto__ === Number.prototype) ? 'EQ' : 'NEQ';
        const inst = (n instanceof Number) ? 'I' : 'N';
        protoEq + '|' + inst;
    "#;
    let res = evaluate_script(script, false, None::<&std::path::Path>).unwrap();
    assert_eq!(
        res, "\"EQ|I\"",
        "Expected boxed Number to have Number prototype and be instanceof Number, got {res}",
    );
    Ok(())
}