{"action":"created","issue":{"url":"https://api.github.com/repos/rustwasm/wasm-bindgen/issues/109","repository_url":"https://api.github.com/repos/rustwasm/wasm-bindgen","labels_url":"https://api.github.com/repos/rustwasm/wasm-bindgen/issues/109/labels{/name}","comments_url":"https://api.github.com/repos/rustwasm/wasm-bindgen/issues/109/comments","events_url":"https://api.github.com/repos/rustwasm/wasm-bindgen/issues/109/events","html_url":"https://github.com/rustwasm/wasm-bindgen/issues/109","id":312321221,"number":109,"title":"DOM example fails: Chrome and Firefox Nightly have `body` on `Document` only","user":{"login":"badboy","id":2129,"avatar_url":"https://avatars2.githubusercontent.com/u/2129?v=4","gravatar_id":"","url":"https://api.github.com/users/badboy","html_url":"https://github.com/badboy","followers_url":"https://api.github.com/users/badboy/followers","following_url":"https://api.github.com/users/badboy/following{/other_user}","gists_url":"https://api.github.com/users/badboy/gists{/gist_id}","starred_url":"https://api.github.com/users/badboy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/badboy/subscriptions","organizations_url":"https://api.github.com/users/badboy/orgs","repos_url":"https://api.github.com/users/badboy/repos","events_url":"https://api.github.com/users/badboy/events{/privacy}","received_events_url":"https://api.github.com/users/badboy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-04-08T16:55:37Z","updated_at":"2018-04-08T19:32:57Z","closed_at":null,"author_association":"NONE","body":"The [current DOM example](https://github.com/rustwasm/wasm-bindgen/tree/9723fdd69bbcd26bed7c61d1904ca21ffbf5fdf7/examples/dom) fails to run on Firefox Nightly (61.0a1) and Chrome with the following error:\r\n\r\n```\r\nTypeError: Object.getOwnPropertyDescriptor(...) is undefined\r\n```\r\n\r\nThis happens when this code is run:\r\n\r\n```javascript\r\nObject.getOwnPropertyDescriptor(HTMLDocument.prototype, 'body').get\r\n```\r\n\r\nIn Chrome and newer Firefox properties of `HTMLDocument` were moved into `Document` (see [this bug](https://bugzilla.mozilla.org/show_bug.cgi?id=897815) I think).\r\nThe following patch makes the example work on Nightly (but then fails on Firefox stable)\r\n\r\n```patch\r\n--- a/examples/dom/src/lib.rs\r\n+++ b/examples/dom/src/lib.rs\r\n@@ -16,12 +16,12 @@ use wasm_bindgen::prelude::*;\r\n // signatures documented on MDN, for example\r\n #[wasm_bindgen]\r\n extern {\r\n-    type HTMLDocument;\r\n-    static document: HTMLDocument;\r\n+    type Document;\r\n+    static document: Document;\r\n     #[wasm_bindgen(method)]\r\n-    fn createElement(this: &HTMLDocument, tagName: &str) -> Element;\r\n+    fn createElement(this: &Document, tagName: &str) -> Element;\r\n     #[wasm_bindgen(method, getter)]\r\n-    fn body(this: &HTMLDocument) -> Element;\r\n+    fn body(this: &Document) -> Element;\r\n \r\n     type Element;\r\n     #[wasm_bindgen(method, setter = innerHTML)]\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/rustwasm/wasm-bindgen/issues/comments/379576037","html_url":"https://github.com/rustwasm/wasm-bindgen/issues/109#issuecomment-379576037","issue_url":"https://api.github.com/repos/rustwasm/wasm-bindgen/issues/109","id":379576037,"user":{"login":"lukewagner","id":9660325,"avatar_url":"https://avatars1.githubusercontent.com/u/9660325?v=4","gravatar_id":"","url":"https://api.github.com/users/lukewagner","html_url":"https://github.com/lukewagner","followers_url":"https://api.github.com/users/lukewagner/followers","following_url":"https://api.github.com/users/lukewagner/following{/other_user}","gists_url":"https://api.github.com/users/lukewagner/gists{/gist_id}","starred_url":"https://api.github.com/users/lukewagner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukewagner/subscriptions","organizations_url":"https://api.github.com/users/lukewagner/orgs","repos_url":"https://api.github.com/users/lukewagner/repos","events_url":"https://api.github.com/users/lukewagner/events{/privacy}","received_events_url":"https://api.github.com/users/lukewagner/received_events","type":"User","site_admin":false},"created_at":"2018-04-08T19:32:57Z","updated_at":"2018-04-08T19:32:57Z","author_association":"CONTRIBUTOR","body":"Very interesting, thanks for pointing this out.  It seems like, while breakage like this should be rare (esp. with everything being pretty well-specified by Web IDL), it will probably happen from time to time and then there's the issue of different browsers doing different things.\r\n\r\nOne idea: if we assume that properties mostly only ever move \"up\" the protochain, wasm-bindgen could use the following helper instead of `Object.getOwnPropertyDescriptor`:\r\n```js\r\nfunction GetOwnOrInheritedPropertyDescriptor(obj, id) {\r\n  while (obj) {\r\n    let desc = Object.getOwnPropertyDescriptor(obj, id);\r\n    if (desc) return desc;\r\n    obj = Object.getPrototypeOf(obj);\r\n  }\r\n  throw \"not found\";\r\n}\r\n```"}}
{"actor":{"display_login":"lukewagner"}}