Merge pull request #7306 from yurydelendik/enable-debugger

Enables debugger only when needed.
This commit is contained in:
Jonas Jenwald 2016-05-10 16:19:49 +02:00
commit aa9ba43fa1
7 changed files with 66 additions and 23 deletions

View File

@ -100,7 +100,8 @@ function preprocess(inFilename, outFilename, defines) {
var STATE_ELSE_TRUE = 2; var STATE_ELSE_TRUE = 2;
// inside if, condition true (process lines until #else or #endif) // inside if, condition true (process lines until #else or #endif)
var STATE_IF_TRUE = 3; var STATE_IF_TRUE = 3;
// inside else, #if was true, so #else is false (ignore lines until #endif) // inside else or elif, #if/#elif was true, so following #else or #elif is
// false (ignore lines until #endif)
var STATE_ELSE_FALSE = 4; var STATE_ELSE_FALSE = 4;
var line; var line;
@ -124,18 +125,18 @@ function preprocess(inFilename, outFilename, defines) {
state = evaluateCondition(m[2]) ? STATE_IF_TRUE : STATE_IF_FALSE; state = evaluateCondition(m[2]) ? STATE_IF_TRUE : STATE_IF_FALSE;
break; break;
case 'elif': case 'elif':
if (state === STATE_IF_TRUE) { if (state === STATE_IF_TRUE || state === STATE_ELSE_FALSE) {
state = STATE_ELSE_FALSE; state = STATE_ELSE_FALSE;
} else if (state === STATE_IF_FALSE) { } else if (state === STATE_IF_FALSE) {
state = evaluateCondition(m[2]) ? STATE_IF_TRUE : STATE_IF_FALSE; state = evaluateCondition(m[2]) ? STATE_IF_TRUE : STATE_IF_FALSE;
} else if (state === STATE_ELSE_TRUE || state === STATE_ELSE_FALSE) { } else if (state === STATE_ELSE_TRUE) {
throw new Error('Found #elif after #else at ' + loc()); throw new Error('Found #elif after #else at ' + loc());
} else { } else {
throw new Error('Found #elif without matching #if at ' + loc()); throw new Error('Found #elif without matching #if at ' + loc());
} }
break; break;
case 'else': case 'else':
if (state === STATE_IF_TRUE) { if (state === STATE_IF_TRUE || state === STATE_ELSE_FALSE) {
state = STATE_ELSE_FALSE; state = STATE_ELSE_FALSE;
} else if (state === STATE_IF_FALSE) { } else if (state === STATE_IF_FALSE) {
state = STATE_ELSE_TRUE; state = STATE_ELSE_TRUE;

View File

@ -0,0 +1,2 @@
'use strict';
var a;

View File

@ -0,0 +1,8 @@
'use strict';
//#if TRUE
var a;
//#elif FALSE
var b;
//#else
var c;
//#endif

View File

@ -1288,6 +1288,24 @@ function validateFileURL(file) {
} }
//#endif //#endif
function loadAndEnablePDFBug(enabledTabs) {
return new Promise(function (resolve, reject) {
var appConfig = PDFViewerApplication.appConfig;
var script = document.createElement('script');
script.src = appConfig.debuggerScriptPath;
script.onload = function () {
PDFBug.enable(enabledTabs);
PDFBug.init(pdfjsLib, appConfig.mainContainer);
resolve();
};
script.onerror = function () {
reject(new Error('Cannot load debugger at ' + script.src));
};
(document.getElementsByTagName('head')[0] || document.body).
appendChild(script);
});
}
function webViewerInitialized() { function webViewerInitialized() {
//#if GENERIC //#if GENERIC
var queryString = document.location.search.substring(1); var queryString = document.location.search.substring(1);
@ -1302,6 +1320,7 @@ function webViewerInitialized() {
//var file = DEFAULT_URL; //var file = DEFAULT_URL;
//#endif //#endif
var waitForBeforeOpening = [];
var appConfig = PDFViewerApplication.appConfig; var appConfig = PDFViewerApplication.appConfig;
//#if GENERIC //#if GENERIC
var fileInput = document.createElement('input'); var fileInput = document.createElement('input');
@ -1393,8 +1412,7 @@ function webViewerInitialized() {
PDFJS.pdfBug = true; PDFJS.pdfBug = true;
var pdfBug = hashParams['pdfbug']; var pdfBug = hashParams['pdfbug'];
var enabled = pdfBug.split(','); var enabled = pdfBug.split(',');
PDFBug.enable(enabled); waitForBeforeOpening.push(loadAndEnablePDFBug(enabled));
PDFBug.init(pdfjsLib, appConfig.mainContainer);
} }
} }
@ -1496,13 +1514,16 @@ function webViewerInitialized() {
PDFViewerApplication.eventBus.dispatch('download'); PDFViewerApplication.eventBus.dispatch('download');
}); });
//#if (FIREFOX || MOZCENTRAL || CHROME) Promise.all(waitForBeforeOpening).then(function () {
//PDFViewerApplication.setTitleUsingUrl(file); webViewerOpenFileViaURL(file);
//PDFViewerApplication.initPassiveLoading(); }).catch(function (reason) {
//return; PDFViewerApplication.error(mozL10n.get('loading_error', null,
//#endif 'An error occurred while opening.'), reason);
});
}
//#if GENERIC //#if GENERIC
function webViewerOpenFileViaURL(file) {
if (file && file.lastIndexOf('file:', 0) === 0) { if (file && file.lastIndexOf('file:', 0) === 0) {
// file:-scheme. Load the contents in the main thread because QtWebKit // file:-scheme. Load the contents in the main thread because QtWebKit
// cannot load file:-URLs in a Web Worker. file:-URLs are usually loaded // cannot load file:-URLs in a Web Worker. file:-URLs are usually loaded
@ -1526,8 +1547,19 @@ function webViewerInitialized() {
if (file) { if (file) {
PDFViewerApplication.open(file); PDFViewerApplication.open(file);
} }
//#endif
} }
//#elif (FIREFOX || MOZCENTRAL || CHROME)
//function webViewerOpenFileViaURL(file) {
// PDFViewerApplication.setTitleUsingUrl(file);
// PDFViewerApplication.initPassiveLoading();
//}
//#else
//function webViewerOpenFileURL(file) {
// if (file) {
// throw new Error('Not implemented: webViewerOpenFileURL');
// }
//}
//#endif
function webViewerPageRendered(e) { function webViewerPageRendered(e) {
var pageNumber = e.pageNumber; var pageNumber = e.pageNumber;

View File

@ -158,6 +158,8 @@ var FontInspector = (function FontInspectorClosure() {
}; };
})(); })();
var opMap;
// Manages all the page steppers. // Manages all the page steppers.
var StepperManager = (function StepperManagerClosure() { var StepperManager = (function StepperManagerClosure() {
var steppers = []; var steppers = [];
@ -171,7 +173,7 @@ var StepperManager = (function StepperManagerClosure() {
name: 'Stepper', name: 'Stepper',
panel: null, panel: null,
manager: null, manager: null,
init: function init() { init: function init(pdfjsLib) {
var self = this; var self = this;
this.panel.setAttribute('style', 'padding: 5px;'); this.panel.setAttribute('style', 'padding: 5px;');
stepperControls = document.createElement('div'); stepperControls = document.createElement('div');
@ -186,6 +188,11 @@ var StepperManager = (function StepperManagerClosure() {
if (sessionStorage.getItem('pdfjsBreakPoints')) { if (sessionStorage.getItem('pdfjsBreakPoints')) {
breakPoints = JSON.parse(sessionStorage.getItem('pdfjsBreakPoints')); breakPoints = JSON.parse(sessionStorage.getItem('pdfjsBreakPoints'));
} }
opMap = Object.create(null);
for (var key in pdfjsLib.OPS) {
opMap[pdfjsLib.OPS[key]] = key;
}
}, },
cleanup: function cleanup() { cleanup: function cleanup() {
stepperChooser.textContent = ''; stepperChooser.textContent = '';
@ -251,8 +258,6 @@ var Stepper = (function StepperClosure() {
return d; return d;
} }
var opMap = null;
function simplifyArgs(args) { function simplifyArgs(args) {
if (typeof args === 'string') { if (typeof args === 'string') {
var MAX_STRING_LENGTH = 75; var MAX_STRING_LENGTH = 75;
@ -290,7 +295,7 @@ var Stepper = (function StepperClosure() {
this.operatorListIdx = 0; this.operatorListIdx = 0;
} }
Stepper.prototype = { Stepper.prototype = {
init: function init(pdfjsLib) { init: function init(operatorList) {
var panel = this.panel; var panel = this.panel;
var content = c('div', 'c=continue, s=step'); var content = c('div', 'c=continue, s=step');
var table = c('table'); var table = c('table');
@ -304,12 +309,7 @@ var Stepper = (function StepperClosure() {
headerRow.appendChild(c('th', 'args')); headerRow.appendChild(c('th', 'args'));
panel.appendChild(content); panel.appendChild(content);
this.table = table; this.table = table;
if (!opMap) { this.updateOperatorList(operatorList);
opMap = Object.create(null);
for (var key in pdfjsLib.OPS) {
opMap[pdfjsLib.OPS[key]] = key;
}
}
}, },
updateOperatorList: function updateOperatorList(operatorList) { updateOperatorList: function updateOperatorList(operatorList) {
var self = this; var self = this;

View File

@ -65,7 +65,6 @@ See https://github.com/adobe-type-tools/cmap-resources
<!--#endif--> <!--#endif-->
<!--#if !MINIFIED --> <!--#if !MINIFIED -->
<script src="debugger.js"></script>
<script src="viewer.js"></script> <script src="viewer.js"></script>
<!--#else--> <!--#else-->
<!--#include viewer-snippet-minified.html--> <!--#include viewer-snippet-minified.html-->

View File

@ -161,6 +161,7 @@ function getViewerConfiguration() {
}, },
printContainer: document.getElementById('printContainer'), printContainer: document.getElementById('printContainer'),
openFileInputName: 'fileInput', openFileInputName: 'fileInput',
debuggerScriptPath: './debugger.js',
}; };
} }