Bug 236349

Summary: Permission API: PermissionStatus with registered "change" listeners shouldn't be GC'd
Product: WebKit Reporter: Marcos Caceres <marcos>
Component: New BugsAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: cdumez, marcos, sihui_liu, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: Safari Technology Preview   
Hardware: Unspecified   
OS: Unspecified   
URL: https://github.com/w3c/permissions/pull/360
Bug Depends on:    
Bug Blocks: 229504    

Description Marcos Caceres 2022-02-08 23:12:51 PST
Related spec change:
https://github.com/w3c/permissions/pull/360

It should be possible to get a PermissionStatus object, register a listener on it, and allow it to go out of scope (but not have it GC'd) 

For example: 

```JS
(async () => {
  const perm = await navigator.permissions.query({ name: "geolocation" });
  perm.onchange = () => { console.log("pass") };
  console.log("going out of scope");
  // bye bye perm
})();

// prompts for permission
navigator.geolocation.getCurrentPosition(console.log);
```

Changing the permission of Geolocation in the above should produce "pass" in the developer console.
Comment 1 Marcos Caceres 2022-02-08 23:15:58 PST
Noting the works in Blink-based browsers.
Comment 2 youenn fablet 2022-02-11 00:28:48 PST
Right, we do not support yet onchange event handler but when it is the case, we should definitely do something about it.
Comment 3 Radar WebKit Bug Importer 2022-02-15 09:31:12 PST
<rdar://problem/88969778>