Almost passing gjslint.

This commit is contained in:
Rob Sayre 2011-07-05 23:06:45 -07:00
parent 3ad0c0b654
commit f5a3587dde
13 changed files with 6235 additions and 6120 deletions

View file

@ -1,7 +1,7 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
"use strict";
'use strict';
var JpegStreamProxyCounter = 0;
// WebWorker Proxy for JpegStream.
@ -12,7 +12,7 @@ var JpegStreamProxy = (function() {
// Tell the main thread to create an image.
postMessage({
action: "jpeg_stream",
action: 'jpeg_stream',
data: {
id: this.id,
raw: bytesToString(bytes)
@ -25,7 +25,7 @@ var JpegStreamProxy = (function() {
return this;
},
getChar: function() {
error("internal error: getChar is not valid on JpegStream");
error('internal error: getChar is not valid on JpegStream');
}
};
@ -36,9 +36,9 @@ var JpegStreamProxy = (function() {
// the time, meaning you can't create a gradient, create a second one and then
// use the first one again. As this isn't used in pdf.js right now, it's okay.
function GradientProxy(cmdQueue, x0, y0, x1, y1) {
cmdQueue.push(["$createLinearGradient", [x0, y0, x1, y1]]);
cmdQueue.push(['$createLinearGradient', [x0, y0, x1, y1]]);
this.addColorStop = function(i, rgba) {
cmdQueue.push(["$addColorStop", [i, rgba]]);
cmdQueue.push(['$addColorStop', [i, rgba]]);
}
}
@ -47,15 +47,15 @@ var patternProxyCounter = 0;
function PatternProxy(cmdQueue, object, kind) {
this.id = patternProxyCounter++;
if (!(object instanceof CanvasProxy) ) {
throw "unkown type to createPattern";
if (!(object instanceof CanvasProxy)) {
throw 'unkown type to createPattern';
}
// Flush the object here to ensure it's available on the main thread.
// TODO: Make some kind of dependency management, such that the object
// gets flushed only if needed.
object.flush();
cmdQueue.push(["$createPatternFromCanvas", [this.id, object.id, kind]]);
cmdQueue.push(['$createPatternFromCanvas', [this.id, object.id, kind]]);
}
var canvasProxyCounter = 0;
@ -68,8 +68,8 @@ function CanvasProxy(width, height) {
// Dummy context that gets exposed.
var ctx = {};
this.getContext = function(type) {
if (type != "2d") {
throw "CanvasProxy can only provide a 2d context.";
if (type != '2d') {
throw 'CanvasProxy can only provide a 2d context.';
}
return ctx;
}
@ -82,45 +82,45 @@ function CanvasProxy(width, height) {
// Setup function calls to `ctx`.
var ctxFunc = [
"createRadialGradient",
"arcTo",
"arc",
"fillText",
"strokeText",
"createImageData",
"drawWindow",
"save",
"restore",
"scale",
"rotate",
"translate",
"transform",
"setTransform",
"clearRect",
"fillRect",
"strokeRect",
"beginPath",
"closePath",
"moveTo",
"lineTo",
"quadraticCurveTo",
"bezierCurveTo",
"rect",
"fill",
"stroke",
"clip",
"measureText",
"isPointInPath",
'createRadialGradient',
'arcTo',
'arc',
'fillText',
'strokeText',
'createImageData',
'drawWindow',
'save',
'restore',
'scale',
'rotate',
'translate',
'transform',
'setTransform',
'clearRect',
'fillRect',
'strokeRect',
'beginPath',
'closePath',
'moveTo',
'lineTo',
'quadraticCurveTo',
'bezierCurveTo',
'rect',
'fill',
'stroke',
'clip',
'measureText',
'isPointInPath',
// These functions are necessary to track the rendering currentX state.
// The exact values can be computed on the main thread only, as the
// worker has no idea about text width.
"$setCurrentX",
"$addCurrentX",
"$saveCurrentX",
"$restoreCurrentX",
"$showText",
"$setFont"
'$setCurrentX',
'$addCurrentX',
'$saveCurrentX',
'$restoreCurrentX',
'$showText',
'$setFont'
];
function buildFuncCall(name) {
@ -154,53 +154,54 @@ function CanvasProxy(width, height) {
}
ctx.putImageData = function(data, x, y, width, height) {
cmdQueue.push(["$putImageData", [data, x, y, width, height]]);
cmdQueue.push(['$putImageData', [data, x, y, width, height]]);
}
ctx.drawImage = function(image, x, y, width, height, sx, sy, swidth, sheight) {
ctx.drawImage = function(image, x, y, width, height,
sx, sy, swidth, sheight) {
if (image instanceof CanvasProxy) {
// Send the image/CanvasProxy to the main thread.
image.flush();
cmdQueue.push(["$drawCanvas", [image.id, x, y, sx, sy, swidth, sheight]]);
} else if(image instanceof JpegStreamProxy) {
cmdQueue.push(["$drawImage", [image.id, x, y, sx, sy, swidth, sheight]])
cmdQueue.push(['$drawCanvas', [image.id, x, y, sx, sy, swidth, sheight]]);
} else if (image instanceof JpegStreamProxy) {
cmdQueue.push(['$drawImage', [image.id, x, y, sx, sy, swidth, sheight]]);
} else {
throw "unkown type to drawImage";
throw 'unkown type to drawImage';
}
}
// Setup property access to `ctx`.
var ctxProp = {
// "canvas"
"globalAlpha": "1",
"globalCompositeOperation": "source-over",
"strokeStyle": "#000000",
"fillStyle": "#000000",
"lineWidth": "1",
"lineCap": "butt",
"lineJoin": "miter",
"miterLimit": "10",
"shadowOffsetX": "0",
"shadowOffsetY": "0",
"shadowBlur": "0",
"shadowColor": "rgba(0, 0, 0, 0)",
"font": "10px sans-serif",
"textAlign": "start",
"textBaseline": "alphabetic",
"mozTextStyle": "10px sans-serif",
"mozImageSmoothingEnabled": "true"
}
'globalAlpha': '1',
'globalCompositeOperation': 'source-over',
'strokeStyle': '#000000',
'fillStyle': '#000000',
'lineWidth': '1',
'lineCap': 'butt',
'lineJoin': 'miter',
'miterLimit': '10',
'shadowOffsetX': '0',
'shadowOffsetY': '0',
'shadowBlur': '0',
'shadowColor': 'rgba(0, 0, 0, 0)',
'font': '10px sans-serif',
'textAlign': 'start',
'textBaseline': 'alphabetic',
'mozTextStyle': '10px sans-serif',
'mozImageSmoothingEnabled': 'true'
};
function buildGetter(name) {
return function() {
return ctx["$" + name];
return ctx['$' + name];
}
}
function buildSetter(name) {
return function(value) {
cmdQueue.push(["$", name, value]);
return ctx["$" + name] = value;
cmdQueue.push(['$', name, value]);
return ctx['$' + name] = value;
}
}
@ -209,23 +210,23 @@ function CanvasProxy(width, height) {
function buildSetterStyle(name) {
return function(value) {
if (value instanceof GradientProxy) {
cmdQueue.push(["$" + name + "Gradient"]);
cmdQueue.push(['$' + name + 'Gradient']);
} else if (value instanceof PatternProxy) {
cmdQueue.push(["$" + name + "Pattern", [value.id]]);
cmdQueue.push(['$' + name + 'Pattern', [value.id]]);
} else {
cmdQueue.push(["$", name, value]);
return ctx["$" + name] = value;
cmdQueue.push(['$', name, value]);
return ctx['$' + name] = value;
}
}
}
for (var name in ctxProp) {
ctx["$" + name] = ctxProp[name];
ctx['$' + name] = ctxProp[name];
ctx.__defineGetter__(name, buildGetter(name));
// Special treatment for `fillStyle` and `strokeStyle`: The passed style
// might be a gradient. Need to check for that.
if (name == "fillStyle" || name == "strokeStyle") {
if (name == 'fillStyle' || name == 'strokeStyle') {
ctx.__defineSetter__(name, buildSetterStyle(name));
} else {
ctx.__defineSetter__(name, buildSetter(name));
@ -239,13 +240,13 @@ function CanvasProxy(width, height) {
*/
CanvasProxy.prototype.flush = function() {
postMessage({
action: "canvas_proxy_cmd_queue",
action: 'canvas_proxy_cmd_queue',
data: {
id: this.id,
cmdQueue: this.cmdQueue,
width: this.width,
height: this.height
id: this.id,
cmdQueue: this.cmdQueue,
width: this.width,
height: this.height
}
});
this.cmdQueue.length = 0;
}
};