Remove unneeded returns

This commit is contained in:
Kevin Sawicki 2016-11-03 10:19:52 -07:00
parent 8e834e9047
commit 3053be345b
4 changed files with 39 additions and 44 deletions

View file

@ -48,7 +48,7 @@ const embedderElementsMap = {}
// Moves the last element of array to the first one. // Moves the last element of array to the first one.
const moveLastToFirst = function (list) { const moveLastToFirst = function (list) {
return list.unshift(list.pop()) list.unshift(list.pop())
} }
// Generate guestInstanceId. // Generate guestInstanceId.
@ -227,7 +227,7 @@ const destroyGuest = function (embedder, guestInstanceId) {
delete guestInstances[guestInstanceId] delete guestInstances[guestInstanceId]
const key = embedder.getId() + '-' + guestInstance.elementInstanceId const key = embedder.getId() + '-' + guestInstance.elementInstanceId
return delete embedderElementsMap[key] delete embedderElementsMap[key]
} }
// Once an embedder has had a guest attached we watch it for destruction to // Once an embedder has had a guest attached we watch it for destruction to
@ -281,7 +281,7 @@ ipcMain.on('ELECTRON_GUEST_VIEW_MANAGER_DESTROY_GUEST', function (event, guestIn
ipcMain.on('ELECTRON_GUEST_VIEW_MANAGER_SET_SIZE', function (event, guestInstanceId, params) { ipcMain.on('ELECTRON_GUEST_VIEW_MANAGER_SET_SIZE', function (event, guestInstanceId, params) {
const guestInstance = guestInstances[guestInstanceId] const guestInstance = guestInstances[guestInstanceId]
return guestInstance != null ? guestInstance.guest.setSize(params) : void 0 guestInstance != null ? guestInstance.guest.setSize(params) : void 0
}) })
// Returns WebContents from its guest id. // Returns WebContents from its guest id.

View file

@ -57,7 +57,7 @@ var dispatchEvent = function (webView, eventName, eventKey, ...args) {
} }
webView.dispatchEvent(domEvent) webView.dispatchEvent(domEvent)
if (eventName === 'load-commit') { if (eventName === 'load-commit') {
return webView.onLoadCommit(domEvent) webView.onLoadCommit(domEvent)
} }
} }
@ -83,7 +83,7 @@ module.exports = {
webView.dispatchEvent(domEvent) webView.dispatchEvent(domEvent)
}) })
return ipcRenderer.on('ELECTRON_GUEST_VIEW_INTERNAL_SIZE_CHANGED-' + viewInstanceId, function (event, ...args) { ipcRenderer.on('ELECTRON_GUEST_VIEW_INTERNAL_SIZE_CHANGED-' + viewInstanceId, function (event, ...args) {
var domEvent, f, i, j, len, ref1 var domEvent, f, i, j, len, ref1
domEvent = new Event('size-changed') domEvent = new Event('size-changed')
ref1 = ['oldWidth', 'oldHeight', 'newWidth', 'newHeight'] ref1 = ['oldWidth', 'oldHeight', 'newWidth', 'newHeight']
@ -98,21 +98,21 @@ module.exports = {
ipcRenderer.removeAllListeners('ELECTRON_GUEST_VIEW_INTERNAL_DESTROY_GUEST-' + viewInstanceId) ipcRenderer.removeAllListeners('ELECTRON_GUEST_VIEW_INTERNAL_DESTROY_GUEST-' + viewInstanceId)
ipcRenderer.removeAllListeners('ELECTRON_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-' + viewInstanceId) ipcRenderer.removeAllListeners('ELECTRON_GUEST_VIEW_INTERNAL_DISPATCH_EVENT-' + viewInstanceId)
ipcRenderer.removeAllListeners('ELECTRON_GUEST_VIEW_INTERNAL_IPC_MESSAGE-' + viewInstanceId) ipcRenderer.removeAllListeners('ELECTRON_GUEST_VIEW_INTERNAL_IPC_MESSAGE-' + viewInstanceId)
return ipcRenderer.removeAllListeners('ELECTRON_GUEST_VIEW_INTERNAL_SIZE_CHANGED-' + viewInstanceId) ipcRenderer.removeAllListeners('ELECTRON_GUEST_VIEW_INTERNAL_SIZE_CHANGED-' + viewInstanceId)
}, },
createGuest: function (params, callback) { createGuest: function (params, callback) {
requestId++ requestId++
ipcRenderer.send('ELECTRON_GUEST_VIEW_MANAGER_CREATE_GUEST', params, requestId) ipcRenderer.send('ELECTRON_GUEST_VIEW_MANAGER_CREATE_GUEST', params, requestId)
return ipcRenderer.once('ELECTRON_RESPONSE_' + requestId, callback) ipcRenderer.once('ELECTRON_RESPONSE_' + requestId, callback)
}, },
attachGuest: function (elementInstanceId, guestInstanceId, params) { attachGuest: function (elementInstanceId, guestInstanceId, params) {
ipcRenderer.send('ELECTRON_GUEST_VIEW_MANAGER_ATTACH_GUEST', elementInstanceId, guestInstanceId, params) ipcRenderer.send('ELECTRON_GUEST_VIEW_MANAGER_ATTACH_GUEST', elementInstanceId, guestInstanceId, params)
return webFrame.attachGuest(elementInstanceId) webFrame.attachGuest(elementInstanceId)
}, },
destroyGuest: function (guestInstanceId) { destroyGuest: function (guestInstanceId) {
return ipcRenderer.send('ELECTRON_GUEST_VIEW_MANAGER_DESTROY_GUEST', guestInstanceId) ipcRenderer.send('ELECTRON_GUEST_VIEW_MANAGER_DESTROY_GUEST', guestInstanceId)
}, },
setSize: function (guestInstanceId, params) { setSize: function (guestInstanceId, params) {
return ipcRenderer.send('ELECTRON_GUEST_VIEW_MANAGER_SET_SIZE', guestInstanceId, params) ipcRenderer.send('ELECTRON_GUEST_VIEW_MANAGER_SET_SIZE', guestInstanceId, params)
} }
} }

View file

@ -32,7 +32,7 @@ class WebViewAttribute {
// Sets the attribute's value. // Sets the attribute's value.
setValue (value) { setValue (value) {
return this.webViewImpl.webviewNode.setAttribute(this.name, value || '') this.webViewImpl.webviewNode.setAttribute(this.name, value || '')
} }
// Changes the attribute's value without triggering its mutation handler. // Changes the attribute's value without triggering its mutation handler.
@ -67,9 +67,9 @@ class BooleanAttribute extends WebViewAttribute {
setValue (value) { setValue (value) {
if (!value) { if (!value) {
return this.webViewImpl.webviewNode.removeAttribute(this.name) this.webViewImpl.webviewNode.removeAttribute(this.name)
} else { } else {
return this.webViewImpl.webviewNode.setAttribute(this.name, '') this.webViewImpl.webviewNode.setAttribute(this.name, '')
} }
} }
} }
@ -84,7 +84,7 @@ class AutosizeDimensionAttribute extends WebViewAttribute {
if (!this.webViewImpl.guestInstanceId) { if (!this.webViewImpl.guestInstanceId) {
return return
} }
return guestViewInternal.setSize(this.webViewImpl.guestInstanceId, { guestViewInternal.setSize(this.webViewImpl.guestInstanceId, {
enableAutoSize: this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_AUTOSIZE].getValue(), enableAutoSize: this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_AUTOSIZE].getValue(),
min: { min: {
width: parseInt(this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_MINWIDTH].getValue() || 0), width: parseInt(this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_MINWIDTH].getValue() || 0),
@ -125,7 +125,7 @@ class PartitionAttribute extends WebViewAttribute {
} }
if (newValue === 'persist:') { if (newValue === 'persist:') {
this.validPartitionId = false this.validPartitionId = false
return window.console.error(webViewConstants.ERROR_MSG_INVALID_PARTITION_ATTRIBUTE) window.console.error(webViewConstants.ERROR_MSG_INVALID_PARTITION_ATTRIBUTE)
} }
} }
} }
@ -141,18 +141,15 @@ class GuestInstanceAttribute extends WebViewAttribute {
if (this.webViewImpl.webviewNode.hasAttribute(this.name)) { if (this.webViewImpl.webviewNode.hasAttribute(this.name)) {
return parseInt(this.webViewImpl.webviewNode.getAttribute(this.name)) return parseInt(this.webViewImpl.webviewNode.getAttribute(this.name))
} }
return undefined
} }
// Sets the attribute's value. // Sets the attribute's value.
setValue (value) { setValue (value) {
if (!value) { if (!value) {
return this.webViewImpl.webviewNode.removeAttribute(this.name) this.webViewImpl.webviewNode.removeAttribute(this.name)
} else if (!isNaN(value)) {
this.webViewImpl.webviewNode.setAttribute(this.name, value)
} }
if (isNaN(value)) {
return
}
return this.webViewImpl.webviewNode.setAttribute(this.name, value)
} }
handleMutation (oldValue, newValue) { handleMutation (oldValue, newValue) {
@ -192,7 +189,7 @@ class SrcAttribute extends WebViewAttribute {
// is possible for this change to get picked up asyncronously by src's // is possible for this change to get picked up asyncronously by src's
// mutation observer |observer|, and then get handled even though we do not // mutation observer |observer|, and then get handled even though we do not
// want to handle this mutation. // want to handle this mutation.
return this.observer.takeRecords() this.observer.takeRecords()
} }
handleMutation (oldValue, newValue) { handleMutation (oldValue, newValue) {
@ -206,7 +203,7 @@ class SrcAttribute extends WebViewAttribute {
this.setValueIgnoreMutation(oldValue) this.setValueIgnoreMutation(oldValue)
return return
} }
return this.parse() this.parse()
} }
// The purpose of this mutation observer is to catch assignment to the src // The purpose of this mutation observer is to catch assignment to the src
@ -232,7 +229,7 @@ class SrcAttribute extends WebViewAttribute {
attributeOldValue: true, attributeOldValue: true,
attributeFilter: [this.name] attributeFilter: [this.name]
} }
return this.observer.observe(this.webViewImpl.webviewNode, params) this.observer.observe(this.webViewImpl.webviewNode, params)
} }
parse () { parse () {
@ -259,7 +256,7 @@ class SrcAttribute extends WebViewAttribute {
opts.userAgent = useragent opts.userAgent = useragent
} }
guestContents = remote.getGuestWebContents(this.webViewImpl.guestInstanceId) guestContents = remote.getGuestWebContents(this.webViewImpl.guestInstanceId)
return guestContents.loadURL(this.getValue(), opts) guestContents.loadURL(this.getValue(), opts)
} }
} }

