Enable the object-shorthand
ESLint rule in src/shared
Please see http://eslint.org/docs/rules/object-shorthand. For the most part, these changes are of the search-and-replace kind, and the previously enabled `no-undef` rule should complement the tests in helping ensure that no stupid errors crept into to the patch.
This commit is contained in:
parent
366277d180
commit
7bee0c2aa3
@ -105,12 +105,12 @@ PDFJS.compatibilityChecked = true;
|
|||||||
var uint32ArrayViewSetters = 0;
|
var uint32ArrayViewSetters = 0;
|
||||||
function createUint32ArrayProp(index) {
|
function createUint32ArrayProp(index) {
|
||||||
return {
|
return {
|
||||||
get: function () {
|
get() {
|
||||||
var buffer = this.buffer, offset = index << 2;
|
var buffer = this.buffer, offset = index << 2;
|
||||||
return (buffer[offset] | (buffer[offset + 1] << 8) |
|
return (buffer[offset] | (buffer[offset + 1] << 8) |
|
||||||
(buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
|
(buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
|
||||||
},
|
},
|
||||||
set: function (value) {
|
set(value) {
|
||||||
var buffer = this.buffer, offset = index << 2;
|
var buffer = this.buffer, offset = index << 2;
|
||||||
buffer[offset] = value & 255;
|
buffer[offset] = value & 255;
|
||||||
buffer[offset + 1] = (value >> 8) & 255;
|
buffer[offset + 1] = (value >> 8) & 255;
|
||||||
@ -190,14 +190,14 @@ PDFJS.compatibilityChecked = true;
|
|||||||
}
|
}
|
||||||
// Trying to fake CanvasPixelArray as Uint8ClampedArray.
|
// Trying to fake CanvasPixelArray as Uint8ClampedArray.
|
||||||
Object.defineProperty(cpaProto, 'buffer', {
|
Object.defineProperty(cpaProto, 'buffer', {
|
||||||
get: function () {
|
get() {
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
Object.defineProperty(cpaProto, 'byteLength', {
|
Object.defineProperty(cpaProto, 'byteLength', {
|
||||||
get: function () {
|
get() {
|
||||||
return this.length;
|
return this.length;
|
||||||
},
|
},
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
@ -411,7 +411,7 @@ PDFJS.compatibilityChecked = true;
|
|||||||
}
|
}
|
||||||
|
|
||||||
Object.defineProperty(HTMLElement.prototype, 'dataset', {
|
Object.defineProperty(HTMLElement.prototype, 'dataset', {
|
||||||
get: function() {
|
get() {
|
||||||
if (this._dataset) {
|
if (this._dataset) {
|
||||||
return this._dataset;
|
return this._dataset;
|
||||||
}
|
}
|
||||||
@ -470,22 +470,22 @@ PDFJS.compatibilityChecked = true;
|
|||||||
}
|
}
|
||||||
|
|
||||||
var classListPrototype = {
|
var classListPrototype = {
|
||||||
add: function(name) {
|
add(name) {
|
||||||
changeList(this.element, name, true, false);
|
changeList(this.element, name, true, false);
|
||||||
},
|
},
|
||||||
contains: function(name) {
|
contains(name) {
|
||||||
return changeList(this.element, name, false, false);
|
return changeList(this.element, name, false, false);
|
||||||
},
|
},
|
||||||
remove: function(name) {
|
remove(name) {
|
||||||
changeList(this.element, name, false, true);
|
changeList(this.element, name, false, true);
|
||||||
},
|
},
|
||||||
toggle: function(name) {
|
toggle(name) {
|
||||||
changeList(this.element, name, true, true);
|
changeList(this.element, name, true, true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.defineProperty(HTMLElement.prototype, 'classList', {
|
Object.defineProperty(HTMLElement.prototype, 'classList', {
|
||||||
get: function() {
|
get() {
|
||||||
if (this._classList) {
|
if (this._classList) {
|
||||||
return this._classList;
|
return this._classList;
|
||||||
}
|
}
|
||||||
@ -562,9 +562,9 @@ PDFJS.compatibilityChecked = true;
|
|||||||
}
|
}
|
||||||
if (!('console' in window)) {
|
if (!('console' in window)) {
|
||||||
window.console = {
|
window.console = {
|
||||||
log: function() {},
|
log() {},
|
||||||
error: function() {},
|
error() {},
|
||||||
warn: function() {}
|
warn() {}
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -772,7 +772,7 @@ PDFJS.compatibilityChecked = true;
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Object.defineProperty(document, 'currentScript', {
|
Object.defineProperty(document, 'currentScript', {
|
||||||
get: function () {
|
get() {
|
||||||
var scripts = document.getElementsByTagName('script');
|
var scripts = document.getElementsByTagName('script');
|
||||||
return scripts[scripts.length - 1];
|
return scripts[scripts.length - 1];
|
||||||
},
|
},
|
||||||
@ -794,10 +794,10 @@ PDFJS.compatibilityChecked = true;
|
|||||||
var inputProto = el.constructor.prototype;
|
var inputProto = el.constructor.prototype;
|
||||||
var typeProperty = Object.getOwnPropertyDescriptor(inputProto, 'type');
|
var typeProperty = Object.getOwnPropertyDescriptor(inputProto, 'type');
|
||||||
Object.defineProperty(inputProto, 'type', {
|
Object.defineProperty(inputProto, 'type', {
|
||||||
get: function () {
|
get() {
|
||||||
return typeProperty.get.call(this);
|
return typeProperty.get.call(this);
|
||||||
},
|
},
|
||||||
set: function (value) {
|
set(value) {
|
||||||
typeProperty.set.call(this, value === 'number' ? 'text' : value);
|
typeProperty.set.call(this, value === 'number' ? 'text' : value);
|
||||||
},
|
},
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
@ -819,11 +819,11 @@ PDFJS.compatibilityChecked = true;
|
|||||||
var readyStateProto = Object.getOwnPropertyDescriptor(documentProto,
|
var readyStateProto = Object.getOwnPropertyDescriptor(documentProto,
|
||||||
'readyState');
|
'readyState');
|
||||||
Object.defineProperty(documentProto, 'readyState', {
|
Object.defineProperty(documentProto, 'readyState', {
|
||||||
get: function () {
|
get() {
|
||||||
var value = readyStateProto.get.call(this);
|
var value = readyStateProto.get.call(this);
|
||||||
return value === 'interactive' ? 'loading' : value;
|
return value === 'interactive' ? 'loading' : value;
|
||||||
},
|
},
|
||||||
set: function (value) {
|
set(value) {
|
||||||
readyStateProto.set.call(this, value);
|
readyStateProto.set.call(this, value);
|
||||||
},
|
},
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
@ -979,7 +979,7 @@ PDFJS.compatibilityChecked = true;
|
|||||||
|
|
||||||
addUnhandledRejection: function addUnhandledRejection(promise) {
|
addUnhandledRejection: function addUnhandledRejection(promise) {
|
||||||
this.unhandledRejections.push({
|
this.unhandledRejections.push({
|
||||||
promise: promise,
|
promise,
|
||||||
time: Date.now()
|
time: Date.now()
|
||||||
});
|
});
|
||||||
this.scheduleRejectionCheck();
|
this.scheduleRejectionCheck();
|
||||||
@ -1160,9 +1160,9 @@ PDFJS.compatibilityChecked = true;
|
|||||||
});
|
});
|
||||||
this._handlers.push({
|
this._handlers.push({
|
||||||
thisPromise: this,
|
thisPromise: this,
|
||||||
onResolve: onResolve,
|
onResolve,
|
||||||
onReject: onReject,
|
onReject,
|
||||||
nextPromise: nextPromise
|
nextPromise,
|
||||||
});
|
});
|
||||||
HandlerManager.scheduleHandlers(this);
|
HandlerManager.scheduleHandlers(this);
|
||||||
return nextPromise;
|
return nextPromise;
|
||||||
@ -1186,20 +1186,20 @@ PDFJS.compatibilityChecked = true;
|
|||||||
this.id = '$weakmap' + (id++);
|
this.id = '$weakmap' + (id++);
|
||||||
}
|
}
|
||||||
WeakMap.prototype = {
|
WeakMap.prototype = {
|
||||||
has: function(obj) {
|
has(obj) {
|
||||||
return !!Object.getOwnPropertyDescriptor(obj, this.id);
|
return !!Object.getOwnPropertyDescriptor(obj, this.id);
|
||||||
},
|
},
|
||||||
get: function(obj, defaultValue) {
|
get(obj, defaultValue) {
|
||||||
return this.has(obj) ? obj[this.id] : defaultValue;
|
return this.has(obj) ? obj[this.id] : defaultValue;
|
||||||
},
|
},
|
||||||
set: function(obj, value) {
|
set(obj, value) {
|
||||||
Object.defineProperty(obj, this.id, {
|
Object.defineProperty(obj, this.id, {
|
||||||
value: value,
|
value,
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
configurable: true
|
configurable: true
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
delete: function(obj) {
|
delete(obj) {
|
||||||
delete obj[this.id];
|
delete obj[this.id];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -1703,7 +1703,7 @@ PDFJS.compatibilityChecked = true;
|
|||||||
}
|
}
|
||||||
|
|
||||||
JURL.prototype = {
|
JURL.prototype = {
|
||||||
toString: function() {
|
toString() {
|
||||||
return this.href;
|
return this.href;
|
||||||
},
|
},
|
||||||
get href() {
|
get href() {
|
||||||
|
@ -376,7 +376,7 @@ function createValidAbsoluteUrl(url, baseUrl) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function shadow(obj, prop, value) {
|
function shadow(obj, prop, value) {
|
||||||
Object.defineProperty(obj, prop, { value: value,
|
Object.defineProperty(obj, prop, { value,
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
configurable: true,
|
configurable: true,
|
||||||
writable: false });
|
writable: false });
|
||||||
@ -1254,8 +1254,8 @@ function MessageHandler(sourceName, targetName, comObj) {
|
|||||||
return action[0].call(action[1], data.data);
|
return action[0].call(action[1], data.data);
|
||||||
}).then(function (result) {
|
}).then(function (result) {
|
||||||
comObj.postMessage({
|
comObj.postMessage({
|
||||||
sourceName: sourceName,
|
sourceName,
|
||||||
targetName: targetName,
|
targetName,
|
||||||
isReply: true,
|
isReply: true,
|
||||||
callbackId: data.callbackId,
|
callbackId: data.callbackId,
|
||||||
data: result
|
data: result
|
||||||
@ -1266,8 +1266,8 @@ function MessageHandler(sourceName, targetName, comObj) {
|
|||||||
reason = reason + '';
|
reason = reason + '';
|
||||||
}
|
}
|
||||||
comObj.postMessage({
|
comObj.postMessage({
|
||||||
sourceName: sourceName,
|
sourceName,
|
||||||
targetName: targetName,
|
targetName,
|
||||||
isReply: true,
|
isReply: true,
|
||||||
callbackId: data.callbackId,
|
callbackId: data.callbackId,
|
||||||
error: reason
|
error: reason
|
||||||
@ -1284,7 +1284,7 @@ function MessageHandler(sourceName, targetName, comObj) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MessageHandler.prototype = {
|
MessageHandler.prototype = {
|
||||||
on: function messageHandlerOn(actionName, handler, scope) {
|
on(actionName, handler, scope) {
|
||||||
var ah = this.actionHandler;
|
var ah = this.actionHandler;
|
||||||
if (ah[actionName]) {
|
if (ah[actionName]) {
|
||||||
error('There is already an actionName called "' + actionName + '"');
|
error('There is already an actionName called "' + actionName + '"');
|
||||||
@ -1297,12 +1297,12 @@ MessageHandler.prototype = {
|
|||||||
* @param {JSON} data JSON data to send.
|
* @param {JSON} data JSON data to send.
|
||||||
* @param {Array} [transfers] Optional list of transfers/ArrayBuffers
|
* @param {Array} [transfers] Optional list of transfers/ArrayBuffers
|
||||||
*/
|
*/
|
||||||
send: function messageHandlerSend(actionName, data, transfers) {
|
send(actionName, data, transfers) {
|
||||||
var message = {
|
var message = {
|
||||||
sourceName: this.sourceName,
|
sourceName: this.sourceName,
|
||||||
targetName: this.targetName,
|
targetName: this.targetName,
|
||||||
action: actionName,
|
action: actionName,
|
||||||
data: data
|
data,
|
||||||
};
|
};
|
||||||
this.postMessage(message, transfers);
|
this.postMessage(message, transfers);
|
||||||
},
|
},
|
||||||
@ -1314,15 +1314,14 @@ MessageHandler.prototype = {
|
|||||||
* @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
|
* @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
|
||||||
* @returns {Promise} Promise to be resolved with response data.
|
* @returns {Promise} Promise to be resolved with response data.
|
||||||
*/
|
*/
|
||||||
sendWithPromise:
|
sendWithPromise(actionName, data, transfers) {
|
||||||
function messageHandlerSendWithPromise(actionName, data, transfers) {
|
|
||||||
var callbackId = this.callbackIndex++;
|
var callbackId = this.callbackIndex++;
|
||||||
var message = {
|
var message = {
|
||||||
sourceName: this.sourceName,
|
sourceName: this.sourceName,
|
||||||
targetName: this.targetName,
|
targetName: this.targetName,
|
||||||
action: actionName,
|
action: actionName,
|
||||||
data: data,
|
data,
|
||||||
callbackId: callbackId
|
callbackId,
|
||||||
};
|
};
|
||||||
var capability = createPromiseCapability();
|
var capability = createPromiseCapability();
|
||||||
this.callbacksCapabilities[callbackId] = capability;
|
this.callbacksCapabilities[callbackId] = capability;
|
||||||
@ -1339,7 +1338,7 @@ MessageHandler.prototype = {
|
|||||||
* @param message {Object} Raw message.
|
* @param message {Object} Raw message.
|
||||||
* @param transfers List of transfers/ArrayBuffers, or undefined.
|
* @param transfers List of transfers/ArrayBuffers, or undefined.
|
||||||
*/
|
*/
|
||||||
postMessage: function (message, transfers) {
|
postMessage(message, transfers) {
|
||||||
if (transfers && this.postMessageTransfers) {
|
if (transfers && this.postMessageTransfers) {
|
||||||
this.comObj.postMessage(message, transfers);
|
this.comObj.postMessage(message, transfers);
|
||||||
} else {
|
} else {
|
||||||
@ -1347,7 +1346,7 @@ MessageHandler.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
destroy: function () {
|
destroy() {
|
||||||
this.comObj.removeEventListener('message', this._onComObjOnMessage);
|
this.comObj.removeEventListener('message', this._onComObjOnMessage);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user