Merge pull request #612 from kkujala/master

Name anonymous functions.
This commit is contained in:
Artur Adib 2011-10-04 14:38:24 -07:00
commit ab89d8aa20
5 changed files with 66 additions and 66 deletions

View File

@ -62,7 +62,7 @@ function loadDocument(aWindow, aDocumentUrl) {
} }
let WebProgressListener = { let WebProgressListener = {
init: function(aWindow, aUrl) { init: function WebProgressListenerInit(aWindow, aUrl) {
this._locationHasChanged = false; this._locationHasChanged = false;
this._documentUrl = aUrl; this._documentUrl = aUrl;

View File

@ -232,7 +232,7 @@ function readFontIndexData(aStream, aIsByte) {
return objects; return objects;
} }
var Type2Parser = function(aFilePath) { var Type2Parser = function type2Parser(aFilePath) {
var font = new Dict(); var font = new Dict();
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
@ -292,7 +292,7 @@ var Type2Parser = function(aFilePath) {
} }
} }
this.parse = function(aStream) { this.parse = function type2ParserParse(aStream) {
font.set('major', aStream.getByte()); font.set('major', aStream.getByte());
font.set('minor', aStream.getByte()); font.set('minor', aStream.getByte());
font.set('hdrSize', aStream.getByte()); font.set('hdrSize', aStream.getByte());

View File

@ -4,7 +4,7 @@
'use strict'; 'use strict';
// Checking if the typed arrays are supported // Checking if the typed arrays are supported
(function() { (function checkTypedArrayCompatibility() {
if (typeof Uint8Array !== 'undefined') if (typeof Uint8Array !== 'undefined')
return; return;
@ -12,7 +12,7 @@
return this.slice(start, end); return this.slice(start, end);
} }
function set_function(array, offset) { function setArrayOffset(array, offset) {
if (arguments.length < 2) if (arguments.length < 2)
offset = 0; offset = 0;
for (var i = 0, n = array.length; i < n; ++i, ++offset) for (var i = 0, n = array.length; i < n; ++i, ++offset)
@ -31,7 +31,7 @@
result.subarray = subarray; result.subarray = subarray;
result.buffer = result; result.buffer = result;
result.byteLength = result.length; result.byteLength = result.length;
result.set = set_function; result.set = setArrayOffset;
if (typeof arg1 === 'object' && arg1.buffer) if (typeof arg1 === 'object' && arg1.buffer)
result.buffer = arg1.buffer; result.buffer = arg1.buffer;
@ -49,31 +49,31 @@
})(); })();
// Object.create() ? // Object.create() ?
(function() { (function checkObjectCreateCompatibility() {
if (typeof Object.create !== 'undefined') if (typeof Object.create !== 'undefined')
return; return;
Object.create = function(proto) { Object.create = function objectCreate(proto) {
var constructor = function() {}; var constructor = function objectCreateConstructor() {};
constructor.prototype = proto; constructor.prototype = proto;
return new constructor(); return new constructor();
}; };
})(); })();
// Object.defineProperty() ? // Object.defineProperty() ?
(function() { (function checkObjectDefinePropertyCompatibility() {
if (typeof Object.defineProperty !== 'undefined') if (typeof Object.defineProperty !== 'undefined')
return; return;
Object.defineProperty = function(obj, name, def) { Object.defineProperty = function objectDefineProperty(obj, name, def) {
delete obj[name]; delete obj[name];
if ('get' in def) if ('get' in def)
obj.__defineGetter__(name, def['get']); obj.__defineGetter__(name, def['get']);
if ('set' in def) if ('set' in def)
obj.__defineSetter__(name, def['set']); obj.__defineSetter__(name, def['set']);
if ('value' in def) { if ('value' in def) {
obj.__defineSetter__(name, function(value) { obj.__defineSetter__(name, function objectDefinePropertySetter(value) {
this.__defineGetter__(name, function() { this.__defineGetter__(name, function objectDefinePropertyGetter() {
return value; return value;
}); });
return value; return value;
@ -84,7 +84,7 @@
})(); })();
// No XMLHttpRequest.response ? // No XMLHttpRequest.response ?
(function() { (function checkXMLHttpRequestResponseCompatibility() {
var xhrPrototype = XMLHttpRequest.prototype; var xhrPrototype = XMLHttpRequest.prototype;
if ('response' in xhrPrototype || if ('response' in xhrPrototype ||
'mozResponseArrayBuffer' in xhrPrototype || 'mozResponseArrayBuffer' in xhrPrototype ||
@ -94,7 +94,7 @@
// IE ? // IE ?
if (typeof VBArray !== 'undefined') { if (typeof VBArray !== 'undefined') {
Object.defineProperty(xhrPrototype, 'response', { Object.defineProperty(xhrPrototype, 'response', {
get: function() { get: function xmlHttpRequestResponseGet() {
return new Uint8Array(new VBArray(this.responseBody).toArray()); return new Uint8Array(new VBArray(this.responseBody).toArray());
} }
}); });
@ -122,14 +122,14 @@
})(); })();
// window.btoa (base64 encode function) ? // window.btoa (base64 encode function) ?
(function() { (function checkWindowBtoaCompatibility() {
if ('btoa' in window) if ('btoa' in window)
return; return;
var digits = var digits =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
window.btoa = function(chars) { window.btoa = function windowBtoa(chars) {
var buffer = ''; var buffer = '';
var i, n; var i, n;
for (i = 0, n = chars.length; i < n; i += 3) { for (i = 0, n = chars.length; i < n; i += 3) {
@ -147,13 +147,13 @@
})(); })();
// Function.prototype.bind ? // Function.prototype.bind ?
(function() { (function checkFunctionPrototypeBindCompatibility() {
if (typeof Function.prototype.bind !== 'undefined') if (typeof Function.prototype.bind !== 'undefined')
return; return;
Function.prototype.bind = function(obj) { Function.prototype.bind = function functionPrototypeBind(obj) {
var fn = this, headArgs = Array.prototype.slice.call(arguments, 1); var fn = this, headArgs = Array.prototype.slice.call(arguments, 1);
var bound = function() { var bound = function functionPrototypeBindBound() {
var args = Array.prototype.concat.apply(headArgs, arguments); var args = Array.prototype.concat.apply(headArgs, arguments);
return fn.apply(obj, args); return fn.apply(obj, args);
}; };
@ -162,15 +162,15 @@
})(); })();
// IE9 text/html data URI // IE9 text/html data URI
(function() { (function checkDocumentDocumentModeCompatibility() {
if (document.documentMode !== 9) if (document.documentMode !== 9)
return; return;
// overriding the src property // overriding the src property
var originalSrcDescriptor = Object.getOwnPropertyDescriptor( var originalSrcDescriptor = Object.getOwnPropertyDescriptor(
HTMLIFrameElement.prototype, 'src'); HTMLIFrameElement.prototype, 'src');
Object.defineProperty(HTMLIFrameElement.prototype, 'src', { Object.defineProperty(HTMLIFrameElement.prototype, 'src', {
get: function() { return this.$src; }, get: function htmlIFrameElementPrototypeSrcGet() { return this.$src; },
set: function(src) { set: function htmlIFrameElementPrototypeSrcSet(src) {
this.$src = src; this.$src = src;
if (src.substr(0, 14) != 'data:text/html') { if (src.substr(0, 14) != 'data:text/html') {
originalSrcDescriptor.set.call(this, src); originalSrcDescriptor.set.call(this, src);
@ -179,7 +179,7 @@
// for text/html, using blank document and then // for text/html, using blank document and then
// document's open, write, and close operations // document's open, write, and close operations
originalSrcDescriptor.set.call(this, 'about:blank'); originalSrcDescriptor.set.call(this, 'about:blank');
setTimeout((function() { setTimeout((function htmlIFrameElementPrototypeSrcOpenWriteClose() {
var doc = this.contentDocument; var doc = this.contentDocument;
doc.open('text/html'); doc.open('text/html');
doc.write(src.substr(src.indexOf(',') + 1)); doc.write(src.substr(src.indexOf(',') + 1));
@ -189,3 +189,4 @@
enumerable: true enumerable: true
}); });
})(); })();

View File

@ -13,9 +13,9 @@ var kMinScale = 0.25;
var kMaxScale = 4.0; var kMaxScale = 4.0;
var Cache = function(size) { var Cache = function cacheCache(size) {
var data = []; var data = [];
this.push = function(view) { this.push = function cachePush(view) {
data.push(view); data.push(view);
if (data.length > size) if (data.length > size)
data.shift().update(); data.shift().update();
@ -31,7 +31,7 @@ var PDFView = {
currentScale: kDefaultScale, currentScale: kDefaultScale,
initialBookmark: document.location.hash.substring(1), initialBookmark: document.location.hash.substring(1),
setScale: function(val, resetAutoSettings) { setScale: function pdfViewSetScale(val, resetAutoSettings) {
var pages = this.pages; var pages = this.pages;
for (var i = 0; i < pages.length; i++) for (var i = 0; i < pages.length; i++)
pages[i].update(val * kCssUnits); pages[i].update(val * kCssUnits);
@ -47,7 +47,7 @@ var PDFView = {
window.dispatchEvent(event); window.dispatchEvent(event);
}, },
parseScale: function(value, resetAutoSettings) { parseScale: function pdfViewParseScale(value, resetAutoSettings) {
if ('custom' == value) if ('custom' == value)
return; return;
@ -72,12 +72,12 @@ var PDFView = {
} }
}, },
zoomIn: function() { zoomIn: function pdfViewZoomIn() {
var newScale = Math.min(kMaxScale, this.currentScale * kDefaultScaleDelta); var newScale = Math.min(kMaxScale, this.currentScale * kDefaultScaleDelta);
this.setScale(newScale, true); this.setScale(newScale, true);
}, },
zoomOut: function() { zoomOut: function pdfViewZoomOut() {
var newScale = Math.max(kMinScale, this.currentScale / kDefaultScaleDelta); var newScale = Math.max(kMinScale, this.currentScale / kDefaultScaleDelta);
this.setScale(newScale, true); this.setScale(newScale, true);
}, },
@ -104,7 +104,7 @@ var PDFView = {
return currentPageNumber; return currentPageNumber;
}, },
open: function(url, scale) { open: function pdfViewOpen(url, scale) {
if (url.indexOf('http') == 0) if (url.indexOf('http') == 0)
return; return;
@ -124,7 +124,7 @@ var PDFView = {
}); });
}, },
navigateTo: function(dest) { navigateTo: function pdfViewNavigateTo(dest) {
if (typeof dest === 'string') if (typeof dest === 'string')
dest = this.destinations[dest]; dest = this.destinations[dest];
if (!(dest instanceof Array)) if (!(dest instanceof Array))
@ -140,7 +140,7 @@ var PDFView = {
} }
}, },
getDestinationHash: function(dest) { getDestinationHash: function pdfViewGetDestinationHash(dest) {
if (typeof dest === 'string') if (typeof dest === 'string')
return '#' + escape(dest); return '#' + escape(dest);
if (dest instanceof Array) { if (dest instanceof Array) {
@ -155,18 +155,18 @@ var PDFView = {
return ''; return '';
}, },
error: function() { error: function pdfViewError() {
var loadingIndicator = document.getElementById('loading'); var loadingIndicator = document.getElementById('loading');
loadingIndicator.innerHTML = 'Error'; loadingIndicator.innerHTML = 'Error';
}, },
progress: function(level) { progress: function pdfViewProgress(level) {
var percent = Math.round(level * 100); var percent = Math.round(level * 100);
var loadingIndicator = document.getElementById('loading'); var loadingIndicator = document.getElementById('loading');
loadingIndicator.innerHTML = 'Loading... ' + percent + '%'; loadingIndicator.innerHTML = 'Loading... ' + percent + '%';
}, },
load: function(data, scale) { load: function pdfViewLoad(data, scale) {
var loadingIndicator = document.getElementById('loading'); var loadingIndicator = document.getElementById('loading');
loadingIndicator.style.display = 'none'; loadingIndicator.style.display = 'none';
@ -218,7 +218,7 @@ var PDFView = {
this.page = 1; this.page = 1;
}, },
setHash: function(hash) { setHash: function pdfViewSetHash(hash) {
if (!hash) if (!hash)
return; return;
@ -233,7 +233,7 @@ var PDFView = {
PDFView.navigateTo(unescape(hash)); PDFView.navigateTo(unescape(hash));
}, },
switchSidebarView: function(view) { switchSidebarView: function pdfViewSwitchSidebarView(view) {
var thumbsScrollView = document.getElementById('sidebarScrollView'); var thumbsScrollView = document.getElementById('sidebarScrollView');
var outlineScrollView = document.getElementById('outlineScrollView'); var outlineScrollView = document.getElementById('outlineScrollView');
var thumbsSwitchButton = document.getElementById('thumbsSwitch'); var thumbsSwitchButton = document.getElementById('thumbsSwitch');
@ -254,7 +254,7 @@ var PDFView = {
} }
}, },
getVisiblePages: function() { getVisiblePages: function pdfViewGetVisiblePages() {
var pages = this.pages; var pages = this.pages;
var kBottomMargin = 10; var kBottomMargin = 10;
var visiblePages = []; var visiblePages = [];
@ -282,7 +282,7 @@ var PDFView = {
} }
}; };
var PageView = function(container, content, id, pageWidth, pageHeight, var PageView = function pageView(container, content, id, pageWidth, pageHeight,
stats, navigateTo) { stats, navigateTo) {
this.id = id; this.id = id;
this.content = content; this.content = content;
@ -303,7 +303,7 @@ var PageView = function(container, content, id, pageWidth, pageHeight,
container.appendChild(anchor); container.appendChild(anchor);
container.appendChild(div); container.appendChild(div);
this.update = function(scale) { this.update = function pageViewUpdate(scale) {
this.scale = scale || this.scale; this.scale = scale || this.scale;
div.style.width = (this.width * this.scale) + 'px'; div.style.width = (this.width * this.scale) + 'px';
div.style.height = (this.height * this.scale) + 'px'; div.style.height = (this.height * this.scale) + 'px';
@ -316,7 +316,7 @@ var PageView = function(container, content, id, pageWidth, pageHeight,
function setupLinks(content, scale) { function setupLinks(content, scale) {
function bindLink(link, dest) { function bindLink(link, dest) {
link.href = PDFView.getDestinationHash(dest); link.href = PDFView.getDestinationHash(dest);
link.onclick = function() { link.onclick = function pageViewSetupLinksOnclick() {
if (dest) if (dest)
PDFView.navigateTo(dest); PDFView.navigateTo(dest);
return false; return false;
@ -337,7 +337,7 @@ var PageView = function(container, content, id, pageWidth, pageHeight,
} }
} }
this.scrollIntoView = function(dest) { this.scrollIntoView = function pageViewScrollIntoView(dest) {
if (!dest) { if (!dest) {
div.scrollIntoView(true); div.scrollIntoView(true);
return; return;
@ -389,7 +389,7 @@ var PageView = function(container, content, id, pageWidth, pageHeight,
if (scale) if (scale)
PDFView.setScale(scale, true); PDFView.setScale(scale, true);
setTimeout(function() { setTimeout(function pageViewScrollIntoViewRelayout() {
// letting page to re-layout before scrolling // letting page to re-layout before scrolling
var scale = PDFView.currentScale; var scale = PDFView.currentScale;
var x = Math.min(boundingRect[0].x, boundingRect[1].x); var x = Math.min(boundingRect[0].x, boundingRect[1].x);
@ -410,7 +410,7 @@ var PageView = function(container, content, id, pageWidth, pageHeight,
}, 0); }, 0);
}; };
this.draw = function() { this.draw = function pageviewDraw() {
if (div.hasChildNodes()) { if (div.hasChildNodes()) {
this.updateStats(); this.updateStats();
return false; return false;
@ -441,7 +441,7 @@ var PageView = function(container, content, id, pageWidth, pageHeight,
return true; return true;
}; };
this.updateStats = function() { this.updateStats = function pageViewUpdateStats() {
var t1 = stats.compile, t2 = stats.fonts, t3 = stats.render; var t1 = stats.compile, t2 = stats.fonts, t3 = stats.render;
var str = 'Time to compile/fonts/render: ' + var str = 'Time to compile/fonts/render: ' +
(t1 - stats.begin) + '/' + (t2 - t1) + '/' + (t3 - t2) + ' ms'; (t1 - stats.begin) + '/' + (t2 - t1) + '/' + (t3 - t2) + ' ms';
@ -449,7 +449,7 @@ var PageView = function(container, content, id, pageWidth, pageHeight,
}; };
}; };
var ThumbnailView = function(container, page, id, pageRatio) { var ThumbnailView = function thumbnailView(container, page, id, pageRatio) {
var anchor = document.createElement('a'); var anchor = document.createElement('a');
anchor.href = '#' + id; anchor.href = '#' + id;
anchor.onclick = function stopNivigation() { anchor.onclick = function stopNivigation() {
@ -464,7 +464,7 @@ var ThumbnailView = function(container, page, id, pageRatio) {
anchor.appendChild(div); anchor.appendChild(div);
container.appendChild(anchor); container.appendChild(anchor);
this.draw = function() { this.draw = function thumbnailViewDraw() {
if (div.hasChildNodes()) if (div.hasChildNodes())
return; return;
@ -495,16 +495,16 @@ var ThumbnailView = function(container, page, id, pageRatio) {
div.style.height = (view.height * scaleY) + 'px'; div.style.height = (view.height * scaleY) + 'px';
div.style.lineHeight = (view.height * scaleY) + 'px'; div.style.lineHeight = (view.height * scaleY) + 'px';
page.startRendering(ctx, function() { }); page.startRendering(ctx, function thumbnailViewDrawStartRendering() {});
}; };
}; };
var DocumentOutlineView = function(outline) { var DocumentOutlineView = function documentOutlineView(outline) {
var outlineView = document.getElementById('outlineView'); var outlineView = document.getElementById('outlineView');
function bindItemLink(domObj, item) { function bindItemLink(domObj, item) {
domObj.href = PDFView.getDestinationHash(item.dest); domObj.href = PDFView.getDestinationHash(item.dest);
domObj.onclick = function(e) { domObj.onclick = function documentOutlineViewOnclick(e) {
PDFView.navigateTo(item.dest); PDFView.navigateTo(item.dest);
return false; return false;
}; };
@ -535,7 +535,7 @@ var DocumentOutlineView = function(outline) {
} }
}; };
window.addEventListener('load', function(evt) { window.addEventListener('load', function webViewerLoad(evt) {
var params = document.location.search.substring(1).split('&'); var params = document.location.search.substring(1).split('&');
for (var i = 0; i < params.length; i++) { for (var i = 0; i < params.length; i++) {
var param = params[i].split('='); var param = params[i].split('=');
@ -550,15 +550,15 @@ window.addEventListener('load', function(evt) {
document.getElementById('fileInput').value = null; document.getElementById('fileInput').value = null;
}, true); }, true);
window.addEventListener('pdfload', function(evt) { window.addEventListener('pdfload', function webViewerPdfload(evt) {
PDFView.load(evt.detail); PDFView.load(evt.detail);
}, true); }, true);
window.addEventListener('pdfprogress', function(evt) { window.addEventListener('pdfprogress', function webViewerPdfProgress(evt) {
PDFView.progress(evt.detail); PDFView.progress(evt.detail);
}, true); }, true);
window.addEventListener('pdferror', function(evt) { window.addEventListener('pdferror', function webViewerPdfError(evt) {
PDFView.error(); PDFView.error();
}, true); }, true);
@ -582,29 +582,29 @@ function updateViewarea() {
PDFView.page = firstPage.id; PDFView.page = firstPage.id;
} }
window.addEventListener('scroll', function onscroll(evt) { window.addEventListener('scroll', function webViewerScroll(evt) {
updateViewarea(); updateViewarea();
}, true); }, true);
window.addEventListener('resize', function onscroll(evt) { window.addEventListener('resize', function webViewerResize(evt) {
if (document.getElementById('pageWidthOption').selected || if (document.getElementById('pageWidthOption').selected ||
document.getElementById('pageFitOption').selected) document.getElementById('pageFitOption').selected)
PDFView.parseScale(document.getElementById('scaleSelect').value); PDFView.parseScale(document.getElementById('scaleSelect').value);
updateViewarea(); updateViewarea();
}); });
window.addEventListener('hashchange', function(evt) { window.addEventListener('hashchange', function webViewerHashchange(evt) {
PDFView.setHash(document.location.hash.substring(1)); PDFView.setHash(document.location.hash.substring(1));
}); });
window.addEventListener('change', function(evt) { window.addEventListener('change', function webViewerChange(evt) {
var files = evt.target.files; var files = evt.target.files;
if (!files || files.length == 0) if (!files || files.length == 0)
return; return;
// Read the local file into a Uint8Array. // Read the local file into a Uint8Array.
var fileReader = new FileReader(); var fileReader = new FileReader();
fileReader.onload = function(evt) { fileReader.onload = function webViewerChangeFileReaderOnload(evt) {
var data = evt.target.result; var data = evt.target.result;
var buffer = new ArrayBuffer(data.length); var buffer = new ArrayBuffer(data.length);
var uint8Array = new Uint8Array(buffer); var uint8Array = new Uint8Array(buffer);
@ -622,7 +622,7 @@ window.addEventListener('change', function(evt) {
document.title = file.name; document.title = file.name;
}, true); }, true);
window.addEventListener('transitionend', function(evt) { window.addEventListener('transitionend', function webViewerTransitionend(evt) {
var pageIndex = 0; var pageIndex = 0;
var pagesCount = PDFView.pages.length; var pagesCount = PDFView.pages.length;

View File

@ -9,16 +9,15 @@
var pdfDoc; var pdfDoc;
window.onload = function() { window.onload = function webViewerWorkerOnload() {
window.canvas = document.getElementById("canvas"); window.canvas = document.getElementById("canvas");
window.ctx = canvas.getContext("2d"); window.ctx = canvas.getContext("2d");
pdfDoc = new WorkerPDFDoc(window.canvas); pdfDoc = new WorkerPDFDoc(window.canvas);
pdfDoc.onChangePage = function(numPage) { pdfDoc.onChangePage = function webViewerWorkerOnChangePage(numPage) {
document.getElementById("pageNumber").value = numPage; document.getElementById("pageNumber").value = numPage;
} }
// pdfDoc.open("canvas.pdf", function() { pdfDoc.open("compressed.tracemonkey-pldi-09.pdf", function webViewerWorkerOpen() {
pdfDoc.open("compressed.tracemonkey-pldi-09.pdf", function() {
document.getElementById("numPages").innerHTML = "/" + pdfDoc.numPages; document.getElementById("numPages").innerHTML = "/" + pdfDoc.numPages;
}) })
} }