Name anonymous functions in worker.js.

This commit is contained in:
Kalervo Kujala 2011-10-28 21:23:30 +03:00
parent 7e6a589074
commit 068e77bdec

View File

@ -8,14 +8,14 @@ function MessageHandler(name, comObj) {
this.comObj = comObj; this.comObj = comObj;
var ah = this.actionHandler = {}; var ah = this.actionHandler = {};
ah['console_log'] = [function(data) { ah['console_log'] = [function ahConsoleLog(data) {
console.log.apply(console, data); console.log.apply(console, data);
}]; }];
ah['console_error'] = [function(data) { ah['console_error'] = [function ahConsoleError(data) {
console.error.apply(console, data); console.error.apply(console, data);
}]; }];
comObj.onmessage = function(event) { comObj.onmessage = function messageHandlerComObjOnMessage(event) {
var data = event.data; var data = event.data;
if (data.action in ah) { if (data.action in ah) {
var action = ah[data.action]; var action = ah[data.action];
@ -27,15 +27,15 @@ function MessageHandler(name, comObj) {
} }
MessageHandler.prototype = { MessageHandler.prototype = {
on: function(actionName, handler, scope) { on: function messageHandlerOn(actionName, handler, scope) {
var ah = this.actionHandler; var ah = this.actionHandler;
if (ah[actionName]) { if (ah[actionName]) {
throw "There is already an actionName called '" + actionName + "'"; throw 'There is already an actionName called "' + actionName + '"';
} }
ah[actionName] = [handler, scope]; ah[actionName] = [handler, scope];
}, },
send: function(actionName, data) { send: function messageHandlerSend(actionName, data) {
this.comObj.postMessage({ this.comObj.postMessage({
action: actionName, action: actionName,
data: data data: data
@ -44,16 +44,16 @@ MessageHandler.prototype = {
}; };
var WorkerProcessorHandler = { var WorkerProcessorHandler = {
setup: function(handler) { setup: function wphSetup(handler) {
var pdfDoc = null; var pdfDoc = null;
handler.on('doc', function(data) { handler.on('doc', function wphSetupDoc(data) {
// Create only the model of the PDFDoc, which is enough for // Create only the model of the PDFDoc, which is enough for
// processing the content of the pdf. // processing the content of the pdf.
pdfDoc = new PDFDocModel(new Stream(data)); pdfDoc = new PDFDocModel(new Stream(data));
}); });
handler.on('page_request', function(pageNum) { handler.on('page_request', function wphSetupPageRequest(pageNum) {
pageNum = parseInt(pageNum); pageNum = parseInt(pageNum);
var page = pdfDoc.getPage(pageNum); var page = pdfDoc.getPage(pageNum);
@ -89,7 +89,7 @@ var WorkerProcessorHandler = {
}); });
}, this); }, this);
handler.on('font', function(data) { handler.on('font', function wphSetupFont(data) {
var objId = data[0]; var objId = data[0];
var name = data[1]; var name = data[1];
var file = data[2]; var file = data[2];
@ -159,11 +159,11 @@ var workerConsole = {
}); });
}, },
time: function(name) { time: function time(name) {
consoleTimer[name] = Date.now(); consoleTimer[name] = Date.now();
}, },
timeEnd: function(name) { timeEnd: function timeEnd(name) {
var time = consoleTimer[name]; var time = consoleTimer[name];
if (time == null) { if (time == null) {
throw 'Unkown timer name ' + name; throw 'Unkown timer name ' + name;