From 788ffba50a0d37fbce7500f69c1efaf2152cd92b Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 27 Jun 2018 20:39:39 +0200 Subject: [PATCH] Replace the `cloneObj` helper function, in the viewer, with native `Object.assign` (PR 9795 follow-up) --- web/pdf_document_properties.js | 5 ++--- web/pdf_history.js | 4 ++-- web/preferences.js | 6 ++---- web/ui_utils.js | 11 ----------- 4 files changed, 6 insertions(+), 20 deletions(-) diff --git a/web/pdf_document_properties.js b/web/pdf_document_properties.js index ce57e94747abe..b5c543d758741 100644 --- a/web/pdf_document_properties.js +++ b/web/pdf_document_properties.js @@ -14,8 +14,7 @@ */ import { - cloneObj, getPageSizeInches, getPDFFileNameFromURL, isPortraitOrientation, - NullL10n + getPageSizeInches, getPDFFileNameFromURL, isPortraitOrientation, NullL10n } from './ui_utils'; import { createPromiseCapability } from 'pdfjs-lib'; @@ -161,7 +160,7 @@ class PDFDocumentProperties { if (fileSize === this.fieldData['fileSize']) { return; // The fileSize has already been correctly set. } - let data = cloneObj(this.fieldData); + let data = Object.assign(Object.create(null), this.fieldData); data['fileSize'] = fileSize; freezeFieldData(data); diff --git a/web/pdf_history.js b/web/pdf_history.js index 3ca1df2cdb62d..f6825e4faaf7d 100644 --- a/web/pdf_history.js +++ b/web/pdf_history.js @@ -14,7 +14,7 @@ */ import { - cloneObj, isValidRotation, parseQueryString, waitOnEventOrTimeout + isValidRotation, parseQueryString, waitOnEventOrTimeout } from './ui_utils'; import { getGlobalEventBus } from './dom_events'; @@ -303,7 +303,7 @@ class PDFHistory { } let position = this._position; if (temporary) { - position = cloneObj(this._position); + position = Object.assign(Object.create(null), this._position); position.temporary = true; } diff --git a/web/preferences.js b/web/preferences.js index 0e6fcf104e50f..b841ad6495d39 100644 --- a/web/preferences.js +++ b/web/preferences.js @@ -13,8 +13,6 @@ * limitations under the License. */ -import { cloneObj } from './ui_utils'; - let defaultPreferences = null; function getDefaultPreferences() { if (!defaultPreferences) { @@ -60,7 +58,7 @@ class BasePreferences { configurable: false, }); - this.prefs = cloneObj(defaults); + this.prefs = Object.assign(Object.create(null), defaults); return this._readFromStorage(defaults); }).then((prefObj) => { if (prefObj) { @@ -96,7 +94,7 @@ class BasePreferences { */ reset() { return this._initializedPromise.then(() => { - this.prefs = cloneObj(this.defaults); + this.prefs = Object.assign(Object.create(null), this.defaults); return this._writeToStorage(this.defaults); }); } diff --git a/web/ui_utils.js b/web/ui_utils.js index 1728d8b8c30af..c067dd420d3de 100644 --- a/web/ui_utils.js +++ b/web/ui_utils.js @@ -611,16 +611,6 @@ function isPortraitOrientation(size) { return size.width <= size.height; } -function cloneObj(obj) { - let result = Object.create(null); - for (let i in obj) { - if (Object.prototype.hasOwnProperty.call(obj, i)) { - result[i] = obj[i]; - } - } - return result; -} - const WaitOnType = { EVENT: 'event', TIMEOUT: 'timeout', @@ -842,7 +832,6 @@ export { VERTICAL_PADDING, isValidRotation, isPortraitOrientation, - cloneObj, PresentationModeState, RendererType, TextLayerMode,