Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Unified Diff: third_party/WebKit/LayoutTests/sensor/resources/sensor-helpers.js

Issue 2481013004: [sensors] Reject test promise when callback throws an error (Closed)
Patch Set: Rebased to master Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/sensor/ambient-light-sensor.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/sensor/resources/sensor-helpers.js
diff --git a/third_party/WebKit/LayoutTests/sensor/resources/sensor-helpers.js b/third_party/WebKit/LayoutTests/sensor/resources/sensor-helpers.js
index 4315317fc1c11b9a541cec7e0b1cade0710a50bf..1e369ba2cf92c44da1e3bd3196f8d7eb22b07914 100644
--- a/third_party/WebKit/LayoutTests/sensor/resources/sensor-helpers.js
+++ b/third_party/WebKit/LayoutTests/sensor/resources/sensor-helpers.js
@@ -1,5 +1,22 @@
'use strict';
+// Wraps callback and calls reject_func if callback throws an error.
+class CallbackWrapper {
+ constructor(callback, reject_func) {
+ this.wrapper_func_ = (args) => {
+ try {
+ callback(args);
+ } catch(e) {
+ reject_func();
+ }
+ }
+ }
+
+ get callback() {
+ return this.wrapper_func_;
+ }
+}
+
function sensor_mocks(mojo) {
return define('Generic Sensor API mocks', [
'mojo/public/js/core',
@@ -53,7 +70,8 @@ function sensor_mocks(mojo) {
if (!this.start_should_fail_ && this.update_reading_function_ != null) {
let timeout = (1 / configuration.frequency) * 1000;
this.sensor_reading_timer_id_ = window.setTimeout(() => {
- this.update_reading_function_(this.buffer_);
+ if (this.update_reading_function_)
+ this.update_reading_function_(this.buffer_);
if (this.reporting_mode_ === sensor.ReportingMode.ON_CHANGE) {
this.client_.sensorReadingChanged();
}
« no previous file with comments | « third_party/WebKit/LayoutTests/sensor/ambient-light-sensor.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698