Changeset 1005
- Timestamp:
- 07/31/08 02:39:18 (1 month ago)
- Files:
-
- trunk/modules/cothread.jsm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/modules/cothread.jsm
r1004 r1005 44 44 const Timer = Components.Constructor('@mozilla.org/timer;1', 'nsITimer', 'initWithCallback'); 45 45 46 // "Abstract" base c'tor 47 function CoThreadBase(func, yieldEvery, thisCtx) { 48 this._thisCtx = thisCtx ? thisCtx : this; 49 50 // default to 1 51 this._yieldEvery = typeof yieldEvery == 'number' ? Math.floor(yieldEvery) : 1; 52 if (yieldEvery < 1) { 53 throw Cr.NS_ERROR_INVALID_ARG; 54 } 55 56 if (typeof func != 'function' && !(func instanceof Function)) { 57 throw Cr.NS_ERROR_INVALID_ARG; 58 } 59 this._func = func; 60 } 61 46 62 /** 47 63 * Constructs a new CoThread (aka. pseudo-thread). … … 67 83 */ 68 84 function CoThread(func, yieldEvery, thisCtx) { 69 70 this._thisCtx = thisCtx ? thisCtx : this; 71 72 // default to 1 73 this._yieldEvery = typeof yieldEvery == 'number' ? Math.floor(yieldEvery) : 1; 74 if (yieldEvery < 1) { 75 throw Cr.NS_ERROR_INVALID_ARG; 76 } 77 78 if (typeof func != 'function' && !(func instanceof Function)) { 79 throw Cr.NS_ERROR_INVALID_ARG; 80 } 81 this._func = func; 82 85 CoThreadBase.call(this, func, yieldEvery, thisCtx); 83 86 this._generator = (function() { for(;;) { yield null }; })(); 84 87 } … … 158 161 */ 159 162 function CoThreadListWalker(func, arrayOrGenerator, yieldEvery, thisCtx) { 160 CoThread .call(this, func, yieldEvery, thisCtx);163 CoThreadBase.call(this, func, yieldEvery, thisCtx); 161 164 162 165 if (arrayOrGenerator instanceof Array) {
