すずねーう
Deno3y ago
2 replies
すずねーう

How do I make Objects, Maps, etc. in rusty_v8 into easy-to-understand String?

Hello. I wrote the following code in rusty_v8
    let isolate = &mut v8::Isolate::new(Default::default());

    let mut client = InspectorClient::new();
    let mut inspector = V8Inspector::create(isolate, &mut client);

    let scope = &mut v8::HandleScope::new(isolate);
    let context = v8::Context::new(scope);
    let scope = &mut v8::ContextScope::new(scope, context);

    inspector.context_created(context, 1, StringView::empty());

    let mut result_strings: Vec<String> = Vec::new();

    v8::String::new(scope, &code)
        .map(|code| {
            println!("code: {}", code.to_rust_string_lossy(scope));
            code
        })
        .and_then(|code| v8::Script::compile(scope, code, None))
        .and_then(|script| script.run(scope))
        .and_then(|value| value.to_string(scope))
        .iter()
        .for_each(|value| {
            result_strings.push(value.to_rust_string_lossy(scope));
        });

    let result = result_strings.join("\n");
    println!("{}", result);


Numbers such as 1+1 and strings such as "Hello!" are output correctly, but objects such as { a: 1 } are displayed as [object Object]. Is there any way to fix this?
Was this page helpful?