diff --git a/reference.md b/reference.md index 7e472d5..089f30f 100644 --- a/reference.md +++ b/reference.md @@ -113,7 +113,7 @@ A finalization registry provides a way to request that a *cleanup callback* get * [The `FinalizationRegistry` Constructor](#the-finalizationregistry-constructor) * [`FinalizationRegistry.prototype.register`](#finalizationregistryprototyperegister) * [`FinalizationRegistry.prototype.unregister`](#finalizationregistryprototypeunregister) - * [`FinalizationRegistry.prototype.cleanupSome`](#finalizationregistryprototypecleanupsome) + * [`FinalizationRegistry.prototype.cleanupSome`](#finalizationregistryprototypecleanupsome) *(optional)* ## FinalizationRegistry Overview @@ -324,15 +324,17 @@ class Thingy { ### `FinalizationRegistry.prototype.cleanupSome` -Triggers callbacks for an implementation-chosen number of objects in the registry that have been reclaimed but whose callbacks have not yet been called: +This **optional** method triggers callbacks for an implementation-chosen number of objects in the registry that have been reclaimed but whose callbacks have not yet been called: ```js -registry.cleanupSome(heldValue => { +registry.cleanupSome?.(heldValue => { // ... }); ``` -**NOTE:** Normally, you don't call this function. Leave it to the JavaScript engine's garbage collector to do the cleanup as appropriate. This function primarily exists to support long-running code which doesn't yield to the event loop, which is more likely to come up in WebAssembly than ordinary JavaScript code. Also note that the callback may not be called (for instance, if there are no registry entries whose targets have been reclaimed). +This method is optional, any given implementation may not have it. It's expected not to be present on web browsers, at least not initially; see [HTML issue #5446](https://github.com/whatwg/html/issues/5446) for details. Since the method is optional, you need to check that it's there before calling it. One way to do that is to use [optional chaining](https://github.com/tc39/proposal-optional-chaining) (`?.`) as in the example above. + +Normally, you don't call this function. Leave it to the JavaScript engine's garbage collector to do the callbacks as appropriate. This function primarily exists to support long-running code which doesn't yield to the event loop, which is more likely to come up in WebAssembly than ordinary JavaScript code. Also note that the callback may not be called (for instance, if there are no registry entries whose targets have been reclaimed). **Parameters**