{"action":"created","issue":{"url":"https://api.github.com/repos/rustwasm/wasm-bindgen/issues/768","repository_url":"https://api.github.com/repos/rustwasm/wasm-bindgen","labels_url":"https://api.github.com/repos/rustwasm/wasm-bindgen/issues/768/labels{/name}","comments_url":"https://api.github.com/repos/rustwasm/wasm-bindgen/issues/768/comments","events_url":"https://api.github.com/repos/rustwasm/wasm-bindgen/issues/768/events","html_url":"https://github.com/rustwasm/wasm-bindgen/issues/768","id":355612930,"node_id":"MDU6SXNzdWUzNTU2MTI5MzA=","number":768,"title":"Serde serialization example from docs not working","user":{"login":"Tarnadas","id":5855071,"node_id":"MDQ6VXNlcjU4NTUwNzE=","avatar_url":"https://avatars2.githubusercontent.com/u/5855071?v=4","gravatar_id":"","url":"https://api.github.com/users/Tarnadas","html_url":"https://github.com/Tarnadas","followers_url":"https://api.github.com/users/Tarnadas/followers","following_url":"https://api.github.com/users/Tarnadas/following{/other_user}","gists_url":"https://api.github.com/users/Tarnadas/gists{/gist_id}","starred_url":"https://api.github.com/users/Tarnadas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tarnadas/subscriptions","organizations_url":"https://api.github.com/users/Tarnadas/orgs","repos_url":"https://api.github.com/users/Tarnadas/repos","events_url":"https://api.github.com/users/Tarnadas/events{/privacy}","received_events_url":"https://api.github.com/users/Tarnadas/received_events","type":"User","site_admin":false},"labels":[{"id":782247497,"node_id":"MDU6TGFiZWw3ODIyNDc0OTc=","url":"https://api.github.com/repos/rustwasm/wasm-bindgen/labels/bug","name":"bug","color":"ee0701","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-08-30T14:31:40Z","updated_at":"2018-08-31T22:49:36Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Basically what the title says.\r\n\r\n```rs\r\n// rust\r\n#[derive(Serialize)]\r\npub struct Example {\r\n    pub field1: HashMap<u32, String>,\r\n    pub field2: Vec<Vec<f32>>,\r\n    pub field3: [f32; 4],\r\n}\r\n\r\n#[wasm_bindgen]\r\npub fn send_example_to_js() -> JsValue {\r\n    let mut field1 = HashMap::new();\r\n    field1.insert(0, String::from(\"ex\"));\r\n    let example = Example {\r\n        field1,\r\n        field2: vec![vec![1., 2.], vec![3., 4.]],\r\n        field3: [1., 2., 3., 4.]\r\n    };\r\n\r\n    JsValue::from_serde(&example).unwrap()\r\n}\r\n```\r\n\r\n```js\r\nimport {\r\n  send_example_to_js\r\n} from 'rustfile';\r\n\r\nsend_example_to_js();\r\n```\r\n\r\nthrows this error:\r\n\r\n```js\r\nUncaught (in promise) TypeError: Cannot read property 'obj' of undefined\r\n    at getObject (lib.rs:23)\r\n    at takeObject (lib.rs:45)\r\n    at send_example_to_js (lib.rs:53)\r\n\r\n// compiled src\r\nfunction getObject(idx) {\r\n    if ((idx & 1) === 1) {\r\n        return stack[idx >> 1];\r\n    } else {\r\n        const val = slab[idx >> 1];\r\n        \r\n        return val.obj; // <----\r\n        \r\n    }\r\n}\r\n\r\nlet slab_next = slab.length;\r\n\r\nfunction dropRef(idx) {\r\n    \r\n    idx = idx >> 1;\r\n    if (idx < 4) return;\r\n    let obj = slab[idx];\r\n    \r\n    obj.cnt -= 1;\r\n    if (obj.cnt > 0) return;\r\n    \r\n    // If we hit 0 then free up our space in the slab\r\n    slab[idx] = slab_next;\r\n    slab_next = idx;\r\n}\r\n\r\nfunction takeObject(idx) {\r\n    const ret = getObject(idx);\r\n    dropRef(idx);\r\n    return ret;\r\n}\r\n\r\nexport function send_example_to_js() {\r\n    return takeObject(wasm.send_example_to_js());\r\n}\r\n```\r\n\r\nI enabled the serialization feature via the TOML file:\r\n```\r\n[dependencies.wasm-bindgen]\r\nversion = \"^0.2\"\r\nfeatures = [\"nightly\", \"serde-serialize\"]\r\n```\r\n\r\nI'm also interested whether HashMap serialization will become a built-in of wasm-bindgen or what would be the easiest approach to pass a JavaScript Object, e.g. { [key: string]: string }, into Rust?"},"comment":{"url":"https://api.github.com/repos/rustwasm/wasm-bindgen/issues/comments/417808073","html_url":"https://github.com/rustwasm/wasm-bindgen/issues/768#issuecomment-417808073","issue_url":"https://api.github.com/repos/rustwasm/wasm-bindgen/issues/768","id":417808073,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNzgwODA3Mw==","user":{"login":"alexcrichton","id":64996,"node_id":"MDQ6VXNlcjY0OTk2","avatar_url":"https://avatars1.githubusercontent.com/u/64996?v=4","gravatar_id":"","url":"https://api.github.com/users/alexcrichton","html_url":"https://github.com/alexcrichton","followers_url":"https://api.github.com/users/alexcrichton/followers","following_url":"https://api.github.com/users/alexcrichton/following{/other_user}","gists_url":"https://api.github.com/users/alexcrichton/gists{/gist_id}","starred_url":"https://api.github.com/users/alexcrichton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexcrichton/subscriptions","organizations_url":"https://api.github.com/users/alexcrichton/orgs","repos_url":"https://api.github.com/users/alexcrichton/repos","events_url":"https://api.github.com/users/alexcrichton/events{/privacy}","received_events_url":"https://api.github.com/users/alexcrichton/received_events","type":"User","site_admin":false},"created_at":"2018-08-31T22:49:36Z","updated_at":"2018-08-31T22:49:36Z","author_association":"COLLABORATOR","body":"@Tarnadas hm there's quite a lot going on there with a lot of dependencies that could be introducing a bug, could you try to perhaps minimize this to see which dependency is causing the issue?"}}
{"actor":{"display_login":"alexcrichton"}}