Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 suiteSetup(function() { | |
| 6 cr.define('bookmarks', function() { | |
| 7 var TestTimerProxy = function(data) { | |
| 8 bookmarks.TimerProxy.call(this); | |
| 9 | |
| 10 this.immediatelyResolveTimeouts = true; | |
| 11 | |
| 12 this.timeoutIds_ = 0; | |
| 13 | |
| 14 /** @private {Object<number, Function>} */ | |
|
tsergeant
2017/06/13 06:48:43
We can do better than Object:
!Map<number, !Funct
calamity
2017/06/16 02:59:26
Done.
| |
| 15 this.activeTimeouts_ = new Map(); | |
| 16 }; | |
| 17 | |
| 18 TestTimerProxy.prototype = { | |
| 19 __proto__: bookmarks.TimerProxy.prototype, | |
| 20 | |
| 21 /** | |
| 22 * @param {Function|string} fn | |
| 23 * @param {number=} delay | |
| 24 * @return {number} | |
| 25 * @override | |
| 26 */ | |
| 27 setTimeout: function(fn, delay) { | |
| 28 if (this.immediatelyResolveTimeouts) | |
| 29 fn(); | |
| 30 else | |
| 31 this.activeTimeouts_[this.timeoutIds_] = fn; | |
| 32 | |
| 33 return this.timeoutIds_++; | |
|
tsergeant
2017/06/13 06:48:43
Optional: You could use cr.createUid() here, since
calamity
2017/06/16 02:59:26
My ids start fighting with other uids which make m
tsergeant
2017/06/16 03:54:22
Oh, sure, I forgot that you were hardcoding the va
| |
| 34 }, | |
| 35 | |
| 36 /** | |
| 37 * @param {number|undefined?} id | |
| 38 * @override | |
| 39 */ | |
| 40 clearTimeout: function(id) { | |
| 41 this.activeTimeouts_.delete(id); | |
| 42 }, | |
| 43 | |
| 44 /** | |
| 45 * Run the function associated with a timeout id and clear it from the | |
| 46 * active timeouts. | |
| 47 * @param {number} id | |
| 48 */ | |
| 49 runTimeoutFn: function(id) { | |
| 50 this.activeTimeouts_[id](); | |
| 51 this.clearTimeout(id); | |
| 52 }, | |
| 53 | |
| 54 /** | |
| 55 * Returns whether a given timeout id has been run or cleared. | |
|
tsergeant
2017/06/13 06:48:43
This sentence is a little tough to read. How about
calamity
2017/06/16 02:59:26
Done.
| |
| 56 * @param {number} id | |
| 57 * @return {boolean} | |
| 58 */ | |
| 59 hasTimeout: function(id) { | |
| 60 return this.activeTimeouts_.has(id); | |
| 61 }, | |
| 62 }; | |
| 63 | |
| 64 return { | |
| 65 TestTimerProxy: TestTimerProxy, | |
| 66 }; | |
| 67 }); | |
| 68 }); | |
| OLD | NEW |