View file

@ -82,7 +82,7 @@ var WebViewImpl = (function () {
// Sets the <webview>.request property. // Sets the <webview>.request property.
WebViewImpl.prototype.setRequestPropertyOnWebViewNode = function (request) { WebViewImpl.prototype.setRequestPropertyOnWebViewNode = function (request) {
return Object.defineProperty(this.webviewNode, 'request', { Object.defineProperty(this.webviewNode, 'request', {
value: request, value: request,
enumerable: true enumerable: true
}) })
@ -119,7 +119,7 @@ var WebViewImpl = (function () {
} }
// Let the changed attribute handle its own mutation // Let the changed attribute handle its own mutation
return this.attributes[attributeName].handleMutation(oldValue, newValue) this.attributes[attributeName].handleMutation(oldValue, newValue)
} }
WebViewImpl.prototype.handleBrowserPluginAttributeMutation = function (attributeName, oldValue, newValue) { WebViewImpl.prototype.handleBrowserPluginAttributeMutation = function (attributeName, oldValue, newValue) {
@ -129,10 +129,9 @@ var WebViewImpl = (function () {
// Track when the element resizes using the element resize callback. // Track when the element resizes using the element resize callback.
webFrame.registerElementResizeCallback(this.internalInstanceId, this.onElementResize.bind(this)) webFrame.registerElementResizeCallback(this.internalInstanceId, this.onElementResize.bind(this))
if (!this.guestInstanceId) { if (this.guestInstanceId) {
return guestViewInternal.attachGuest(this.internalInstanceId, this.guestInstanceId, this.buildParams())
} }
return guestViewInternal.attachGuest(this.internalInstanceId, this.guestInstanceId, this.buildParams())
} }
} }
@ -157,7 +156,7 @@ var WebViewImpl = (function () {
// Only fire the DOM event if the size of the <webview> has actually // Only fire the DOM event if the size of the <webview> has actually
// changed. // changed.
return this.dispatchEvent(webViewEvent) this.dispatchEvent(webViewEvent)
} }
} }
@ -177,7 +176,7 @@ var WebViewImpl = (function () {
resizeEvent.newHeight = newSize.height resizeEvent.newHeight = newSize.height
this.dispatchEvent(resizeEvent) this.dispatchEvent(resizeEvent)
if (this.guestInstanceId) { if (this.guestInstanceId) {
return guestViewInternal.setSize(this.guestInstanceId, { guestViewInternal.setSize(this.guestInstanceId, {
normal: newSize normal: newSize
}) })
} }
@ -190,7 +189,7 @@ var WebViewImpl = (function () {
} }
WebViewImpl.prototype.dispatchEvent = function (webViewEvent) { WebViewImpl.prototype.dispatchEvent = function (webViewEvent) {
return this.webviewNode.dispatchEvent(webViewEvent) this.webviewNode.dispatchEvent(webViewEvent)
} }
// Adds an 'on<event>' property on the webview, which can be used to set/unset // Adds an 'on<event>' property on the webview, which can be used to set/unset
@ -284,10 +283,9 @@ var registerBrowserPluginElement = function () {
proto.attributeChangedCallback = function (name, oldValue, newValue) { proto.attributeChangedCallback = function (name, oldValue, newValue) {
var internal var internal
internal = v8Util.getHiddenValue(this, 'internal') internal = v8Util.getHiddenValue(this, 'internal')
if (!internal) { if (internal) {
return internal.handleBrowserPluginAttributeMutation(name, oldValue, newValue)
} }
return internal.handleBrowserPluginAttributeMutation(name, oldValue, newValue)
} }
proto.attachedCallback = function () { proto.attachedCallback = function () {
// Load the plugin immediately. // Load the plugin immediately.
@ -313,10 +311,9 @@ var registerWebViewElement = function () {
proto.attributeChangedCallback = function (name, oldValue, newValue) { proto.attributeChangedCallback = function (name, oldValue, newValue) {
var internal var internal
internal = v8Util.getHiddenValue(this, 'internal') internal = v8Util.getHiddenValue(this, 'internal')
if (!internal) { if (internal) {
return internal.handleWebviewAttributeMutation(name, oldValue, newValue)
} }
return internal.handleWebviewAttributeMutation(name, oldValue, newValue)
} }
proto.detachedCallback = function () { proto.detachedCallback = function () {
var internal var internal
@ -340,9 +337,10 @@ var registerWebViewElement = function () {
internal.elementAttached = true internal.elementAttached = true
instance = internal.attributes[webViewConstants.ATTRIBUTE_GUESTINSTANCE].getValue() instance = internal.attributes[webViewConstants.ATTRIBUTE_GUESTINSTANCE].getValue()
if (instance) { if (instance) {
return internal.attachGuestInstance(instance) internal.attachGuestInstance(instance)
} else {
internal.attributes[webViewConstants.ATTRIBUTE_SRC].parse()
} }
return internal.attributes[webViewConstants.ATTRIBUTE_SRC].parse()
} }
} }
@ -424,7 +422,7 @@ var registerWebViewElement = function () {
createNonBlockHandler = function (m) { createNonBlockHandler = function (m) {
return function (...args) { return function (...args) {
const internal = v8Util.getHiddenValue(this, 'internal') const internal = v8Util.getHiddenValue(this, 'internal')
return 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 (j = 0, len1 = nonblockMethods.length; j < len1; j++) { for (j = 0, len1 = nonblockMethods.length; j < len1; j++) {
@ -460,7 +458,7 @@ var registerWebViewElement = function () {
delete proto.createdCallback delete proto.createdCallback
delete proto.attachedCallback delete proto.attachedCallback
delete proto.detachedCallback delete proto.detachedCallback
return delete proto.attributeChangedCallback delete proto.attributeChangedCallback
} }
var useCapture = true var useCapture = true
@ -471,7 +469,7 @@ var listener = function (event) {
} }
registerBrowserPluginElement() registerBrowserPluginElement()
registerWebViewElement() registerWebViewElement()
return window.removeEventListener(event.type, listener, useCapture) window.removeEventListener(event.type, listener, useCapture)
} }
window.addEventListener('readystatechange', listener, true) window.addEventListener('readystatechange', listener, true)