Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Allows a document to exercise the Budget API within a service worker by sendi ng commands. | 1 // Allows a document to exercise the Budget API within a service worker by sendi ng commands. |
| 2 | 2 |
| 3 self.addEventListener('message', function(workerEvent) { | 3 self.addEventListener('message', function(workerEvent) { |
| 4 port = workerEvent.data; | 4 port = workerEvent.data; |
| 5 | 5 |
| 6 // Listen to incoming commands on the message port. | 6 // Listen to incoming commands on the message port. |
| 7 port.onmessage = function(event) { | 7 port.onmessage = function(event) { |
| 8 if (typeof event.data != 'object' || !event.data.command) | 8 if (typeof event.data != 'object' || !event.data.command) |
| 9 return; | 9 return; |
| 10 var options = event.data.options || {}; | 10 var options = event.data.options || {}; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 break; | 47 break; |
| 48 | 48 |
| 49 case 'checkInterfaces': | 49 case 'checkInterfaces': |
| 50 let success = false; | 50 let success = false; |
| 51 let message = ""; | 51 let message = ""; |
| 52 try { | 52 try { |
| 53 success = 'BudgetService' in self && | 53 success = 'BudgetService' in self && |
| 54 WorkerNavigator.prototype.hasOwnProperty('budget') && | 54 WorkerNavigator.prototype.hasOwnProperty('budget') && |
| 55 BudgetService.prototype.hasOwnProperty('getCost') && | 55 BudgetService.prototype.hasOwnProperty('getCost') && |
| 56 BudgetService.prototype.hasOwnProperty('getBudget') && | 56 BudgetService.prototype.hasOwnProperty('getBudget') && |
| 57 BudgetService.prototype.hasOwnProperty('reserve') | 57 BudgetService.prototype.hasOwnProperty('reserve') && |
| 58 'BudgetState' in self && | |
| 59 BudgetState.prototype.hasOwnProperty('budgetAt') && | |
| 60 BudgetState.prototype.hasOwnProperty('time'); | |
|
Peter Beverloo
2016/12/14 11:37:08
Something that crossed my mind - we have no tests
harkness
2016/12/14 13:48:58
Sure, I can look into adding something for one or
| |
| 58 } catch(err) { | 61 } catch(err) { |
| 59 message = err.message; | 62 message = err.message; |
| 60 } | 63 } |
| 61 port.postMessage({ | 64 port.postMessage({ |
| 62 command: event.data.command, | 65 command: event.data.command, |
| 63 success: success, | 66 success: success, |
| 64 message: message}); | 67 message: message}); |
| 65 break; | 68 break; |
| 66 | 69 |
| 67 default: | 70 default: |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 78 | 81 |
| 79 function makeErrorHandler(command) { | 82 function makeErrorHandler(command) { |
| 80 return function(error) { | 83 return function(error) { |
| 81 var errorMessage = error ? error.message : 'unknown error'; | 84 var errorMessage = error ? error.message : 'unknown error'; |
| 82 port.postMessage({ | 85 port.postMessage({ |
| 83 command: command, | 86 command: command, |
| 84 success: false, | 87 success: false, |
| 85 errorMessage: errorMessage }); | 88 errorMessage: errorMessage }); |
| 86 }; | 89 }; |
| 87 } | 90 } |
| OLD | NEW |