Browse Source

Merge pull request #7942 from yurydelendik/rm-deadcode

Fixes preprocessor testing and adds deadcode removal.
Jonas Jenwald 8 years ago committed by GitHub
parent
commit
ca0ebdfa56
  1. 16
      external/builder/fixtures_esprima/blocks-expected.js
  2. 38
      external/builder/fixtures_esprima/comments-expected.js
  3. 13
      external/builder/fixtures_esprima/deadcode-expected.js
  4. 25
      external/builder/fixtures_esprima/deadcode.js
  5. 4
      external/builder/fixtures_esprima/evals-expected.js
  6. 10
      external/builder/fixtures_esprima/ifs-expected.js
  7. 40
      external/builder/preprocessor2.js
  8. 30
      src/display/font_loader.js
  9. 66
      web/pdf_page_view.js

16
external/builder/fixtures_esprima/blocks-expected.js vendored

@ -1,10 +1,10 @@
function test() { function test() {
"test"; "test";
"1"; "1";
"2"; "2";
"3"; "3";
if ("test") { if ("test") {
"5"; "5";
} }
"4"; "4";
} }

38
external/builder/fixtures_esprima/comments-expected.js vendored

@ -1,28 +1,28 @@
function f1() { function f1() {
/* head */ /* head */
"1"; "1";
/* mid */ /* mid */
"2"; "2";
} }
/* tail */ /* tail */
function f2() { function f2() {
// head // head
"1"; "1";
// mid // mid
"2"; "2";
} }
// tail // tail
function f2() { function f2() {
if ("1") { if ("1") {
// begin block // begin block
"1"; "1";
}
"2";
// trailing
if (/* s */
"3")
/*e*/
{
"4";
} }
"2";
// trailing
if (/* s */
"3")
/*e*/
{
"4";
}
} }

13
external/builder/fixtures_esprima/deadcode-expected.js vendored

@ -0,0 +1,13 @@
function f1() {
}
function f2() {
return 1;
}
function f3() {
var i = 0;
throw "test";
}
function f4() {
var i = 0;
}

25
external/builder/fixtures_esprima/deadcode.js vendored

@ -0,0 +1,25 @@
function f1() {
return;
var i = 0;
}
function f2() {
return 1;
var i = 0;
}
function f3() {
var i = 0;
throw "test";
var j = 0;
}
function f4() {
var i = 0;
if (true) {
return;
}
throw "test";
var j = 0;
}

4
external/builder/fixtures_esprima/evals-expected.js vendored

@ -5,8 +5,8 @@ var d = false;
var e = true; var e = true;
var f = 'text'; var f = 'text';
var g = { var g = {
"obj": { "i": 1 }, "obj": { "i": 1 },
"j": 2 "j": 2
}; };
var h = { 'test': 'test' }; var h = { 'test': 'test' };
var i = '0'; var i = '0';

10
external/builder/fixtures_esprima/ifs-expected.js vendored

@ -1,17 +1,17 @@
if ('test') { if ('test') {
"1"; "1";
} }
{ {
"1"; "1";
} }
{ {
"1"; "1";
} }
; ;
{ {
"2"; "2";
} }
; ;
if ('1') { if ('1') {
"1"; "1";
} }

40
external/builder/preprocessor2.js vendored

@ -169,22 +169,38 @@ function postprocessNode(ctx, node) {
case 'BlockStatement': case 'BlockStatement':
var subExpressionIndex = 0; var subExpressionIndex = 0;
while (subExpressionIndex < node.body.length) { while (subExpressionIndex < node.body.length) {
if (node.body[subExpressionIndex].type === 'EmptyStatement') { switch (node.body[subExpressionIndex].type) {
// Removing empty statements from the blocks. case 'EmptyStatement':
node.body.splice(subExpressionIndex, 1); // Removing empty statements from the blocks.
continue; node.body.splice(subExpressionIndex, 1);
} continue;
if (node.body[subExpressionIndex].type === 'BlockStatement') { case 'BlockStatement':
// Block statements inside a block are moved to the parent one. // Block statements inside a block are moved to the parent one.
var subChildren = node.body[subExpressionIndex].body; var subChildren = node.body[subExpressionIndex].body;
Array.prototype.splice.apply(node.body, Array.prototype.splice.apply(node.body,
[subExpressionIndex, 1].concat(subChildren)); [subExpressionIndex, 1].concat(subChildren));
subExpressionIndex += subChildren.length; subExpressionIndex += Math.max(subChildren.length - 1, 0);
continue; continue;
case 'ReturnStatement':
case 'ThrowStatement':
// Removing dead code after return or throw.
node.body.splice(subExpressionIndex + 1,
node.body.length - subExpressionIndex - 1);
break;
} }
subExpressionIndex++; subExpressionIndex++;
} }
break; break;
case 'FunctionDeclaration':
case 'FunctionExpression':
var block = node.body;
if (block.body.length > 0 &&
block.body[block.body.length - 1].type === 'ReturnStatement' &&
!block.body[block.body.length - 1].argument) {
// Function body ends with return without arg -- removing it.
block.body.pop();
}
break;
} }
return node; return node;
} }

