{"action":"created","issue":{"url":"https://api.github.com/repos/whatwg/html/issues/855","repository_url":"https://api.github.com/repos/whatwg/html","labels_url":"https://api.github.com/repos/whatwg/html/issues/855/labels{/name}","comments_url":"https://api.github.com/repos/whatwg/html/issues/855/comments","events_url":"https://api.github.com/repos/whatwg/html/issues/855/events","html_url":"https://github.com/whatwg/html/issues/855","id":140027836,"number":855,"title":"Should we be doing prepare to run a script/clean up after running a script more often?","user":{"login":"domenic","id":617481,"avatar_url":"https://avatars.githubusercontent.com/u/617481?v=3","gravatar_id":"","url":"https://api.github.com/users/domenic","html_url":"https://github.com/domenic","followers_url":"https://api.github.com/users/domenic/followers","following_url":"https://api.github.com/users/domenic/following{/other_user}","gists_url":"https://api.github.com/users/domenic/gists{/gist_id}","starred_url":"https://api.github.com/users/domenic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/domenic/subscriptions","organizations_url":"https://api.github.com/users/domenic/orgs","repos_url":"https://api.github.com/users/domenic/repos","events_url":"https://api.github.com/users/domenic/events{/privacy}","received_events_url":"https://api.github.com/users/domenic/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/whatwg/html/labels/clarification","name":"clarification","color":"fef2c0"},{"url":"https://api.github.com/repos/whatwg/html/labels/topic:%20multiple%20globals","name":"topic: multiple globals","color":"009800"}],"state":"open","locked":false,"assignee":{"login":"domenic","id":617481,"avatar_url":"https://avatars.githubusercontent.com/u/617481?v=3","gravatar_id":"","url":"https://api.github.com/users/domenic","html_url":"https://github.com/domenic","followers_url":"https://api.github.com/users/domenic/followers","following_url":"https://api.github.com/users/domenic/following{/other_user}","gists_url":"https://api.github.com/users/domenic/gists{/gist_id}","starred_url":"https://api.github.com/users/domenic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/domenic/subscriptions","organizations_url":"https://api.github.com/users/domenic/orgs","repos_url":"https://api.github.com/users/domenic/repos","events_url":"https://api.github.com/users/domenic/events{/privacy}","received_events_url":"https://api.github.com/users/domenic/received_events","type":"User","site_admin":false},"milestone":null,"comments":4,"created_at":"2016-03-10T22:28:25Z","updated_at":"2016-06-22T19:50:24Z","closed_at":null,"body":"Now that we understand this issue better (see below for how we got there), here's a checklist of known places in HTML that should be doing this better.\r\n\r\nIn all cases, they need to be appropriately wrapped with [prepare to run script](https://html.spec.whatwg.org/multipage/webappapis.html#prepare-to-run-script) to correctly set up the entry global, and I believe also [prepare to run a callback](https://html.spec.whatwg.org/multipage/webappapis.html#prepare-to-run-a-callback) to correctly set up the incumbent global. (The latter especially if there are any cases of callbacks being \"saved\" and called later, but maybe in general?)\r\n\r\n- [ ] [Structured clone](https://html.spec.whatwg.org/multipage/infrastructure.html#safe-passing-of-structured-data)\r\n- [ ] [Custom element definition](https://html.spec.whatwg.org/multipage/scripting.html#element-definition)\r\n  - Probably should be converting the stored callbacks to Web IDL callback types\r\n- [ ] [Cross-origin objects](https://html.spec.whatwg.org/multipage/browsers.html#cross-origin-objects), maybe? (there are some Call()s and Get()s)\r\n\r\nOther specs are welcome to join this checklist.\r\n\r\n----\r\n\r\n_Original post:_\r\n\r\nWhen speccing custom elements, which do their fair share of Get()s and Construct()s, I realized that currently we do those sorts of things and bypass the following hooks:\r\n\r\n- https://html.spec.whatwg.org/#check-if-we-can-run-script\r\n- https://html.spec.whatwg.org/#prepare-to-run-script\r\n- https://html.spec.whatwg.org/#clean-up-after-running-script\r\n\r\nIn all cases this impacts tracking of the entry settings object and JS execution context stack. (See, however, #473 for how I messed that up a bit and still need to fix it.)\r\n\r\nIn some cases, it would also cause microtasks (and \"global script clean-up jobs\") to run. This would be the case for e.g. constructing custom elements from the parser, where there's a clean stack, but it would not be the case for createElement() or for structured clone, where there's some user code in the stack.\r\n\r\nIt seems likely to me that we need to wrap all our Get()s, Construct()s, etc. in appropriate check/prepare/cleanup steps. (Even GetOwnProperty()s are affected if proxies are involved.)\r\n\r\nWhen we use Web IDL, this is taken care of for us by the \"invoke\" algorithm. (Except for the fact that the invoke algorithm isn't up to date with last year's changes to HTML, i.e. the script settings object stack, but that's not a new problem...)\r\n\r\n@ajklein says he thinks he filed a bug on this a long time ago against either HTML or Web IDL. I didn't remember seeing it in the HTML archives, so I'm creating a new one. @bzbarsky presumably has thoughts here too, which I'd love to hear.\r\n\r\n<del>I'd probably solve this by introducing a one- or two-word verb like \"invoke\" that links to the appropriate wrapper steps, so that instead of saying \"Let _x_ be Get(y, z)\" we can do \"Let _x_ be the result of [invoking] Get(y, z).\"</del>"},"comment":{"url":"https://api.github.com/repos/whatwg/html/issues/comments/227856725","html_url":"https://github.com/whatwg/html/issues/855#issuecomment-227856725","issue_url":"https://api.github.com/repos/whatwg/html/issues/855","id":227856725,"user":{"login":"domenic","id":617481,"avatar_url":"https://avatars.githubusercontent.com/u/617481?v=3","gravatar_id":"","url":"https://api.github.com/users/domenic","html_url":"https://github.com/domenic","followers_url":"https://api.github.com/users/domenic/followers","following_url":"https://api.github.com/users/domenic/following{/other_user}","gists_url":"https://api.github.com/users/domenic/gists{/gist_id}","starred_url":"https://api.github.com/users/domenic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/domenic/subscriptions","organizations_url":"https://api.github.com/users/domenic/orgs","repos_url":"https://api.github.com/users/domenic/repos","events_url":"https://api.github.com/users/domenic/events{/privacy}","received_events_url":"https://api.github.com/users/domenic/received_events","type":"User","site_admin":false},"created_at":"2016-06-22T19:50:24Z","updated_at":"2016-06-22T19:50:24Z","body":"@bzbarsky, can you confirm for me that we do not need to do the \"prepare to run a callback\" stuff (which manages the incumbent mechanisms) unless we are saving a callback and calling it later?\r\n\r\nE.g. when structured cloning we do a few GetOwnProperty()s. Do we need to manage the backup incumbent settings object stack and increment the skip-when-determining-incumbent counter in those cases? I think that since we are immediately invoking code, those mechanisms are not relevant. But I'd appreciate confirmation."}}
{"actor":{"display_login":"domenic"}}