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. 13
      external/builder/fixtures_esprima/deadcode-expected.js
  2. 25
      external/builder/fixtures_esprima/deadcode.js
  3. 24
      external/builder/preprocessor2.js
  4. 8
      src/display/font_loader.js
  5. 4
      web/pdf_page_view.js

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;
}

24
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) {
case 'EmptyStatement':
// Removing empty statements from the blocks. // Removing empty statements from the blocks.
node.body.splice(subExpressionIndex, 1); node.body.splice(subExpressionIndex, 1);
continue; continue;
} case 'BlockStatement':
if (node.body[subExpressionIndex].type === '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;
} }

8
src/display/font_loader.js

@ -360,7 +360,10 @@ 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')) {
throw new Error('Not implemented: createNativeFontFace');
}
if (!this.data) { if (!this.data) {
return null; return null;
} }
@ -376,9 +379,6 @@ var FontFaceObject = (function FontFaceObjectClosure() {
this.options.fontRegistry.registerFont(this); this.options.fontRegistry.registerFont(this);
} }
return nativeFontFace; return nativeFontFace;
} else { // eslint-disable-line no-else-return
throw new Error('Not implemented: createNativeFontFace');
}
}, },
createFontFaceRule: function FontFaceObject_createFontFaceRule() { createFontFaceRule: function FontFaceObject_createFontFaceRule() {

4
web/pdf_page_view.js

@ -624,7 +624,8 @@ 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 cancelled = false;
var ensureNotCancelled = function () { var ensureNotCancelled = function () {
if (cancelled) { if (cancelled) {
@ -660,7 +661,6 @@ var PDFPageView = (function PDFPageViewClosure() {
cancelled = true; cancelled = true;
} }
}; };
}
}, },
/** /**

Loading…
Cancel
Save