Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TryFromJs from JsMap for HashMap & BtreeMap #3998

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Nikita-str
Copy link

Seems like TryFromJs didn't convert correctly from JsMap into HashMap / BtreeMap

This PR fix it

Example
Next code

use boa_engine::{value::TryFromJs, Context, JsResult, Source};
use std::collections::HashMap;

fn main() -> JsResult<()> {
    let js_code = "new Map([['a', 2], ['b', 3]])";
    let mut context = Context::default();

    let js_value = context.eval(Source::from_bytes(js_code))?;
    println!("{}", js_value.display());

    let map = HashMap::<String, i32>::try_from_js(&js_value, &mut context)?;
    println!("{map:?}");
    Ok(())
}

before this changes will return:

Map { "a" → 2, "b" → 3 }
{}

and after changes returns:

Map { "a" → 2, "b" → 3 }
{"a": 2, "b": 3}

Notes
I don't find more fast way(than the one used in for_each_elem_in_js_map) to get (key, value)'s from JsMap.
Maybe there is a way?
Or maybe I should write it (for example by function like next but that just return Option<(JsValue, JsValue)>)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant