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

View file

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

View file

@ -402,18 +402,17 @@ var registerWebViewElement = function () {
}
}
}
for (let i = 0, len = methods.length; i < len; i++) {
const method = methods[i]
for (const method of methods) {
proto[method] = createBlockHandler(method)
}
const createNonBlockHandler = function (m) {
return function (...args) {
const internal = v8Util.getHiddenValue(this, 'internal')
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++) {
const method = nonblockMethods[j]
for (const method of nonblockMethods) {
proto[method] = createNonBlockHandler(method)
}