8000 fix: remove bad usages of for-in and guard against it by MarshallOfSound · Pull Request #22616 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: remove bad usages of for-in and guard against it #22616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"no-var": "error",
"no-unused-vars": 0,
"no-global-assign": 0,
"guard-for-in": 2,
"@typescript-eslint/no-unused-vars": ["error", {
"vars": "all",
"args": "after-used",
Expand Down
5 changes: 2 additions & 3 deletions lib/browser/api/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const delegate = {
},
menuWillShow: (menu) => {
// Ensure radio groups have at least one menu item selected
for (const id in menu.groupsMap) {
for (const id of Object.keys(menu.groupsMap)) {
const found = menu.groupsMap[id].find(item => item.checked) || null
if (!found) v8Util.setHiddenValue(menu.groupsMap[id][0], 'checked', true)
}
Expand Down Expand Up @@ -201,8 +201,7 @@ function areValidTemplateItems (template) {

function sortTemplate (template) {
const sorted = sortMenuItems(template)
for (const id in sorted) {
const item = sorted[id]
for (const item of sorted) {
if (Array.isArray(item.submenu)) {
item.submenu = sortTemplate(item.submenu)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/api/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class ClientRequest extends Writable {
this._started = true
const stringifyValues = (obj) => {
const ret = {}
for (const k in obj) {
for (const k of Object.keys(obj)) {
ret[k] = obj[k].toString()
}
return ret
Expand Down
6 changes: 3 additions & 3 deletions lib/browser/guest-view-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const createGuest = function (embedder, params) {

// Clear the guest from map when it is destroyed.
guest.once('destroyed', () => {
if (guestInstanceId in guestInstances) {
if (Object.prototype.hasOwnProperty.call(guestInstances, guestInstanceId)) {
detachGuest(embedder, guestInstanceId)
}
})
Expand Down Expand Up @@ -288,7 +288,7 @@ const watchEmbedder = function (embedder) {

// Forward embedder window visiblity change events to guest
const (visibilityState) {
for (const guestInstanceId in guestInstances) {
for (const guestInstanceId of Object.keys(guestInstances)) {
const guestInstance = guestInstances[guestInstanceId]
guestInstance.visibilityState = visibilityState
if (guestInstance.embedder === embedder) {
Expand All @@ -302,7 +302,7 @@ const watchEmbedder = function (embedder) {
// Usually the guestInstances is cleared when guest is destroyed, but it
// may happen that the embedder gets manually destroyed earlier than guest,
// and the embedder will be invalid in the usual code path.
for (const guestInstanceId in guestInstances) {
for (const guestInstanceId of Object.keys(guestInstances)) {
const guestInstance = guestInstances[guestInstanceId]
if (guestInstance.embedder === embedder) {
detachGuest(embedder, parseInt(guestInstanceId))
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function createLazyInstance (
) {
let lazyModule: Object
const module: any = {}
for (const method in (holder as any).prototype) {
for (const method in (holder as any).prototype) { // eslint-disable-line guard-for-in
module[method] = (...args: any) => {
// create new instance of module at runtime if none exists
if (!lazyModule) {
Expand Down
4 changes: 2 additions & 2 deletions lib/renderer/api/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function wrapArgs (args, visited = new Set()) {
members: []
}
visited.add(value)
for (const prop in value) {
for (const prop in value) { // eslint-disable-line guard-for-in
meta.members.push({
name: prop,
value: valueToMeta(value[prop])
Expand Down Expand Up @@ -219,7 +219,7 @@ function metaToValue (meta) {
exception: () => { throw metaToError(meta.value) }
}

if (meta.type in types) {
if (Object.prototype.hasOwnProperty.call(types, meta.type)) {
return types[meta.type]()
} else {
let ret
Expand Down
2 changes: 1 addition & 1 deletion spec/expect-helpers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function resolveSingleObjectGetters (object) {
if (object && typeof object === 'object') {
const newObject = {}
for (const key in object) {
for (const key in object) { // eslint-disable-line guard-for-in
newObject[key] = resolveGetters(object[key])[0]
}
return newObject
Expand Down
0