Use for/of and remove loop variables

This commit is contained in:
Kevin Sawicki 2016-11-03 11:09:53 -07:00
parent 6eab14359c
commit 0e1c2b0fcb
3 changed files with 13 additions and 20 deletions

View file

@ -44,16 +44,13 @@ const DEPRECATED_EVENTS = {
} }
const dispatchEvent = function (webView, eventName, eventKey, ...args) { const dispatchEvent = function (webView, eventName, eventKey, ...args) {
let f, i, j, len
if (DEPRECATED_EVENTS[eventName] != null) { if (DEPRECATED_EVENTS[eventName] != null) {
dispatchEvent.apply(null, [webView, DEPRECATED_EVENTS[eventName], eventKey].concat(args)) dispatchEvent(webView, DEPRECATED_EVENTS[eventName], eventKey, ...args)
} }
const domEvent = new Event(eventName) const domEvent = new Event(eventName)
const props = WEB_VIEW_EVENTS[eventKey] WEB_VIEW_EVENTS[eventKey].forEach((prop, index) => {
for (i = j = 0, len = props.length; j < len; i = ++j) { domEvent[prop] = args[index]
f = props[i] })
domEvent[f] = args[i]
}
webView.dispatchEvent(domEvent) webView.dispatchEvent(domEvent)
if (eventName === 'load-commit') { if (eventName === 'load-commit') {
webView.onLoadCommit(domEvent) webView.onLoadCommit(domEvent)
@ -82,12 +79,11 @@ module.exports = {
}) })
ipcRenderer.on(`ELECTRON_GUEST_VIEW_INTERNAL_SIZE_CHANGED-${viewInstanceId}`, function (event, ...args) { ipcRenderer.on(`ELECTRON_GUEST_VIEW_INTERNAL_SIZE_CHANGED-${viewInstanceId}`, function (event, ...args) {
let f, i, j, len
const domEvent = new Event('size-changed') const domEvent = new Event('size-changed')
const props = ['oldWidth', 'oldHeight', 'newWidth', 'newHeight'] const props = ['oldWidth', 'oldHeight', 'newWidth', 'newHeight']
for (i = j = 0, len = props.length; j < len; i = ++j) { for (let i = 0; i < props.length; i++) {
f = props[i] const prop = props[i]
domEvent[f] = args[i] domEvent[prop] = args[i]
} }
webView.onSizeChanged(domEvent) webView.onSizeChanged(domEvent)
}) })

View file

@ -212,11 +212,9 @@ class SrcAttribute extends WebViewAttribute {
// spawns off a new process. // spawns off a new process.
setupMutationObserver () { setupMutationObserver () {
this.observer = new MutationObserver((mutations) => { this.observer = new MutationObserver((mutations) => {
let i, len, mutation, newValue, oldValue for (const mutation of mutations) {
for (i = 0, len = mutations.length; i < len; i++) { const {oldValue} = mutation
mutation = mutations[i] const newValue = this.getValue()
oldValue = mutation.oldValue
newValue = this.getValue()
if (oldValue !== newValue) { if (oldValue !== newValue) {
return return
} }

View file

@ -402,18 +402,17 @@ var registerWebViewElement = function () {
} }
} }
} }
for (let i = 0, len = methods.length; i < len; i++) { for (const method of methods) {
const method = methods[i]
proto[method] = createBlockHandler(method) proto[method] = createBlockHandler(method)
} }
const createNonBlockHandler = function (m) { const createNonBlockHandler = function (m) {
return function (...args) { return function (...args) {
const internal = v8Util.getHiddenValue(this, 'internal') const internal = v8Util.getHiddenValue(this, 'internal')
ipcRenderer.send.apply(ipcRenderer, ['ELECTRON_BROWSER_ASYNC_CALL_TO_GUEST_VIEW', null, internal.guestInstanceId, m].concat(args)) ipcRenderer.send.apply(ipcRenderer, ['ELECTRON_BROWSER_ASYNC_CALL_TO_GUEST_VIEW', null, internal.guestInstanceId, m].concat(args))
} }
} }
for (let j = 0, len1 = nonblockMethods.length; j < len1; j++) { for (const method of nonblockMethods) {
const method = nonblockMethods[j]
proto[method] = createNonBlockHandler(method) proto[method] = createNonBlockHandler(method)
} }