Name anonymous functions for debugging purposes.
It also makes profiling more convenient.
This commit is contained in:
parent
b8c7030309
commit
2d03f93fed
@ -39,7 +39,7 @@ function load() {
|
|||||||
|
|
||||||
var r = new XMLHttpRequest();
|
var r = new XMLHttpRequest();
|
||||||
r.open('GET', manifestFile, false);
|
r.open('GET', manifestFile, false);
|
||||||
r.onreadystatechange = function(e) {
|
r.onreadystatechange = function loadOnreadystatechange(e) {
|
||||||
if (r.readyState == 4) {
|
if (r.readyState == 4) {
|
||||||
log('done\n');
|
log('done\n');
|
||||||
manifest = JSON.parse(r.responseText);
|
manifest = JSON.parse(r.responseText);
|
||||||
@ -62,7 +62,7 @@ function nextTask() {
|
|||||||
var r = new XMLHttpRequest();
|
var r = new XMLHttpRequest();
|
||||||
r.open('GET', task.file);
|
r.open('GET', task.file);
|
||||||
r.mozResponseType = r.responseType = 'arraybuffer';
|
r.mozResponseType = r.responseType = 'arraybuffer';
|
||||||
r.onreadystatechange = function() {
|
r.onreadystatechange = function nextTaskOnreadystatechange() {
|
||||||
var failure;
|
var failure;
|
||||||
if (r.readyState == 4) {
|
if (r.readyState == 4) {
|
||||||
var data = r.mozResponseArrayBuffer || r.mozResponse ||
|
var data = r.mozResponseArrayBuffer || r.mozResponse ||
|
||||||
@ -85,11 +85,15 @@ function isLastPage(task) {
|
|||||||
return (task.pageNum > task.pdfDoc.numPages);
|
return (task.pageNum > task.pdfDoc.numPages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function canvasToDataURL() {
|
||||||
|
return canvas.toDataURL('image/png');
|
||||||
|
}
|
||||||
|
|
||||||
function nextPage(task, loadError) {
|
function nextPage(task, loadError) {
|
||||||
var failure = loadError || '';
|
var failure = loadError || '';
|
||||||
|
|
||||||
if (!task.pdfDoc) {
|
if (!task.pdfDoc) {
|
||||||
sendTaskResult(canvas.toDataURL('image/png'), task, failure);
|
sendTaskResult(canvasToDataURL(), task, failure);
|
||||||
log('done' + (failure ? ' (failed !: ' + failure + ')' : '') + '\n');
|
log('done' + (failure ? ' (failed !: ' + failure + ')' : '') + '\n');
|
||||||
++currentTaskIdx;
|
++currentTaskIdx;
|
||||||
nextTask();
|
nextTask();
|
||||||
@ -126,7 +130,7 @@ function nextPage(task, loadError) {
|
|||||||
|
|
||||||
page.startRendering(
|
page.startRendering(
|
||||||
ctx,
|
ctx,
|
||||||
function(e) {
|
function nextPageStartRendering(e) {
|
||||||
snapshotCurrentPage(task, (!failure && e) ?
|
snapshotCurrentPage(task, (!failure && e) ?
|
||||||
('render : ' + e) : failure);
|
('render : ' + e) : failure);
|
||||||
}
|
}
|
||||||
@ -146,13 +150,13 @@ function nextPage(task, loadError) {
|
|||||||
function snapshotCurrentPage(task, failure) {
|
function snapshotCurrentPage(task, failure) {
|
||||||
log('done, snapshotting... ');
|
log('done, snapshotting... ');
|
||||||
|
|
||||||
sendTaskResult(canvas.toDataURL('image/png'), task, failure);
|
sendTaskResult(canvasToDataURL(), task, failure);
|
||||||
log('done' + (failure ? ' (failed !: ' + failure + ')' : '') + '\n');
|
log('done' + (failure ? ' (failed !: ' + failure + ')' : '') + '\n');
|
||||||
|
|
||||||
// Set up the next request
|
// Set up the next request
|
||||||
var backoff = (inFlightRequests > 0) ? inFlightRequests * 10 : 0;
|
var backoff = (inFlightRequests > 0) ? inFlightRequests * 10 : 0;
|
||||||
setTimeout(
|
setTimeout(
|
||||||
function() {
|
function snapshotCurrentPageSetTimeout() {
|
||||||
++task.pageNum;
|
++task.pageNum;
|
||||||
nextPage(task);
|
nextPage(task);
|
||||||
},
|
},
|
||||||
@ -201,7 +205,7 @@ function sendTaskResult(snapshot, task, failure) {
|
|||||||
// (The POST URI is ignored atm.)
|
// (The POST URI is ignored atm.)
|
||||||
r.open('POST', '/submit_task_results', true);
|
r.open('POST', '/submit_task_results', true);
|
||||||
r.setRequestHeader('Content-Type', 'application/json');
|
r.setRequestHeader('Content-Type', 'application/json');
|
||||||
r.onreadystatechange = function(e) {
|
r.onreadystatechange = function sendTaskResultOnreadystatechange(e) {
|
||||||
if (r.readyState == 4) {
|
if (r.readyState == 4) {
|
||||||
inFlightRequests--;
|
inFlightRequests--;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user