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(); |
} |