{"action":"created","issue":{"url":"https://api.github.com/repos/whatwg/html/issues/1238","repository_url":"https://api.github.com/repos/whatwg/html","labels_url":"https://api.github.com/repos/whatwg/html/issues/1238/labels{/name}","comments_url":"https://api.github.com/repos/whatwg/html/issues/1238/comments","events_url":"https://api.github.com/repos/whatwg/html/issues/1238/events","html_url":"https://github.com/whatwg/html/issues/1238","id":154425510,"number":1238,"title":"\"Upgrade an element\" step 4 should remove element, or an already constructed marker","user":{"login":"dominiccooney","id":55120,"avatar_url":"https://avatars.githubusercontent.com/u/55120?v=3","gravatar_id":"","url":"https://api.github.com/users/dominiccooney","html_url":"https://github.com/dominiccooney","followers_url":"https://api.github.com/users/dominiccooney/followers","following_url":"https://api.github.com/users/dominiccooney/following{/other_user}","gists_url":"https://api.github.com/users/dominiccooney/gists{/gist_id}","starred_url":"https://api.github.com/users/dominiccooney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dominiccooney/subscriptions","organizations_url":"https://api.github.com/users/dominiccooney/orgs","repos_url":"https://api.github.com/users/dominiccooney/repos","events_url":"https://api.github.com/users/dominiccooney/events{/privacy}","received_events_url":"https://api.github.com/users/dominiccooney/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/whatwg/html/labels/topic:%20custom%20elements","name":"topic: custom elements","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-05-12T08:30:02Z","updated_at":"2016-05-21T07:50:26Z","closed_at":null,"body":"I'm trying to implement [the HTMLElement constructor](https://html.spec.whatwg.org/multipage/dom.html#dom-htmlelement) in Blink. Step 8 replaces an element with an already constructed marker. I don't see anywhere that removes already constructed markers from the stack, which could be a problem.\r\n\r\nI think [upgrade an element](https://html.spec.whatwg.org/multipage/scripting.html#concept-upgrade-an-element) step 4 may intend to simply pop from the construction stack instead of popping _element_; in the common case the top of the stack will not be _element_ but an already constructed marker. Maybe already constructed markers should be associated with the element that caused them, and step 4 can pop _element_ or its associated already constructed marker."},"comment":{"url":"https://api.github.com/repos/whatwg/html/issues/comments/220764529","html_url":"https://github.com/whatwg/html/issues/1238#issuecomment-220764529","issue_url":"https://api.github.com/repos/whatwg/html/issues/1238","id":220764529,"user":{"login":"dominiccooney","id":55120,"avatar_url":"https://avatars.githubusercontent.com/u/55120?v=3","gravatar_id":"","url":"https://api.github.com/users/dominiccooney","html_url":"https://github.com/dominiccooney","followers_url":"https://api.github.com/users/dominiccooney/followers","following_url":"https://api.github.com/users/dominiccooney/following{/other_user}","gists_url":"https://api.github.com/users/dominiccooney/gists{/gist_id}","starred_url":"https://api.github.com/users/dominiccooney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dominiccooney/subscriptions","organizations_url":"https://api.github.com/users/dominiccooney/orgs","repos_url":"https://api.github.com/users/dominiccooney/repos","events_url":"https://api.github.com/users/dominiccooney/events{/privacy}","received_events_url":"https://api.github.com/users/dominiccooney/received_events","type":"User","site_admin":false},"created_at":"2016-05-21T07:50:26Z","updated_at":"2016-05-21T07:50:26Z","body":"I'm trying to implement this is Blink. I'm glad there is now popping somewhere. Could you sanity check me on the following observation?\r\n\r\nI believe by popping the construction stack in upgrade, the spec prevents reentering a constructor of a given type, during upgrade. The reason is subsequent constructor calls, with new or through upgrade (for example, innerHTML) will reach step 5 of HTMLElement constructor. To put it another way, popping in upgrade &ldquo;protects&rdquo; the time between the UA calling the author's constructor and super getting to run; but in addition it extends protection to the author's constructor body, too, because the popping happens after that.\r\n\r\nWhile this is a severe restriction I believe this is probably the only sane situation to prevent &ldquo;poaching.&rdquo;\r\n\r\nOne interesting wrinkle this causes is that calling the same constructor, whether with new or upgrade, *is* allowed during a call caused by \"new\" because the construction stack is empty. This is not a particular problem for our implementation, but it is an asymmetry for the author. I believe they can detect whether a call is via new or upgrade this way:\r\n\r\n````javascript\r\nclass X extends HTMLElement() {\r\n  constructor(opt_in_detect) {\r\n    super();\r\n    console.log('in upgrade? ', inUpgrade(opt_in_detect));\r\n  }\r\n  inUpgrade(opt_in_detect) {\r\n    if (opt_in_detect) throw 'OK';\r\n    else try {\r\n      new X(true);\r\n    } catch (e) {\r\n      return e != 'OK';\r\n    }\r\n    // unreached\r\n  }\r\n}\r\n````\r\n\r\n&hellip;but I&rsquo;m not sure. :)"}}
{"actor":{"display_login":"dominiccooney"}}