This repository has been archived by the owner on Apr 16, 2019. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RByers I'm having a hard time grokking this logic. I understand it's meant to determine whether the browser supports passive listeners, but I don't exactly see how it's doing that. Can you clarify?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's a little ugly / confusing, sorry about that. Basically the canonical way (only way at the moment) to feature detect for dictionary members is to pass a custom object to an API that takes the dictionary and see if the getter is invoked for the property of interest. WebIDL Ecmascript bindings require that the getter for each supported property is invoked when the function is called.
So in this case we do a dummy call to
addEventListener
(passing null as the handler is defined to be a no-op). We pass into that a custom object whosepassive
getter function just records that it has been called. There are four possible behaviors:addEventListener
ordefineProperty
at all - throws,supportsPassive
remains false.addEventListener
expects only a boolean in the 3rd position. The object gets coerced to the valuetrue
without invoking the getter.supportsPassive
remains false.addEventListener
supports taking a dictionary in the 3rd position, but not thepassive
member. In that case other getters may be invoked, but not the one we've defined forpassive
.supportsPassive
remains false.addEventListener
supports the passive option. In that case the getter function we've defined gets run as part of the JavaScript API binding andsupportsPassive
will be true.For context see the original design discussion and this WebIDL issue where we're considering exposing something less ugly.