30
src/display/font_loader.js

@ -360,25 +360,25 @@ var FontFaceObject = (function FontFaceObjectClosure() {
} }
FontFaceObject.prototype = { FontFaceObject.prototype = {
createNativeFontFace: function FontFaceObject_createNativeFontFace() { createNativeFontFace: function FontFaceObject_createNativeFontFace() {
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('MOZCENTRAL')) { if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('MOZCENTRAL')) {
if (!this.data) { throw new Error('Not implemented: createNativeFontFace');
return null; }
}
if (this.options.disableFontFace) { if (!this.data) {
this.disableFontFace = true; return null;
return null; }
}
var nativeFontFace = new FontFace(this.loadedName, this.data, {}); if (this.options.disableFontFace) {
this.disableFontFace = true;
return null;
}
if (this.options.fontRegistry) { var nativeFontFace = new FontFace(this.loadedName, this.data, {});
this.options.fontRegistry.registerFont(this);
} if (this.options.fontRegistry) {
return nativeFontFace; this.options.fontRegistry.registerFont(this);
} else { // eslint-disable-line no-else-return
throw new Error('Not implemented: createNativeFontFace');
} }
return nativeFontFace;
}, },
createFontFaceRule: function FontFaceObject_createFontFaceRule() { createFontFaceRule: function FontFaceObject_createFontFaceRule() {

66
web/pdf_page_view.js

@ -624,43 +624,43 @@ var PDFPageView = (function PDFPageViewClosure() {
onRenderContinue: function (cont) { }, onRenderContinue: function (cont) { },
cancel: function () { }, cancel: function () { },
}; };
} else { // eslint-disable-line no-else-return }
var cancelled = false;
var ensureNotCancelled = function () { var cancelled = false;
if (cancelled) { var ensureNotCancelled = function () {
throw 'cancelled'; if (cancelled) {
} throw 'cancelled';
}; }
};
var self = this; var self = this;
var pdfPage = this.pdfPage; var pdfPage = this.pdfPage;
var SVGGraphics = pdfjsLib.SVGGraphics; var SVGGraphics = pdfjsLib.SVGGraphics;
var actualSizeViewport = this.viewport.clone({scale: CSS_UNITS}); var actualSizeViewport = this.viewport.clone({scale: CSS_UNITS});
var promise = pdfPage.getOperatorList().then(function (opList) { var promise = pdfPage.getOperatorList().then(function (opList) {
ensureNotCancelled();
var svgGfx = new SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
return svgGfx.getSVG(opList, actualSizeViewport).then(function (svg) {
ensureNotCancelled(); ensureNotCancelled();
var svgGfx = new SVGGraphics(pdfPage.commonObjs, pdfPage.objs); self.svg = svg;
return svgGfx.getSVG(opList, actualSizeViewport).then(function (svg) { self.paintedViewport = actualSizeViewport;
ensureNotCancelled();
self.svg = svg; svg.style.width = wrapper.style.width;
self.paintedViewport = actualSizeViewport; svg.style.height = wrapper.style.height;
self.renderingState = RenderingStates.FINISHED;
svg.style.width = wrapper.style.width; wrapper.appendChild(svg);
svg.style.height = wrapper.style.height;
self.renderingState = RenderingStates.FINISHED;
wrapper.appendChild(svg);
});
}); });
});
return { return {
promise: promise, promise: promise,
onRenderContinue: function (cont) { onRenderContinue: function (cont) {
cont(); cont();
}, },
cancel: function () { cancel: function () {
cancelled = true; cancelled = true;
} }
}; };
}
}, },
/** /**

Loading…
Cancel
Save