From 7bee0c2aa392b145d5cc23ac62d06b30fdf0af14 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 25 Apr 2017 16:07:59 +0200 Subject: [PATCH] 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. --- src/shared/compatibility.js | 56 ++++++++++++++++++------------------- src/shared/util.js | 27 +++++++++--------- 2 files changed, 41 insertions(+), 42 deletions(-) diff --git a/src/shared/compatibility.js b/src/shared/compatibility.js index e01b95ce6..7b9be12b5 100644 --- a/src/shared/compatibility.js +++ b/src/shared/compatibility.js @@ -105,12 +105,12 @@ PDFJS.compatibilityChecked = true; var uint32ArrayViewSetters = 0; function createUint32ArrayProp(index) { return { - get: function () { + get() { var buffer = this.buffer, offset = index << 2; return (buffer[offset] | (buffer[offset + 1] << 8) | (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0; }, - set: function (value) { + set(value) { var buffer = this.buffer, offset = index << 2; buffer[offset] = value & 255; buffer[offset + 1] = (value >> 8) & 255; @@ -190,14 +190,14 @@ PDFJS.compatibilityChecked = true; } // Trying to fake CanvasPixelArray as Uint8ClampedArray. Object.defineProperty(cpaProto, 'buffer', { - get: function () { + get() { return this; }, enumerable: false, configurable: true }); Object.defineProperty(cpaProto, 'byteLength', { - get: function () { + get() { return this.length; }, enumerable: false, @@ -411,7 +411,7 @@ PDFJS.compatibilityChecked = true; } Object.defineProperty(HTMLElement.prototype, 'dataset', { - get: function() { + get() { if (this._dataset) { return this._dataset; } @@ -470,22 +470,22 @@ PDFJS.compatibilityChecked = true; } var classListPrototype = { - add: function(name) { + add(name) { changeList(this.element, name, true, false); }, - contains: function(name) { + contains(name) { return changeList(this.element, name, false, false); }, - remove: function(name) { + remove(name) { changeList(this.element, name, false, true); }, - toggle: function(name) { + toggle(name) { changeList(this.element, name, true, true); } }; Object.defineProperty(HTMLElement.prototype, 'classList', { - get: function() { + get() { if (this._classList) { return this._classList; } @@ -562,9 +562,9 @@ PDFJS.compatibilityChecked = true; } if (!('console' in window)) { window.console = { - log: function() {}, - error: function() {}, - warn: function() {} + log() {}, + error() {}, + warn() {} }; return; } @@ -772,7 +772,7 @@ PDFJS.compatibilityChecked = true; return; } Object.defineProperty(document, 'currentScript', { - get: function () { + get() { var scripts = document.getElementsByTagName('script'); return scripts[scripts.length - 1]; }, @@ -794,10 +794,10 @@ PDFJS.compatibilityChecked = true; var inputProto = el.constructor.prototype; var typeProperty = Object.getOwnPropertyDescriptor(inputProto, 'type'); Object.defineProperty(inputProto, 'type', { - get: function () { + get() { return typeProperty.get.call(this); }, - set: function (value) { + set(value) { typeProperty.set.call(this, value === 'number' ? 'text' : value); }, enumerable: true, @@ -819,11 +819,11 @@ PDFJS.compatibilityChecked = true; var readyStateProto = Object.getOwnPropertyDescriptor(documentProto, 'readyState'); Object.defineProperty(documentProto, 'readyState', { - get: function () { + get() { var value = readyStateProto.get.call(this); return value === 'interactive' ? 'loading' : value; }, - set: function (value) { + set(value) { readyStateProto.set.call(this, value); }, enumerable: true, @@ -979,7 +979,7 @@ PDFJS.compatibilityChecked = true; addUnhandledRejection: function addUnhandledRejection(promise) { this.unhandledRejections.push({ - promise: promise, + promise, time: Date.now() }); this.scheduleRejectionCheck(); @@ -1160,9 +1160,9 @@ PDFJS.compatibilityChecked = true; }); this._handlers.push({ thisPromise: this, - onResolve: onResolve, - onReject: onReject, - nextPromise: nextPromise + onResolve, + onReject, + nextPromise, }); HandlerManager.scheduleHandlers(this); return nextPromise; @@ -1186,20 +1186,20 @@ PDFJS.compatibilityChecked = true; this.id = '$weakmap' + (id++); } WeakMap.prototype = { - has: function(obj) { + has(obj) { return !!Object.getOwnPropertyDescriptor(obj, this.id); }, - get: function(obj, defaultValue) { + get(obj, defaultValue) { return this.has(obj) ? obj[this.id] : defaultValue; }, - set: function(obj, value) { + set(obj, value) { Object.defineProperty(obj, this.id, { - value: value, + value, enumerable: false, configurable: true }); }, - delete: function(obj) { + delete(obj) { delete obj[this.id]; } }; @@ -1703,7 +1703,7 @@ PDFJS.compatibilityChecked = true; } JURL.prototype = { - toString: function() { + toString() { return this.href; }, get href() { diff --git a/src/shared/util.js b/src/shared/util.js index f6f7f3974..f17cc92cb 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -376,7 +376,7 @@ function createValidAbsoluteUrl(url, baseUrl) { } function shadow(obj, prop, value) { - Object.defineProperty(obj, prop, { value: value, + Object.defineProperty(obj, prop, { value, enumerable: true, configurable: true, writable: false }); @@ -1254,8 +1254,8 @@ function MessageHandler(sourceName, targetName, comObj) { return action[0].call(action[1], data.data); }).then(function (result) { comObj.postMessage({ - sourceName: sourceName, - targetName: targetName, + sourceName, + targetName, isReply: true, callbackId: data.callbackId, data: result @@ -1266,8 +1266,8 @@ function MessageHandler(sourceName, targetName, comObj) { reason = reason + ''; } comObj.postMessage({ - sourceName: sourceName, - targetName: targetName, + sourceName, + targetName, isReply: true, callbackId: data.callbackId, error: reason @@ -1284,7 +1284,7 @@ function MessageHandler(sourceName, targetName, comObj) { } MessageHandler.prototype = { - on: function messageHandlerOn(actionName, handler, scope) { + on(actionName, handler, scope) { var ah = this.actionHandler; if (ah[actionName]) { error('There is already an actionName called "' + actionName + '"'); @@ -1297,12 +1297,12 @@ MessageHandler.prototype = { * @param {JSON} data JSON data to send. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers */ - send: function messageHandlerSend(actionName, data, transfers) { + send(actionName, data, transfers) { var message = { sourceName: this.sourceName, targetName: this.targetName, action: actionName, - data: data + data, }; this.postMessage(message, transfers); }, @@ -1314,15 +1314,14 @@ MessageHandler.prototype = { * @param {Array} [transfers] Optional list of transfers/ArrayBuffers. * @returns {Promise} Promise to be resolved with response data. */ - sendWithPromise: - function messageHandlerSendWithPromise(actionName, data, transfers) { + sendWithPromise(actionName, data, transfers) { var callbackId = this.callbackIndex++; var message = { sourceName: this.sourceName, targetName: this.targetName, action: actionName, - data: data, - callbackId: callbackId + data, + callbackId, }; var capability = createPromiseCapability(); this.callbacksCapabilities[callbackId] = capability; @@ -1339,7 +1338,7 @@ MessageHandler.prototype = { * @param message {Object} Raw message. * @param transfers List of transfers/ArrayBuffers, or undefined. */ - postMessage: function (message, transfers) { + postMessage(message, transfers) { if (transfers && this.postMessageTransfers) { this.comObj.postMessage(message, transfers); } else { @@ -1347,7 +1346,7 @@ MessageHandler.prototype = { } }, - destroy: function () { + destroy() { this.comObj.removeEventListener('message', this._onComObjOnMessage); } };