Chromium Code Reviews| 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..36cf5de940f9b1397f498c516cd82756c9d9d597 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(); |
| + } |
| + } |
| + } |
| + |
| + callback() { |
|
Mikhail
2016/11/08 09:04:16
Could you provide more readable name for it, for e
|
| + 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(); |
| } |