[generic-sensor] Avoid unhandled promise rejection #16414
Merged
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.
By testing for a global binding via an unqualified IdentifierReference,
the Generic Sensor utility file produces a rejected promise which is not
handled. If testharness.js has not yet determined that testing is
complete, this unhandled rejection will cause a harness-level error.
Such errors will occur based on relative timing of asynchronous
operations, and this has been observed to be unstable in Apple Safari as
hosted on Azure Pipelines.
Update the feature detection logic to avoid generating an unhandled
rejection by instead referencing a property of the global object.
I have not been able to reproduce the harness error locally, but the issue is clear from the results collected via Azure Pipelines and uploaded to wpt.fyi. The most recent results for
ambient-light/AmbientLightSensor_insecure_context.html
demonstrate the problemThe "history" feature on that page shows that this is intermittent in that environment. The same problem affects all tests which do not use the
sensor_test
function, that is: all of the_insecure_context.html
tests.In addition to promoting determinism in those specific tests, this change improves failure messages for all tests in browsers which don't define the Mojo interface. Currently, the tests fail with the message: "ReferenceError: MojoInterfaceInterceptor is not defined". With this patch applied, they instead fail with the message, "assert_true: Mojo testing interface is not available. expected true got false"