mirror of
https://github.com/electron/electron.git
synced 2026-01-28 00:38:35 -05:00
refactor: add prefer-const to .eslintrc + fix errors (#14880)
This commit is contained in:
committed by
Samuel Attard
parent
07161a8452
commit
3ad3ade828
@@ -42,7 +42,7 @@ Object.assign(app, {
|
||||
|
||||
const nativeFn = app.getAppMetrics
|
||||
app.getAppMetrics = () => {
|
||||
let metrics = nativeFn.call(app)
|
||||
const metrics = nativeFn.call(app)
|
||||
for (const metric of metrics) {
|
||||
if ('memory' in metric) {
|
||||
deprecate.removeProperty(metric, 'memory')
|
||||
@@ -96,7 +96,7 @@ app.allowNTLMCredentialsForAllDomains = function (allow) {
|
||||
if (!process.noDeprecations) {
|
||||
deprecate.warn('app.allowNTLMCredentialsForAllDomains', 'session.allowNTLMCredentialsForDomains')
|
||||
}
|
||||
let domains = allow ? '*' : ''
|
||||
const domains = allow ? '*' : ''
|
||||
if (!this.isReady()) {
|
||||
this.commandLine.appendSwitch('auth-server-whitelist', domains)
|
||||
} else {
|
||||
@@ -106,7 +106,7 @@ app.allowNTLMCredentialsForAllDomains = function (allow) {
|
||||
|
||||
// Routes the events to webContents.
|
||||
const events = ['login', 'certificate-error', 'select-client-certificate']
|
||||
for (let name of events) {
|
||||
for (const name of events) {
|
||||
app.on(name, (event, webContents, ...args) => {
|
||||
webContents.emit(name, event, ...args)
|
||||
})
|
||||
|
||||
@@ -17,7 +17,7 @@ const isSameArgs = (args) => args.length === spawnedArgs.length && args.every((e
|
||||
|
||||
// Spawn a command and invoke the callback when it completes with an error
|
||||
// and the output from standard out.
|
||||
let spawnUpdate = function (args, detached, callback) {
|
||||
const spawnUpdate = function (args, detached, callback) {
|
||||
let error, errorEmitted, stderr, stdout
|
||||
|
||||
try {
|
||||
|
||||
@@ -41,14 +41,14 @@ BrowserWindow.prototype._init = function () {
|
||||
this.webContents.on('-add-new-contents', (event, webContents, disposition,
|
||||
userGesture, left, top, width,
|
||||
height) => {
|
||||
let urlFrameName = v8Util.getHiddenValue(webContents, 'url-framename')
|
||||
const urlFrameName = v8Util.getHiddenValue(webContents, 'url-framename')
|
||||
if ((disposition !== 'foreground-tab' && disposition !== 'new-window' &&
|
||||
disposition !== 'background-tab') || !urlFrameName) {
|
||||
event.preventDefault()
|
||||
return
|
||||
}
|
||||
|
||||
let { url, frameName } = urlFrameName
|
||||
const { url, frameName } = urlFrameName
|
||||
v8Util.deleteHiddenValue(webContents, 'url-framename')
|
||||
const options = {
|
||||
show: true,
|
||||
@@ -115,7 +115,7 @@ BrowserWindow.prototype._init = function () {
|
||||
}
|
||||
|
||||
const visibilityEvents = ['show', 'hide', 'minimize', 'maximize', 'restore']
|
||||
for (let event of visibilityEvents) {
|
||||
for (const event of visibilityEvents) {
|
||||
this.on(event, visibilityChanged)
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ BrowserWindow.getAllWindows = () => {
|
||||
}
|
||||
|
||||
BrowserWindow.getFocusedWindow = () => {
|
||||
for (let window of BrowserWindow.getAllWindows()) {
|
||||
for (const window of BrowserWindow.getAllWindows()) {
|
||||
if (window.isFocused() || window.isDevToolsFocused()) return window
|
||||
}
|
||||
return null
|
||||
|
||||
@@ -284,7 +284,7 @@ module.exports = {
|
||||
},
|
||||
|
||||
showCertificateTrustDialog: function (...args) {
|
||||
let [window, options, callback] = parseArgs(...args)
|
||||
const [window, options, callback] = parseArgs(...args)
|
||||
|
||||
if (options == null || typeof options !== 'object') {
|
||||
throw new TypeError('options must be an object')
|
||||
|
||||
@@ -8,7 +8,7 @@ const MenuItem = function (options) {
|
||||
const { Menu } = require('electron')
|
||||
|
||||
// Preserve extra fields specified by user
|
||||
for (let key in options) {
|
||||
for (const key in options) {
|
||||
if (!(key in this)) this[key] = options[key]
|
||||
}
|
||||
if (typeof this.role === 'string' || this.role instanceof String) {
|
||||
|
||||
@@ -180,7 +180,7 @@ function areValidTemplateItems (template) {
|
||||
|
||||
function sortTemplate (template) {
|
||||
const sorted = sortMenuItems(template)
|
||||
for (let id in sorted) {
|
||||
for (const id in sorted) {
|
||||
const item = sorted[id]
|
||||
if (Array.isArray(item.submenu)) {
|
||||
item.submenu = sortTemplate(item.submenu)
|
||||
|
||||
@@ -141,11 +141,10 @@ const NavigationController = (function () {
|
||||
}
|
||||
|
||||
NavigationController.prototype.goToOffset = function (offset) {
|
||||
let pendingIndex
|
||||
if (!this.canGoToOffset(offset)) {
|
||||
return
|
||||
}
|
||||
pendingIndex = this.currentIndex + offset
|
||||
const pendingIndex = this.currentIndex + offset
|
||||
if (this.inPageIndex > -1 && pendingIndex >= this.inPageIndex) {
|
||||
this.pendingIndex = pendingIndex
|
||||
return this.webContents._goToOffset(offset)
|
||||
|
||||
@@ -119,7 +119,7 @@ class ClientRequest extends EventEmitter {
|
||||
let urlStr = options.url
|
||||
|
||||
if (!urlStr) {
|
||||
let urlObj = {}
|
||||
const urlObj = {}
|
||||
const protocol = options.protocol || 'http:'
|
||||
if (!kSupportedProtocols.has(protocol)) {
|
||||
throw new Error('Protocol "' + protocol + '" not supported. ')
|
||||
@@ -149,7 +149,7 @@ class ClientRequest extends EventEmitter {
|
||||
// an invalid request.
|
||||
throw new TypeError('Request path contains unescaped characters.')
|
||||
}
|
||||
let pathObj = url.parse(options.path || '/')
|
||||
const pathObj = url.parse(options.path || '/')
|
||||
urlObj.pathname = pathObj.pathname
|
||||
urlObj.search = pathObj.search
|
||||
urlObj.hash = pathObj.hash
|
||||
@@ -161,7 +161,7 @@ class ClientRequest extends EventEmitter {
|
||||
throw new Error('redirect mode should be one of follow, error or manual')
|
||||
}
|
||||
|
||||
let urlRequestOptions = {
|
||||
const urlRequestOptions = {
|
||||
method: method,
|
||||
url: urlStr,
|
||||
redirect: redirectPolicy
|
||||
@@ -180,7 +180,7 @@ class ClientRequest extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
let urlRequest = new URLRequest(urlRequestOptions)
|
||||
const urlRequest = new URLRequest(urlRequestOptions)
|
||||
|
||||
// Set back and forward links.
|
||||
this.urlRequest = urlRequest
|
||||
@@ -192,7 +192,7 @@ class ClientRequest extends EventEmitter {
|
||||
this.extraHeaders = {}
|
||||
|
||||
if (options.headers) {
|
||||
for (let key in options.headers) {
|
||||
for (const key in options.headers) {
|
||||
this.setHeader(key, options.headers[key])
|
||||
}
|
||||
}
|
||||
@@ -286,8 +286,8 @@ class ClientRequest extends EventEmitter {
|
||||
}
|
||||
|
||||
_write (chunk, encoding, callback, isLast) {
|
||||
let chunkIsString = typeof chunk === 'string'
|
||||
let chunkIsBuffer = chunk instanceof Buffer
|
||||
const chunkIsString = typeof chunk === 'string'
|
||||
const chunkIsBuffer = chunk instanceof Buffer
|
||||
if (!chunkIsString && !chunkIsBuffer) {
|
||||
throw new TypeError('First argument must be a string or Buffer.')
|
||||
}
|
||||
@@ -306,7 +306,7 @@ class ClientRequest extends EventEmitter {
|
||||
|
||||
// Headers are assumed to be sent on first call to _writeBuffer,
|
||||
// i.e. after the first call to write or end.
|
||||
let result = this.urlRequest.write(chunk, isLast)
|
||||
const result = this.urlRequest.write(chunk, isLast)
|
||||
|
||||
// The write callback is fired asynchronously to mimic Node.js.
|
||||
if (callback) {
|
||||
@@ -318,7 +318,7 @@ class ClientRequest extends EventEmitter {
|
||||
|
||||
write (data, encoding, callback) {
|
||||
if (this.urlRequest.finished) {
|
||||
let error = new Error('Write after end.')
|
||||
const error = new Error('Write after end.')
|
||||
process.nextTick(writeAfterEndNT, this, error, callback)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -317,7 +317,7 @@ module.exports = {
|
||||
|
||||
getFocusedWebContents () {
|
||||
let focused = null
|
||||
for (let contents of binding.getAllWebContents()) {
|
||||
for (const contents of binding.getAllWebContents()) {
|
||||
if (!contents.isFocused()) continue
|
||||
if (focused == null) focused = contents
|
||||
// Return webview web contents which may be embedded inside another
|
||||
|
||||
@@ -51,7 +51,7 @@ class ObjectsRegistry {
|
||||
// then garbage collected in old page).
|
||||
remove (webContents, contextId, id) {
|
||||
const ownerKey = getOwnerKey(webContents, contextId)
|
||||
let owner = this.owners[ownerKey]
|
||||
const owner = this.owners[ownerKey]
|
||||
if (owner) {
|
||||
// Remove the reference in owner.
|
||||
owner.delete(id)
|
||||
@@ -63,10 +63,10 @@ class ObjectsRegistry {
|
||||
// Clear all references to objects refrenced by the WebContents.
|
||||
clear (webContents, contextId) {
|
||||
const ownerKey = getOwnerKey(webContents, contextId)
|
||||
let owner = this.owners[ownerKey]
|
||||
const owner = this.owners[ownerKey]
|
||||
if (!owner) return
|
||||
|
||||
for (let id of owner) this.dereference(id)
|
||||
for (const id of owner) this.dereference(id)
|
||||
|
||||
delete this.owners[ownerKey]
|
||||
}
|
||||
@@ -87,7 +87,7 @@ class ObjectsRegistry {
|
||||
|
||||
// Private: Dereference the object from store.
|
||||
dereference (id) {
|
||||
let pointer = this.storage[id]
|
||||
const pointer = this.storage[id]
|
||||
if (pointer == null) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -37,8 +37,8 @@ const getObjectMembers = function (object) {
|
||||
}
|
||||
// Map properties to descriptors.
|
||||
return names.map((name) => {
|
||||
let descriptor = Object.getOwnPropertyDescriptor(object, name)
|
||||
let member = { name, enumerable: descriptor.enumerable, writable: false }
|
||||
const descriptor = Object.getOwnPropertyDescriptor(object, name)
|
||||
const member = { name, enumerable: descriptor.enumerable, writable: false }
|
||||
if (descriptor.get === undefined && typeof object[name] === 'function') {
|
||||
member.type = 'method'
|
||||
} else {
|
||||
@@ -51,7 +51,7 @@ const getObjectMembers = function (object) {
|
||||
|
||||
// Return the description of object's prototype.
|
||||
const getObjectPrototype = function (object) {
|
||||
let proto = Object.getPrototypeOf(object)
|
||||
const proto = Object.getPrototypeOf(object)
|
||||
if (proto === null || proto === Object.prototype) return null
|
||||
return {
|
||||
members: getObjectMembers(proto),
|
||||
@@ -189,7 +189,7 @@ const unwrapArgs = function (sender, contextId, args) {
|
||||
then: metaToValue(meta.then)
|
||||
})
|
||||
case 'object': {
|
||||
let ret = {}
|
||||
const ret = {}
|
||||
Object.defineProperty(ret.constructor, 'name', { value: meta.name })
|
||||
|
||||
for (const { name, value } of meta.members) {
|
||||
@@ -213,7 +213,7 @@ const unwrapArgs = function (sender, contextId, args) {
|
||||
}
|
||||
|
||||
const processId = sender.getProcessId()
|
||||
let callIntoRenderer = function (...args) {
|
||||
const callIntoRenderer = function (...args) {
|
||||
if (!sender.isDestroyed() && processId === sender.getProcessId()) {
|
||||
sender.send('ELECTRON_RENDERER_CALLBACK', contextId, meta.id, valueToMeta(sender, contextId, args))
|
||||
} else {
|
||||
@@ -295,7 +295,7 @@ handleRemoteCommand('ELECTRON_BROWSER_CURRENT_WEB_CONTENTS', function (event, co
|
||||
|
||||
handleRemoteCommand('ELECTRON_BROWSER_CONSTRUCTOR', function (event, contextId, id, args) {
|
||||
args = unwrapArgs(event.sender, contextId, args)
|
||||
let constructor = objectsRegistry.get(id)
|
||||
const constructor = objectsRegistry.get(id)
|
||||
|
||||
if (constructor == null) {
|
||||
throwRPCError(`Cannot call constructor on missing remote object ${id}`)
|
||||
@@ -306,7 +306,7 @@ handleRemoteCommand('ELECTRON_BROWSER_CONSTRUCTOR', function (event, contextId,
|
||||
|
||||
handleRemoteCommand('ELECTRON_BROWSER_FUNCTION_CALL', function (event, contextId, id, args) {
|
||||
args = unwrapArgs(event.sender, contextId, args)
|
||||
let func = objectsRegistry.get(id)
|
||||
const func = objectsRegistry.get(id)
|
||||
|
||||
if (func == null) {
|
||||
throwRPCError(`Cannot call function on missing remote object ${id}`)
|
||||
@@ -317,7 +317,7 @@ handleRemoteCommand('ELECTRON_BROWSER_FUNCTION_CALL', function (event, contextId
|
||||
|
||||
handleRemoteCommand('ELECTRON_BROWSER_MEMBER_CONSTRUCTOR', function (event, contextId, id, method, args) {
|
||||
args = unwrapArgs(event.sender, contextId, args)
|
||||
let object = objectsRegistry.get(id)
|
||||
const object = objectsRegistry.get(id)
|
||||
|
||||
if (object == null) {
|
||||
throwRPCError(`Cannot call constructor '${method}' on missing remote object ${id}`)
|
||||
@@ -328,7 +328,7 @@ handleRemoteCommand('ELECTRON_BROWSER_MEMBER_CONSTRUCTOR', function (event, cont
|
||||
|
||||
handleRemoteCommand('ELECTRON_BROWSER_MEMBER_CALL', function (event, contextId, id, method, args) {
|
||||
args = unwrapArgs(event.sender, contextId, args)
|
||||
let obj = objectsRegistry.get(id)
|
||||
const obj = objectsRegistry.get(id)
|
||||
|
||||
if (obj == null) {
|
||||
throwRPCError(`Cannot call function '${method}' on missing remote object ${id}`)
|
||||
@@ -339,7 +339,7 @@ handleRemoteCommand('ELECTRON_BROWSER_MEMBER_CALL', function (event, contextId,
|
||||
|
||||
handleRemoteCommand('ELECTRON_BROWSER_MEMBER_SET', function (event, contextId, id, name, args) {
|
||||
args = unwrapArgs(event.sender, contextId, args)
|
||||
let obj = objectsRegistry.get(id)
|
||||
const obj = objectsRegistry.get(id)
|
||||
|
||||
if (obj == null) {
|
||||
throwRPCError(`Cannot set property '${name}' on missing remote object ${id}`)
|
||||
@@ -350,7 +350,7 @@ handleRemoteCommand('ELECTRON_BROWSER_MEMBER_SET', function (event, contextId, i
|
||||
})
|
||||
|
||||
handleRemoteCommand('ELECTRON_BROWSER_MEMBER_GET', function (event, contextId, id, name) {
|
||||
let obj = objectsRegistry.get(id)
|
||||
const obj = objectsRegistry.get(id)
|
||||
|
||||
if (obj == null) {
|
||||
throwRPCError(`Cannot get property '${name}' on missing remote object ${id}`)
|
||||
@@ -369,14 +369,14 @@ handleRemoteCommand('ELECTRON_BROWSER_CONTEXT_RELEASE', (event, contextId) => {
|
||||
})
|
||||
|
||||
handleRemoteCommand('ELECTRON_BROWSER_GUEST_WEB_CONTENTS', function (event, contextId, guestInstanceId) {
|
||||
let guestViewManager = require('@electron/internal/browser/guest-view-manager')
|
||||
const guestViewManager = require('@electron/internal/browser/guest-view-manager')
|
||||
return valueToMeta(event.sender, contextId, guestViewManager.getGuest(guestInstanceId))
|
||||
})
|
||||
|
||||
ipcMain.on('ELECTRON_BROWSER_ASYNC_CALL_TO_GUEST_VIEW', function (event, requestId, guestInstanceId, method, args, hasCallback) {
|
||||
new Promise(resolve => {
|
||||
let guestViewManager = require('./guest-view-manager')
|
||||
let guest = guestViewManager.getGuest(guestInstanceId)
|
||||
const guestViewManager = require('./guest-view-manager')
|
||||
const guest = guestViewManager.getGuest(guestInstanceId)
|
||||
if (guest.hostWebContents !== event.sender) {
|
||||
throw new Error('Access denied')
|
||||
}
|
||||
@@ -396,8 +396,8 @@ ipcMain.on('ELECTRON_BROWSER_ASYNC_CALL_TO_GUEST_VIEW', function (event, request
|
||||
|
||||
ipcMain.on('ELECTRON_BROWSER_SYNC_CALL_TO_GUEST_VIEW', function (event, guestInstanceId, method, args) {
|
||||
try {
|
||||
let guestViewManager = require('@electron/internal/browser/guest-view-manager')
|
||||
let guest = guestViewManager.getGuest(guestInstanceId)
|
||||
const guestViewManager = require('@electron/internal/browser/guest-view-manager')
|
||||
const guest = guestViewManager.getGuest(guestInstanceId)
|
||||
if (guest.hostWebContents !== event.sender) {
|
||||
throw new Error('Access denied')
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ const binding = process.atomBinding('crash_reporter')
|
||||
|
||||
const sendSync = function (channel, ...args) {
|
||||
if (process.type === 'browser') {
|
||||
let event = {}
|
||||
const event = {}
|
||||
electron.ipcMain.emit(channel, event, ...args)
|
||||
return event.returnValue
|
||||
} else {
|
||||
|
||||
@@ -36,7 +36,7 @@ function wrapArgs (args, visited = new Set()) {
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
visited.add(value)
|
||||
let meta = {
|
||||
const meta = {
|
||||
type: 'array',
|
||||
value: wrapArgs(value, visited)
|
||||
}
|
||||
@@ -67,13 +67,13 @@ function wrapArgs (args, visited = new Set()) {
|
||||
}
|
||||
}
|
||||
|
||||
let meta = {
|
||||
const meta = {
|
||||
type: 'object',
|
||||
name: value.constructor ? value.constructor.name : '',
|
||||
members: []
|
||||
}
|
||||
visited.add(value)
|
||||
for (let prop in value) {
|
||||
for (const prop in value) {
|
||||
meta.members.push({
|
||||
name: prop,
|
||||
value: valueToMeta(value[prop])
|
||||
@@ -109,10 +109,10 @@ function wrapArgs (args, visited = new Set()) {
|
||||
function setObjectMembers (ref, object, metaId, members) {
|
||||
if (!Array.isArray(members)) return
|
||||
|
||||
for (let member of members) {
|
||||
for (const member of members) {
|
||||
if (object.hasOwnProperty(member.name)) continue
|
||||
|
||||
let descriptor = { enumerable: member.enumerable }
|
||||
const descriptor = { enumerable: member.enumerable }
|
||||
if (member.type === 'method') {
|
||||
const remoteMemberFunction = function (...args) {
|
||||
let command
|
||||
@@ -163,7 +163,7 @@ function setObjectMembers (ref, object, metaId, members) {
|
||||
// This matches |getObjectPrototype| in rpc-server.
|
||||
function setObjectPrototype (ref, object, metaId, descriptor) {
|
||||
if (descriptor === null) return
|
||||
let proto = {}
|
||||
const proto = {}
|
||||
setObjectMembers(ref, proto, metaId, descriptor.members)
|
||||
setObjectPrototype(ref, proto, metaId, descriptor.proto)
|
||||
Object.setPrototypeOf(object, proto)
|
||||
@@ -201,7 +201,7 @@ function proxyFunctionProperties (remoteMemberFunction, metaId, name) {
|
||||
return Object.getOwnPropertyNames(target)
|
||||
},
|
||||
getOwnPropertyDescriptor: (target, property) => {
|
||||
let descriptor = Object.getOwnPropertyDescriptor(target, property)
|
||||
const descriptor = Object.getOwnPropertyDescriptor(target, property)
|
||||
if (descriptor) return descriptor
|
||||
loadRemoteProperties()
|
||||
return Object.getOwnPropertyDescriptor(target, property)
|
||||
@@ -231,7 +231,7 @@ function metaToValue (meta) {
|
||||
|
||||
// A shadow class to represent the remote function object.
|
||||
if (meta.type === 'function') {
|
||||
let remoteFunction = function (...args) {
|
||||
const remoteFunction = function (...args) {
|
||||
let command
|
||||
if (this && this.constructor === remoteFunction) {
|
||||
command = 'ELECTRON_BROWSER_CONSTRUCTOR'
|
||||
@@ -262,7 +262,7 @@ function metaToValue (meta) {
|
||||
function metaToPlainObject (meta) {
|
||||
const obj = (() => meta.type === 'error' ? new Error() : {})()
|
||||
for (let i = 0; i < meta.members.length; i++) {
|
||||
let { name, value } = meta.members[i]
|
||||
const { name, value } = meta.members[i]
|
||||
obj[name] = value
|
||||
}
|
||||
return obj
|
||||
|
||||
@@ -91,7 +91,7 @@ const getStorageManager = (storageType, extensionId) => {
|
||||
// eslint-disable-next-line standard/no-callback-literal
|
||||
if (keys.length === 0) return callback({})
|
||||
|
||||
let items = {}
|
||||
const items = {}
|
||||
keys.forEach(function (key) {
|
||||
let value = storage[key]
|
||||
if (value == null) value = defaults[key]
|
||||
|
||||
@@ -48,7 +48,7 @@ let preloadScript = null
|
||||
let preloadScripts = []
|
||||
let isBackgroundPage = false
|
||||
let appPath = null
|
||||
for (let arg of process.argv) {
|
||||
for (const arg of process.argv) {
|
||||
if (arg.indexOf('--guest-instance-id=') === 0) {
|
||||
// This is a guest web view.
|
||||
process.guestInstanceId = parseInt(arg.substr(arg.indexOf('=') + 1))
|
||||
|
||||
@@ -19,7 +19,7 @@ v8Util.setHiddenValue(global, 'Buffer', Buffer)
|
||||
v8Util.setHiddenValue(global, 'ipc', new EventEmitter())
|
||||
// The process object created by browserify is not an event emitter, fix it so
|
||||
// the API is more compatible with non-sandboxed renderers.
|
||||
for (let prop of Object.keys(EventEmitter.prototype)) {
|
||||
for (const prop of Object.keys(EventEmitter.prototype)) {
|
||||
if (process.hasOwnProperty(prop)) {
|
||||
delete process[prop]
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ global.module = module
|
||||
|
||||
// Set the __filename to the path of html file if it is file: protocol.
|
||||
if (self.location.protocol === 'file:') {
|
||||
let pathname = process.platform === 'win32' && self.location.pathname[0] === '/' ? self.location.pathname.substr(1) : self.location.pathname
|
||||
const pathname = process.platform === 'win32' && self.location.pathname[0] === '/' ? self.location.pathname.substr(1) : self.location.pathname
|
||||
global.__filename = path.normalize(decodeURIComponent(pathname))
|
||||
global.__dirname = path.dirname(global.__filename)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user