OLD | NEW |
1 const Cc = Components.classes; | 1 const Cc = Components.classes; |
2 const Ci = Components.interfaces; | 2 const Ci = Components.interfaces; |
3 const Cr = Components.results; | 3 const Cr = Components.results; |
4 const Cu = Components.utils; | 4 const Cu = Components.utils; |
5 | 5 |
6 const MILLIS_IN_SECOND = 1000; | 6 const MILLIS_IN_SECOND = 1000; |
7 const MILLIS_IN_MINUTE = 60 * MILLIS_IN_SECOND; | 7 const MILLIS_IN_MINUTE = 60 * MILLIS_IN_SECOND; |
8 const MILLIS_IN_HOUR = 60 * MILLIS_IN_MINUTE; | 8 const MILLIS_IN_HOUR = 60 * MILLIS_IN_MINUTE; |
9 const MILLIS_IN_DAY = 24 * MILLIS_IN_HOUR; | 9 const MILLIS_IN_DAY = 24 * MILLIS_IN_HOUR; |
10 | 10 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 162 |
163 function setupVirtualTime(processTimers) | 163 function setupVirtualTime(processTimers) |
164 { | 164 { |
165 let currentTime = 100000 * MILLIS_IN_HOUR; | 165 let currentTime = 100000 * MILLIS_IN_HOUR; |
166 let startTime = currentTime; | 166 let startTime = currentTime; |
167 let scheduledTasks = []; | 167 let scheduledTasks = []; |
168 | 168 |
169 let modules = Array.prototype.slice.call(arguments, 1); | 169 let modules = Array.prototype.slice.call(arguments, 1); |
170 this._virtualTimeModules = modules; | 170 this._virtualTimeModules = modules; |
171 | 171 |
172 for each (let module in this._virtualTimeModules) | 172 for (let module of this._virtualTimeModules) |
173 { | 173 { |
174 let global = Cu.getGlobalForObject(getModuleGlobal(module)); | 174 let global = Cu.getGlobalForObject(getModuleGlobal(module)); |
175 | 175 |
176 // Replace Date.now() function | 176 // Replace Date.now() function |
177 this["_origNow" + module] = global.Date.now; | 177 this["_origNow" + module] = global.Date.now; |
178 global.Date.now = function() currentTime; | 178 global.Date.now = function() currentTime; |
179 } | 179 } |
180 | 180 |
181 // Wrap timers | 181 // Wrap timers |
182 if (processTimers) | 182 if (processTimers) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 } | 229 } |
230 this._runScheduledTasks(maxHours); | 230 this._runScheduledTasks(maxHours); |
231 } | 231 } |
232 | 232 |
233 this._runScheduledTasks = function(maxHours) | 233 this._runScheduledTasks = function(maxHours) |
234 { | 234 { |
235 let endTime = currentTime + maxHours * MILLIS_IN_HOUR; | 235 let endTime = currentTime + maxHours * MILLIS_IN_HOUR; |
236 while (true) | 236 while (true) |
237 { | 237 { |
238 let nextTask = null; | 238 let nextTask = null; |
239 for each (let task in scheduledTasks) | 239 for (let task of scheduledTasks) |
240 { | 240 { |
241 if (!nextTask || nextTask.nextExecution > task.nextExecution) | 241 if (!nextTask || nextTask.nextExecution > task.nextExecution) |
242 nextTask = task; | 242 nextTask = task; |
243 } | 243 } |
244 if (!nextTask || nextTask.nextExecution > endTime) | 244 if (!nextTask || nextTask.nextExecution > endTime) |
245 break; | 245 break; |
246 | 246 |
247 currentTime = nextTask.nextExecution; | 247 currentTime = nextTask.nextExecution; |
248 nextTask.handler(); | 248 nextTask.handler(); |
249 | 249 |
(...skipping 15 matching lines...) Expand all Loading... |
265 nextTask.nextExecution = currentTime + nextTask.delay; | 265 nextTask.nextExecution = currentTime + nextTask.delay; |
266 } | 266 } |
267 | 267 |
268 currentTime = endTime; | 268 currentTime = endTime; |
269 } | 269 } |
270 | 270 |
271 this._skipTasks = function(hours) | 271 this._skipTasks = function(hours) |
272 { | 272 { |
273 let newTasks = []; | 273 let newTasks = []; |
274 currentTime += hours * MILLIS_IN_HOUR; | 274 currentTime += hours * MILLIS_IN_HOUR; |
275 for each (let task in scheduledTasks) | 275 for (let task of scheduledTasks) |
276 { | 276 { |
277 if (task.nextExecution >= currentTime) | 277 if (task.nextExecution >= currentTime) |
278 newTasks.push(task); | 278 newTasks.push(task); |
279 else if (task.type != Components.interfaces.nsITimer.TYPE_ONE_SHOT) | 279 else if (task.type != Components.interfaces.nsITimer.TYPE_ONE_SHOT) |
280 { | 280 { |
281 task.nextExecution = currentTime; | 281 task.nextExecution = currentTime; |
282 newTasks.push(task); | 282 newTasks.push(task); |
283 } | 283 } |
284 } | 284 } |
285 scheduledTasks = newTasks; | 285 scheduledTasks = newTasks; |
286 } | 286 } |
287 | 287 |
288 this.getTimeOffset = function() (currentTime - startTime) / MILLIS_IN_HOUR; | 288 this.getTimeOffset = function() (currentTime - startTime) / MILLIS_IN_HOUR; |
289 | 289 |
290 this.__defineGetter__("currentTime", function() currentTime); | 290 this.__defineGetter__("currentTime", function() currentTime); |
291 } | 291 } |
292 | 292 |
293 function restoreVirtualTime() | 293 function restoreVirtualTime() |
294 { | 294 { |
295 for each (let module in this._virtualTimeModules) | 295 for (let module of this._virtualTimeModules) |
296 { | 296 { |
297 let global = Cu.getGlobalForObject(getModuleGlobal(module)); | 297 let global = Cu.getGlobalForObject(getModuleGlobal(module)); |
298 | 298 |
299 // Restore Date.now() function | 299 // Restore Date.now() function |
300 if ("_origNow" + module in this) | 300 if ("_origNow" + module in this) |
301 { | 301 { |
302 global.Date.now = this["_origNow" + module]; | 302 global.Date.now = this["_origNow" + module]; |
303 delete this["_origNow" + module]; | 303 delete this["_origNow" + module]; |
304 } | 304 } |
305 } | 305 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 let result = [Cr.NS_OK, 404, ""]; | 399 let result = [Cr.NS_OK, 404, ""]; |
400 if (this._data) | 400 if (this._data) |
401 result = [Cr.NS_OK, 0, this._data]; | 401 result = [Cr.NS_OK, 0, this._data]; |
402 else if (this._path in requestHandlers) | 402 else if (this._path in requestHandlers) |
403 result = requestHandlers[this._path]({method: "GET", path: this._path,
queryString: this._queryString}); | 403 result = requestHandlers[this._path]({method: "GET", path: this._path,
queryString: this._queryString}); |
404 [this.channel.status, this.channel.responseStatus, this.responseText] =
result; | 404 [this.channel.status, this.channel.responseStatus, this.responseText] =
result; |
405 this.status = this.channel.responseStatus; | 405 this.status = this.channel.responseStatus; |
406 | 406 |
407 let eventName = (this.channel.status == Cr.NS_OK ? "load" : "error"); | 407 let eventName = (this.channel.status == Cr.NS_OK ? "load" : "error"); |
408 let event = {type: eventName}; | 408 let event = {type: eventName}; |
409 for each (let handler in this["_" + eventName + "Handlers"]) | 409 for (let handler of this["_" + eventName + "Handlers"]) |
410 handler.call(this, event); | 410 handler.call(this, event); |
411 }.bind(this)); | 411 }.bind(this)); |
412 }, | 412 }, |
413 | 413 |
414 overrideMimeType: function(mime) | 414 overrideMimeType: function(mime) |
415 { | 415 { |
416 }, | 416 }, |
417 | 417 |
418 channel: | 418 channel: |
419 { | 419 { |
420 status: -1, | 420 status: -1, |
421 responseStatus: 0, | 421 responseStatus: 0, |
422 loadFlags: 0, | 422 loadFlags: 0, |
423 INHIBIT_CACHING: 0, | 423 INHIBIT_CACHING: 0, |
424 VALIDATE_ALWAYS: 0, | 424 VALIDATE_ALWAYS: 0, |
425 QueryInterface: function() this | 425 QueryInterface: function() this |
426 } | 426 } |
427 } | 427 } |
428 | 428 |
429 this.registerHandler = function(path, handler) requestHandlers[path] = handler
; | 429 this.registerHandler = function(path, handler) requestHandlers[path] = handler
; |
430 | 430 |
431 let modules = Array.prototype.slice.call(arguments, 1); | 431 let modules = Array.prototype.slice.call(arguments, 1); |
432 this._virtualXMLHttpModules = modules; | 432 this._virtualXMLHttpModules = modules; |
433 for each (let module in this._virtualTimeModules) | 433 for (let module of this._virtualTimeModules) |
434 { | 434 { |
435 let global = getModuleGlobal(module); | 435 let global = getModuleGlobal(module); |
436 | 436 |
437 // Replace XMLHttpRequest constructor | 437 // Replace XMLHttpRequest constructor |
438 this["_origXMLHttpRequest" + module] = global.XMLHttpRequest; | 438 this["_origXMLHttpRequest" + module] = global.XMLHttpRequest; |
439 global.XMLHttpRequest = XMLHttpRequest; | 439 global.XMLHttpRequest = XMLHttpRequest; |
440 } | 440 } |
441 } | 441 } |
442 | 442 |
443 function restoreVirtualXMLHttp() | 443 function restoreVirtualXMLHttp() |
444 { | 444 { |
445 for each (let module in this._virtualXMLHttpModules) | 445 for (let module of this._virtualXMLHttpModules) |
446 { | 446 { |
447 let global = getModuleGlobal(module); | 447 let global = getModuleGlobal(module); |
448 | 448 |
449 // Restore XMLHttpRequest constructor | 449 // Restore XMLHttpRequest constructor |
450 if ("_origXMLHttpRequest" + module in this) | 450 if ("_origXMLHttpRequest" + module in this) |
451 { | 451 { |
452 global.XMLHttpRequest = this["_origXMLHttpRequest" + module]; | 452 global.XMLHttpRequest = this["_origXMLHttpRequest" + module]; |
453 delete this["_origXMLHttpRequest" + module]; | 453 delete this["_origXMLHttpRequest" + module]; |
454 } | 454 } |
455 } | 455 } |
(...skipping 21 matching lines...) Expand all Loading... |
477 table.setAttribute("border", "border"); | 477 table.setAttribute("border", "border"); |
478 | 478 |
479 let header = table.insertRow(-1); | 479 let header = table.insertRow(-1); |
480 header.style.fontWeight = "bold"; | 480 header.style.fontWeight = "bold"; |
481 header.insertCell(-1).textContent = "Function name"; | 481 header.insertCell(-1).textContent = "Function name"; |
482 header.insertCell(-1).textContent = "Call count"; | 482 header.insertCell(-1).textContent = "Call count"; |
483 header.insertCell(-1).textContent = "Min execution time (total/own)"; | 483 header.insertCell(-1).textContent = "Min execution time (total/own)"; |
484 header.insertCell(-1).textContent = "Max execution time (total/own)"; | 484 header.insertCell(-1).textContent = "Max execution time (total/own)"; |
485 header.insertCell(-1).textContent = "Total execution time (total/own)"; | 485 header.insertCell(-1).textContent = "Total execution time (total/own)"; |
486 | 486 |
487 for each (let script in scripts) | 487 for (let script of scripts) |
488 showProfilingDataForScript(script, table); | 488 showProfilingDataForScript(script, table); |
489 | 489 |
490 document.getElementById("display").appendChild(table); | 490 document.getElementById("display").appendChild(table); |
491 } | 491 } |
492 | 492 |
493 function showProfilingDataForScript(script, table) | 493 function showProfilingDataForScript(script, table) |
494 { | 494 { |
495 let functionName = script.functionName; | 495 let functionName = script.functionName; |
496 if (functionName == "anonymous") | 496 if (functionName == "anonymous") |
497 functionName = guessFunctionName(script.fileName, script.baseLineNumber); | 497 functionName = guessFunctionName(script.fileName, script.baseLineNumber); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 return oldFinish.apply(this, arguments); | 548 return oldFinish.apply(this, arguments); |
549 } | 549 } |
550 window.addEventListener("unload", function() | 550 window.addEventListener("unload", function() |
551 { | 551 { |
552 debuggerService.off(); | 552 debuggerService.off(); |
553 }, true); | 553 }, true); |
554 debuggerService.on(); | 554 debuggerService.on(); |
555 debuggerService.flags |= debuggerService.COLLECT_PROFILE_DATA; | 555 debuggerService.flags |= debuggerService.COLLECT_PROFILE_DATA; |
556 debuggerService.clearProfileData(); | 556 debuggerService.clearProfileData(); |
557 } | 557 } |
OLD | NEW |