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

JsSerializable doesn't handle Value::Reference correctly #61

Open
Dreae opened this issue Dec 30, 2017 · 0 comments
Open

JsSerializable doesn't handle Value::Reference correctly #61

Dreae opened this issue Dec 30, 2017 · 0 comments

Comments

@Dreae
Copy link

Dreae commented Dec 30, 2017

There seems to be a bug when passing structs containing a Value::Reference to JavaScript. When accessing the struct field containing the reference in JavaScript it only contains an empty object instead of the reference passed in by Rust.

See the below code for clarification.

#[derive(Serialize)]
struct ReferenceHolder {
    reference: Value
}
js_serializable!(ReferenceHolder);

fn test_ref() {
    let message = "Hello!".as_bytes();
    let reference = Value::Reference(Reference::from(TypedArray::from(message)));
    let obj = ReferenceHolder {
        reference: Value::Reference(Reference::from(TypedArray::from(message)))
    };

    js! {
        console.log(@{reference});
        // Prints `Uint8Array [ 72, 101, 108, 108, 111, 33 ]`

        console.log(@{obj});
        // Prints `Object { reference: {} }`
    };
}

fn main() {
    stdweb::initialize();

    test_ref();
}
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

No branches or pull requests

1 participant