mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
wip
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
"root": true,
|
||||
"extends": "standard",
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"plugins": ["@typescript-eslint"],
|
||||
"plugins": ["@typescript-eslint", "unicorn"],
|
||||
"env": {
|
||||
"browser": true
|
||||
},
|
||||
@@ -19,7 +19,8 @@
|
||||
"prefer-const": ["error", {
|
||||
"destructuring": "all"
|
||||
}],
|
||||
"standard/no-callback-literal": "off"
|
||||
"standard/no-callback-literal": "off",
|
||||
"unicorn/no-this-assignment": "error"
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 6,
|
||||
|
||||
@@ -319,7 +319,7 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
||||
const wrapRealpathSync = function (realpathSync: Function) {
|
||||
return function (this: any, pathArgument: string, options: any) {
|
||||
const pathInfo = splitPath(pathArgument);
|
||||
if (!pathInfo.isAsar) return realpathSync.apply(this, arguments);
|
||||
if (!pathInfo.isAsar) return Reflect.apply(realpathSync, this, arguments);
|
||||
const { asarPath, filePath } = pathInfo;
|
||||
|
||||
const archive = getOrCreateArchive(asarPath);
|
||||
@@ -343,7 +343,7 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
||||
const wrapRealpath = function (realpath: Function) {
|
||||
return function (this: any, pathArgument: string, options: any, callback: any) {
|
||||
const pathInfo = splitPath(pathArgument);
|
||||
if (!pathInfo.isAsar) return realpath.apply(this, arguments);
|
||||
if (!pathInfo.isAsar) return Reflect.apply(realpath, this, arguments);
|
||||
const { asarPath, filePath } = pathInfo;
|
||||
|
||||
if (arguments.length < 3) {
|
||||
@@ -428,7 +428,7 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
||||
const { access } = fs;
|
||||
fs.access = function (pathArgument: string, mode: any, callback: any) {
|
||||
const pathInfo = splitPath(pathArgument);
|
||||
if (!pathInfo.isAsar) return access.apply(this, arguments);
|
||||
if (!pathInfo.isAsar) return Reflect.apply(access, this, arguments);
|
||||
const { asarPath, filePath } = pathInfo;
|
||||
|
||||
if (typeof mode === 'function') {
|
||||
@@ -476,7 +476,7 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
||||
const { accessSync } = fs;
|
||||
fs.accessSync = function (pathArgument: string, mode: any) {
|
||||
const pathInfo = splitPath(pathArgument);
|
||||
if (!pathInfo.isAsar) return accessSync.apply(this, arguments);
|
||||
if (!pathInfo.isAsar) return Reflect.apply(accessSync, this, arguments);
|
||||
const { asarPath, filePath } = pathInfo;
|
||||
|
||||
if (mode == null) mode = fs.constants.F_OK;
|
||||
@@ -567,7 +567,7 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
||||
fs.readFile = function (pathArgument: string, options: any, callback: any) {
|
||||
const pathInfo = splitPath(pathArgument);
|
||||
if (!pathInfo.isAsar) {
|
||||
return readFile.apply(this, arguments);
|
||||
return Reflect.apply(readFile, this, arguments);
|
||||
}
|
||||
|
||||
return fsReadFileAsar(pathArgument, options, callback);
|
||||
@@ -577,7 +577,7 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
||||
fs.promises.readFile = function (pathArgument: string, options: any) {
|
||||
const pathInfo = splitPath(pathArgument);
|
||||
if (!pathInfo.isAsar) {
|
||||
return readFilePromise.apply(this, arguments);
|
||||
return Reflect.apply(readFilePromise, this, arguments);
|
||||
}
|
||||
|
||||
const p = util.promisify(fsReadFileAsar);
|
||||
@@ -587,7 +587,7 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
||||
const { readFileSync } = fs;
|
||||
fs.readFileSync = function (pathArgument: string, options: any) {
|
||||
const pathInfo = splitPath(pathArgument);
|
||||
if (!pathInfo.isAsar) return readFileSync.apply(this, arguments);
|
||||
if (!pathInfo.isAsar) return Reflect.apply(readFileSync, this, arguments);
|
||||
const { asarPath, filePath } = pathInfo;
|
||||
|
||||
const archive = getOrCreateArchive(asarPath);
|
||||
@@ -628,7 +628,7 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
||||
callback = options;
|
||||
options = undefined;
|
||||
}
|
||||
if (!pathInfo.isAsar) return readdir.apply(this, arguments);
|
||||
if (!pathInfo.isAsar) return Reflect.apply(readdir, this, arguments);
|
||||
const { asarPath, filePath } = pathInfo;
|
||||
|
||||
const archive = getOrCreateArchive(asarPath);
|
||||
@@ -677,7 +677,7 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
||||
const { readdirSync } = fs;
|
||||
fs.readdirSync = function (pathArgument: string, options: ReaddirSyncOptions | BufferEncoding | null) {
|
||||
const pathInfo = splitPath(pathArgument);
|
||||
if (!pathInfo.isAsar) return readdirSync.apply(this, arguments);
|
||||
if (!pathInfo.isAsar) return Reflect.apply(readdirSync, this, arguments);
|
||||
const { asarPath, filePath } = pathInfo;
|
||||
|
||||
const archive = getOrCreateArchive(asarPath);
|
||||
@@ -793,7 +793,7 @@ export const wrapFsWithAsar = (fs: Record<string, any>) => {
|
||||
const processNoAsarOriginalValue = process.noAsar;
|
||||
process.noAsar = true;
|
||||
try {
|
||||
return func.apply(this, arguments);
|
||||
return Reflect.apply(func, this, arguments);
|
||||
} finally {
|
||||
process.noAsar = processNoAsarOriginalValue;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -52,7 +52,7 @@ export function removeFunction<T extends Function> (fn: T, removedName: string):
|
||||
const warn = warnOnce(`${fn.name} function`);
|
||||
return function (this: any) {
|
||||
warn();
|
||||
fn.apply(this, arguments);
|
||||
Reflect.apply(fn, this, arguments);
|
||||
} as unknown as typeof fn;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ export function renameFunction<T extends Function> (fn: T, newName: string): T {
|
||||
const warn = warnOnce(`${fn.name} function`, `${newName} function`);
|
||||
return function (this: any) {
|
||||
warn();
|
||||
return fn.apply(this, arguments);
|
||||
return Reflect.apply(fn, this, arguments);
|
||||
} as unknown as typeof fn;
|
||||
}
|
||||
|
||||
@@ -138,6 +138,6 @@ export function moveAPI<T extends Function> (fn: T, oldUsage: string, newUsage:
|
||||
const warn = warnOnce(oldUsage, newUsage);
|
||||
return function (this: any) {
|
||||
warn();
|
||||
return fn.apply(this, arguments);
|
||||
return Reflect.apply(fn, this, arguments);
|
||||
} as unknown as typeof fn;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ if (process.type === 'renderer') {
|
||||
if (request === 'vm') {
|
||||
console.warn('The vm module of Node.js is deprecated in the renderer process and will be removed.');
|
||||
}
|
||||
return _load.apply(this, arguments);
|
||||
return Reflect.apply(_load, this, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -2265,7 +2265,7 @@ describe('net module', () => {
|
||||
const resp = await net.fetch(url.pathToFileURL(path.join(__dirname, 'fixtures', 'hello.txt')).toString());
|
||||
expect(resp.ok).to.be.true();
|
||||
// trimRight instead of asserting the whole string to avoid line ending shenanigans on WOA
|
||||
expect((await resp.text()).trimRight()).to.equal('hello world');
|
||||
expect((await resp.text()).trimEnd()).to.equal('hello world');
|
||||
});
|
||||
|
||||
it('can make requests to custom protocols', async () => {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
2
spec/fixtures/extensions/chrome-api/main.js
vendored
2
spec/fixtures/extensions/chrome-api/main.js
vendored
@@ -33,7 +33,7 @@ const testMap = {
|
||||
connectTab (name) {
|
||||
chrome.runtime.onConnect.addListener(port => {
|
||||
port.onMessage.addListener(message => {
|
||||
console.log([port.name, message].join());
|
||||
console.log([port.name, message].join(','));
|
||||
});
|
||||
});
|
||||
chrome.runtime.sendMessage({ method: 'connectTab', args: [name] });
|
||||
|
||||
@@ -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 element of json) {
|
||||
if (!('id' in element)) {
|
||||
// already encoded blob or byteArray
|
||||
ebml.push(json[i]);
|
||||
ebml.push(element);
|
||||
continue;
|
||||
}
|
||||
|
||||
let data = json[i].data;
|
||||
let data = element.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 element) ? numToFixedBuffer(data, element.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(element.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 element of arr) {
|
||||
if (typeof element === 'object') {
|
||||
// an array
|
||||
toFlatArray(arr[i], outBuffer);
|
||||
toFlatArray(element, outBuffer);
|
||||
} else {
|
||||
// a simple element
|
||||
outBuffer.push(arr[i]);
|
||||
outBuffer.push(element);
|
||||
}
|
||||
}
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user