From ce1a9740f6201b6ac5c51034cabfc02038923fa0 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 7 Jun 2016 10:24:48 -0700 Subject: [PATCH] :art: Use const and for/of loops --- lib/browser/guest-view-manager.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/browser/guest-view-manager.js b/lib/browser/guest-view-manager.js index 0bdbb1d1f68..3d4596d725d 100644 --- a/lib/browser/guest-view-manager.js +++ b/lib/browser/guest-view-manager.js @@ -57,12 +57,12 @@ var getNextInstanceId = function () { // Create a new guest instance. var createGuest = function (embedder, params) { - var destroy, destroyEvents, event, fn, guest, i, id, j, len, len1, listeners if (webViewManager == null) { webViewManager = process.atomBinding('web_view_manager') } - id = getNextInstanceId(embedder) - guest = webContents.create({ + + const id = getNextInstanceId(embedder) + const guest = webContents.create({ isGuest: true, partition: params.partition, embedder: embedder @@ -73,20 +73,19 @@ var createGuest = function (embedder, params) { } // Destroy guest when the embedder is gone or navigated. - destroyEvents = ['will-destroy', 'crashed', 'did-navigate'] - destroy = function () { + const destroyEvents = ['will-destroy', 'crashed', 'did-navigate'] + const destroy = function () { if (guestInstances[id] != null) { - return destroyGuest(embedder, id) + destroyGuest(embedder, id) } } - for (i = 0, len = destroyEvents.length; i < len; i++) { - event = destroyEvents[i] + for (const event of destroyEvents) { embedder.once(event, destroy) // Users might also listen to the crashed event, so We must ensure the guest // is destroyed before users' listener gets called. It is done by moving our // listener to the first one in queue. - listeners = embedder._events[event] + const listeners = embedder._events[event] if (Array.isArray(listeners)) { moveLastToFirst(listeners) } @@ -132,13 +131,12 @@ var createGuest = function (embedder, params) { }) // Dispatch events to embedder. - fn = function (event) { - return guest.on(event, function (_, ...args) { + const fn = function (event) { + guest.on(event, function (_, ...args) { embedder.send.apply(embedder, ['ELECTRON_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-' + guest.viewInstanceId, event].concat(args)) }) } - for (j = 0, len1 = supportedWebViewEvents.length; j < len1; j++) { - event = supportedWebViewEvents[j] + for (const event of supportedWebViewEvents) { fn(event) } @@ -151,6 +149,7 @@ var createGuest = function (embedder, params) { guest.on('size-changed', function (_, ...args) { embedder.send.apply(embedder, ['ELECTRON_GUEST_VIEW_INTERNAL_SIZE_CHANGED-' + guest.viewInstanceId].concat(args)) }) + return id }