[heycam/webidl] Should we "check if we can run script" before calling callbacks? (#993)

Most places in HTML that use [prepare to run script](https://html.spec.whatwg.org/multipage/webappapis.html#prepare-to-run-script) call [check if we can run script](https://html.spec.whatwg.org/multipage/webappapis.html#check-if-we-can-run-script) beforehand, and bail out if you can't:

- [run a classic script](https://html.spec.whatwg.org/multipage/webappapis.html#run-a-classic-script)
- [run a module script](https://html.spec.whatwg.org/multipage/webappapis.html#run-a-module-script)
- [HostEnqueueFinalizationRegistryCleanupJob](https://html.spec.whatwg.org/multipage/webappapis.html#hostenqueuefinalizationregistrycleanupjob)
- [HostEnqueuePromiseJob](https://html.spec.whatwg.org/multipage/webappapis.html#hostenqueuepromisejob)

However, Web IDL notably does not! See:

- [invoke](https://heycam.github.io/webidl/#invoke-a-callback-function)
- [construct](https://heycam.github.io/webidl/#construct-a-callback-function)
- [call a user object's operation](https://heycam.github.io/webidl/#call-a-user-objects-operation)

This is important because the first step in "check if we can run the script" is to return false if we're in a non-fully-active document, e.g. a detached iframe or a bfcached page.

Chrome seems to include such a "check if we can run script" check for Web IDL callbacks: see https://jsfiddle.net/shaseley/w4nsq2oj/7/ which runs the task in Firefox and Safari but does _not_ run the task in Chrome. Discovered by @shaseley @natechapin.

Worse, https://jsfiddle.net/n04m3jpo/ shows a variant with promise handlers (instead of `setTimeout`'s Web IDL callbacks) where Chrome and Safari *do* run the promise handler, and Firefox does not.

(On the spec side, I think we cargo-culted the "check if we can run script" check into HostEnqueueFinalizationRegistryCleanupJob and HostEnqueuePromiseJob without testing, because I thought it was about the user disabling scripting, and I forgot it was also about non-fully-active documents.)

My instinct is that we should be uniform here and not run the handler in any cases. /cc @smaug---- @rakina for bfcache connection, @syg for promise/finalization registry connection.

Related: https://github.com/whatwg/html/issues/2621

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/issues/993

Received on Thursday, 24 June 2021 21:49:05 UTC