refactor: use `for-of` instead of `for` simple array iteration (#39338)

This commit is contained in:
Milan Burda 2023-08-07 11:30:15 +02:00 коммит произвёл GitHub
Родитель 67523a47b4
Коммит 3d45429667
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 20 добавлений и 20 удалений

Просмотреть файл

@ -194,8 +194,8 @@ const messageBox = (sync: boolean, window: BrowserWindow | null, options?: Messa
if (cancelId == null) {
// If the defaultId is set to 0, ensure the cancel button is a different index (1)
cancelId = (defaultId === 0 && buttons.length > 1) ? 1 : 0;
for (let i = 0; i < buttons.length; i++) {
const text = buttons[i].toLowerCase();
for (const [i, button] of buttons.entries()) {
const text = button.toLowerCase();
if (text === 'cancel' || text === 'no') {
cancelId = i;
break;

Просмотреть файл

@ -60,8 +60,8 @@ ifdescribe(!process.arch.includes('arm') && process.platform !== 'win32')('deskt
const sources = await desktopCapturer.getSources({ types: ['screen'] });
expect(sources).to.be.an('array').of.length(displays.length);
for (let i = 0; i < sources.length; i++) {
expect(sources[i].display_id).to.equal(displays[i].id.toString());
for (const [i, source] of sources.entries()) {
expect(source.display_id).to.equal(displays[i].id.toString());
}
});

Просмотреть файл

@ -133,14 +133,14 @@ describe('renderer nodeIntegrationInSubFrames', () => {
const generateConfigs = (webPreferences: any, ...permutations: {name: string, webPreferences: any}[]) => {
const configs = [{ webPreferences, names: [] as string[] }];
for (let i = 0; i < permutations.length; i++) {
for (const permutation of permutations) {
const length = configs.length;
for (let j = 0; j < length; j++) {
const newConfig = Object.assign({}, configs[j]);
newConfig.webPreferences = Object.assign({},
newConfig.webPreferences, permutations[i].webPreferences);
newConfig.webPreferences, permutation.webPreferences);
newConfig.names = newConfig.names.slice(0);
newConfig.names.push(permutations[i].name);
newConfig.names.push(permutation.name);
configs.push(newConfig);
}
}

Просмотреть файл

@ -313,16 +313,16 @@ function bitsToBuffer (bits) {
function generateEBML (json) {
const ebml = [];
for (let i = 0; i < json.length; i++) {
if (!('id' in json[i])) {
for (const item of json) {
if (!('id' in item)) {
// already encoded blob or byteArray
ebml.push(json[i]);
ebml.push(item);
continue;
}
let data = json[i].data;
let data = item.data;
if (typeof data === 'object') data = generateEBML(data);
if (typeof data === 'number') data = ('size' in json[i]) ? numToFixedBuffer(data, json[i].size) : bitsToBuffer(data.toString(2));
if (typeof data === 'number') data = ('size' in item) ? numToFixedBuffer(data, item.size) : bitsToBuffer(data.toString(2));
if (typeof data === 'string') data = strToBuffer(data);
const len = data.size || data.byteLength || data.length;
@ -335,7 +335,7 @@ function generateEBML (json) {
// going to fix this, i'm probably just going to write some hacky thing which
// converts that string into a buffer-esque thing
ebml.push(numToBuffer(json[i].id));
ebml.push(numToBuffer(item.id));
ebml.push(bitsToBuffer(size));
ebml.push(data);
}
@ -349,13 +349,13 @@ function toFlatArray (arr, outBuffer) {
if (outBuffer == null) {
outBuffer = [];
}
for (let i = 0; i < arr.length; i++) {
if (typeof arr[i] === 'object') {
for (const item of arr) {
if (typeof item === 'object') {
// an array
toFlatArray(arr[i], outBuffer);
toFlatArray(item, outBuffer);
} else {
// a simple element
outBuffer.push(arr[i]);
outBuffer.push(item);
}
}
return outBuffer;

Просмотреть файл

@ -74,14 +74,14 @@ crashReporter.start({
// https://github.com/electron/electron/blob/main/docs/api/desktop-capturer.md
getSources({ types: ['window', 'screen'] }).then(sources => {
for (let i = 0; i < sources.length; ++i) {
if (sources[i].name === 'Electron') {
for (const source of sources) {
if (source.name === 'Electron') {
(navigator as any).webkitGetUserMedia({
audio: false,
video: {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: sources[i].id,
chromeMediaSourceId: source.id,
minWidth: 1280,
maxWidth: 1280,
minHeight: 720,