refactor: prevent consistent early exception (#24191)

* refactor: prevent consistent early exception

* Use _linkedBinding where possible

* Remove dead electronBinding
This commit is contained in:
Shelley Vohr 2020-06-22 20:32:45 -07:00 коммит произвёл GitHub
Родитель 4c77fe318d
Коммит 659e79fc08
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
78 изменённых файлов: 134 добавлений и 145 удалений

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

@ -141,7 +141,6 @@ auto_filenames = {
"lib/common/api/native-image.ts",
"lib/common/api/shell.ts",
"lib/common/define-properties.ts",
"lib/common/electron-binding-setup.ts",
"lib/common/type-utils.ts",
"lib/common/web-view-methods.ts",
"lib/common/webpack-globals-provider.ts",
@ -175,7 +174,6 @@ auto_filenames = {
]
isolated_bundle_deps = [
"lib/common/electron-binding-setup.ts",
"lib/isolated_renderer/init.js",
"lib/renderer/web-view/web-view-constants.ts",
"lib/renderer/web-view/web-view-element.ts",
@ -247,7 +245,6 @@ auto_filenames = {
"lib/common/api/native-image.ts",
"lib/common/api/shell.ts",
"lib/common/define-properties.ts",
"lib/common/electron-binding-setup.ts",
"lib/common/init.ts",
"lib/common/parse-features-string.ts",
"lib/common/reset-search-paths.ts",
@ -271,7 +268,6 @@ auto_filenames = {
"lib/common/api/native-image.ts",
"lib/common/api/shell.ts",
"lib/common/define-properties.ts",
"lib/common/electron-binding-setup.ts",
"lib/common/init.ts",
"lib/common/reset-search-paths.ts",
"lib/common/type-utils.ts",
@ -315,7 +311,6 @@ auto_filenames = {
"lib/common/api/native-image.ts",
"lib/common/api/shell.ts",
"lib/common/define-properties.ts",
"lib/common/electron-binding-setup.ts",
"lib/common/init.ts",
"lib/common/reset-search-paths.ts",
"lib/common/type-utils.ts",

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

@ -4,8 +4,8 @@ import * as path from 'path';
import { deprecate, Menu } from 'electron';
import { EventEmitter } from 'events';
const bindings = process.electronBinding('app');
const commandLine = process.electronBinding('command_line');
const bindings = process._linkedBinding('electron_browser_app');
const commandLine = process._linkedBinding('electron_common_command_line');
const { app, App } = bindings;
// Only one app object permitted.

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

@ -1,7 +1,7 @@
'use strict';
const EventEmitter = require('events').EventEmitter;
const { autoUpdater, AutoUpdater } = process.electronBinding('auto_updater');
const { autoUpdater, AutoUpdater } = process._linkedBinding('electron_browser_auto_updater');
// AutoUpdater is an EventEmitter.
Object.setPrototypeOf(AutoUpdater.prototype, EventEmitter.prototype);

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

@ -1,6 +1,6 @@
import { EventEmitter } from 'events';
const { BrowserView } = process.electronBinding('browser_view');
const { BrowserView } = process._linkedBinding('electron_browser_browser_view');
Object.setPrototypeOf(BrowserView.prototype, EventEmitter.prototype);

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

@ -2,7 +2,7 @@
const electron = require('electron');
const { TopLevelWindow, deprecate } = electron;
const { BrowserWindow } = process.electronBinding('window');
const { BrowserWindow } = process._linkedBinding('electron_browser_window');
Object.setPrototypeOf(BrowserWindow.prototype, TopLevelWindow.prototype);
@ -59,7 +59,7 @@ BrowserWindow.prototype._init = function () {
}
// Notify the creation of the window.
const event = process.electronBinding('event').createEmpty();
const event = process._linkedBinding('electron_browser_event').createEmpty();
app.emit('browser-window-created', event, this);
Object.defineProperty(this, 'devToolsWebContents', {

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

@ -1 +1 @@
export default process.electronBinding('content_tracing');
export default process._linkedBinding('electron_browser_content_tracing');

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

@ -1,6 +1,6 @@
import { app, deprecate } from 'electron';
const binding = process.electronBinding('crash_reporter');
const binding = process._linkedBinding('electron_browser_crash_reporter');
class CrashReporter {
start (options: Electron.CrashReporterStartOptions) {

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

@ -1,8 +1,8 @@
'use strict';
const { app, BrowserWindow, deprecate } = require('electron');
const binding = process.electronBinding('dialog');
const v8Util = process.electronBinding('v8_util');
const binding = process._linkedBinding('electron_browser_dialog');
const v8Util = process._linkedBinding('electron_common_v8_util');
const DialogType = {
OPEN: 'OPEN',

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

@ -1 +1,2 @@
export default process.electronBinding('global_shortcut').globalShortcut;
const { globalShortcut } = process._linkedBinding('electron_browser_global_shortcut');
export default globalShortcut;

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

@ -3,7 +3,7 @@ import { EventEmitter } from 'events';
let _inAppPurchase;
if (process.platform === 'darwin') {
const { inAppPurchase, InAppPurchase } = process.electronBinding('in_app_purchase');
const { inAppPurchase, InAppPurchase } = process._linkedBinding('electron_browser_in_app_purchase');
// inAppPurchase is an EventEmitter.
Object.setPrototypeOf(InAppPurchase.prototype, EventEmitter.prototype);

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

@ -3,8 +3,8 @@
const { TopLevelWindow, MenuItem, webContents } = require('electron');
const { sortMenuItems } = require('@electron/internal/browser/api/menu-utils');
const EventEmitter = require('events').EventEmitter;
const v8Util = process.electronBinding('v8_util');
const bindings = process.electronBinding('menu');
const v8Util = process._linkedBinding('electron_common_v8_util');
const bindings = process._linkedBinding('electron_browser_menu');
const { Menu } = bindings;
let applicationMenu = null;

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

@ -1,5 +1,5 @@
import { MessagePortMain } from '@electron/internal/browser/message-port-main';
const { createPair } = process.electronBinding('message_port');
const { createPair } = process._linkedBinding('electron_browser_message_port');
export default class MessageChannelMain {
port1: MessagePortMain;

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

@ -1,6 +1,6 @@
import { EventEmitter } from 'events';
const { NativeTheme, nativeTheme } = process.electronBinding('native_theme');
const { NativeTheme, nativeTheme } = process._linkedBinding('electron_common_native_theme');
Object.setPrototypeOf(NativeTheme.prototype, EventEmitter.prototype);
EventEmitter.call(nativeTheme as any);

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

@ -2,7 +2,13 @@ import * as url from 'url';
import { Readable, Writable } from 'stream';
import { app } from 'electron';
import { ClientRequestConstructorOptions, UploadProgress } from 'electron/main';
const { net, Net, isValidHeaderName, isValidHeaderValue, createURLLoader } = process.electronBinding('net');
const {
net,
Net,
isValidHeaderName,
isValidHeaderValue,
createURLLoader
} = process._linkedBinding('electron_browser_net');
const kSupportedProtocols = new Set(['http:', 'https:']);

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

@ -1,4 +1,7 @@
const { Notification: ElectronNotification, isSupported } = process.electronBinding('notification');
const {
Notification: ElectronNotification,
isSupported
} = process._linkedBinding('electron_common_notification');
ElectronNotification.isSupported = isSupported;

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

@ -1,7 +1,11 @@
import { EventEmitter } from 'events';
import { app } from 'electron';
const { createPowerMonitor, getSystemIdleState, getSystemIdleTime } = process.electronBinding('power_monitor');
const {
createPowerMonitor,
getSystemIdleState,
getSystemIdleTime
} = process._linkedBinding('electron_browser_power_monitor');
class PowerMonitor extends EventEmitter {
constructor () {

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

@ -1 +1,2 @@
export default process.electronBinding('power_save_blocker').powerSaveBlocker;
const { powerSaveBlocker } = process._linkedBinding('electron_browser_power_save_blocker');
export default powerSaveBlocker;

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

@ -1,7 +1,7 @@
import { app, session } from 'electron';
// Global protocol APIs.
const protocol = process.electronBinding('protocol');
const protocol = process._linkedBinding('electron_browser_protocol');
// Fallback protocol APIs of default session.
Object.setPrototypeOf(protocol, new Proxy({}, {

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

@ -2,7 +2,7 @@
import { createLazyInstance } from '../utils';
const { EventEmitter } = require('events');
const { Screen, createScreen } = process.electronBinding('screen');
const { Screen, createScreen } = process._linkedBinding('electron_common_screen');
// Screen is an EventEmitter.
Object.setPrototypeOf(Screen.prototype, EventEmitter.prototype);

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

@ -1,4 +1,4 @@
const { fromPartition } = process.electronBinding('session');
const { fromPartition } = process._linkedBinding('electron_browser_session');
export default {
fromPartition,

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

@ -1,6 +1,6 @@
import { EventEmitter } from 'events';
import { deprecate } from 'electron';
const { systemPreferences, SystemPreferences } = process.electronBinding('system_preferences');
const { systemPreferences, SystemPreferences } = process._linkedBinding('electron_browser_system_preferences');
// SystemPreferences is an EventEmitter.
Object.setPrototypeOf(SystemPreferences.prototype, EventEmitter.prototype);

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

@ -2,7 +2,7 @@
const electron = require('electron');
const { EventEmitter } = require('events');
const { TopLevelWindow } = process.electronBinding('top_level_window');
const { TopLevelWindow } = process._linkedBinding('electron_browser_top_level_window');
Object.setPrototypeOf(TopLevelWindow.prototype, EventEmitter.prototype);

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

@ -1,3 +1,3 @@
const { Tray } = process.electronBinding('tray');
const { Tray } = process._linkedBinding('electron_browser_tray');
export default Tray;

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

@ -1,3 +1,3 @@
const { View } = process.electronBinding('view');
const { View } = process._linkedBinding('electron_browser_view');
export default View;

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

@ -1,6 +1,6 @@
import { View } from 'electron';
const { ImageView } = process.electronBinding('image_view');
const { ImageView } = process._linkedBinding('electron_browser_image_view');
Object.setPrototypeOf(ImageView.prototype, View.prototype);

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

@ -1,6 +1,6 @@
import { View } from 'electron';
const { WebContentsView } = process.electronBinding('web_contents_view');
const { WebContentsView } = process._linkedBinding('electron_browser_web_contents_view');
Object.setPrototypeOf(WebContentsView.prototype, View.prototype);

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

@ -97,7 +97,7 @@ const defaultPrintingSetting = {
};
// JavaScript implementations of WebContents.
const binding = process.electronBinding('web_contents');
const binding = process._linkedBinding('electron_browser_web_contents');
const { WebContents } = binding;
Object.setPrototypeOf(NavigationController.prototype, EventEmitter.prototype);
@ -562,7 +562,7 @@ WebContents.prototype._init = function () {
app.emit('login', event, this, ...args);
});
const event = process.electronBinding('event').createEmpty();
const event = process._linkedBinding('electron_browser_event').createEmpty();
app.emit('web-contents-created', event, this);
// Properties

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

@ -1,6 +1,6 @@
import { shell, Menu } from 'electron';
const v8Util = process.electronBinding('v8_util');
const v8Util = process._linkedBinding('electron_common_v8_util');
const isMac = process.platform === 'darwin';

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

@ -1,4 +1,7 @@
const { createDesktopCapturer, getMediaSourceIdForWebContents: getMediaSourceIdForWebContentsBinding } = process.electronBinding('desktop_capturer');
const {
createDesktopCapturer,
getMediaSourceIdForWebContents: getMediaSourceIdForWebContentsBinding
} = process._linkedBinding('electron_browser_desktop_capturer');
const deepEqual = (a: ElectronInternal.GetSourcesOptions, b: ElectronInternal.GetSourcesOptions) => JSON.stringify(a) === JSON.stringify(b);

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

@ -59,7 +59,7 @@ function sanitizeOptionsForGuest (options) {
// Create a new guest instance.
const createGuest = function (embedder, params) {
if (webViewManager == null) {
webViewManager = process.electronBinding('web_view_manager');
webViewManager = process._linkedBinding('electron_browser_web_view_manager');
}
const guest = webContents.create({

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

@ -2,7 +2,7 @@
const electron = require('electron');
const { BrowserWindow } = electron;
const { isSameOrigin } = process.electronBinding('v8_util');
const { isSameOrigin } = process._linkedBinding('electron_common_v8_util');
const { ipcMainInternal } = require('@electron/internal/browser/ipc-main-internal');
const ipcMainUtils = require('@electron/internal/browser/ipc-main-internal-utils');
const { parseFeatures } = require('@electron/internal/common/parse-features-string');

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

@ -17,7 +17,7 @@ require('../common/reset-search-paths');
// Import common settings.
require('@electron/internal/common/init');
process.electronBinding('event_emitter').setEventEmitterPrototype(EventEmitter.prototype);
process._linkedBinding('electron_browser_event_emitter').setEventEmitterPrototype(EventEmitter.prototype);
if (process.platform === 'win32') {
// Redirect node's console to use our own implementations, since node can not

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

@ -2,7 +2,7 @@
import { WebContents } from 'electron';
const v8Util = process.electronBinding('v8_util');
const v8Util = process._linkedBinding('electron_common_v8_util');
const getOwnerKey = (webContents: WebContents, contextId: string) => {
return `${webContents.id}-${contextId}`;

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

@ -5,10 +5,10 @@ import { ipcMainInternal } from '../ipc-main-internal';
import { isPromise, isSerializableObject, deserialize, serialize } from '../../common/type-utils';
import type { MetaTypeFromRenderer, ObjectMember, MetaType, ObjProtoDescriptor } from '../../common/remote/types';
const v8Util = process.electronBinding('v8_util');
const eventBinding = process.electronBinding('event');
const features = process.electronBinding('features');
const { NativeImage } = process.electronBinding('native_image');
const v8Util = process._linkedBinding('electron_common_v8_util');
const eventBinding = process._linkedBinding('electron_browser_event');
const features = process._linkedBinding('electron_common_features');
const { NativeImage } = process._linkedBinding('electron_common_native_image');
if (!features.isRemoteModuleEnabled()) {
throw new Error('remote module is disabled');

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

@ -3,8 +3,8 @@
const electron = require('electron');
const fs = require('fs');
const eventBinding = process.electronBinding('event');
const clipboard = process.electronBinding('clipboard');
const eventBinding = process._linkedBinding('electron_browser_event');
const clipboard = process._linkedBinding('electron_common_clipboard');
const { ipcMainInternal } = require('@electron/internal/browser/ipc-main-internal');
const ipcMainUtils = require('@electron/internal/browser/ipc-main-internal-utils');

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

@ -1,4 +1,4 @@
const clipboard = process.electronBinding('clipboard');
const clipboard = process._linkedBinding('electron_common_clipboard');
if (process.type === 'renderer') {
const ipcRendererUtils = require('@electron/internal/renderer/ipc-renderer-internal-utils');

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

@ -1,3 +1,3 @@
const { nativeImage } = process.electronBinding('native_image');
const { nativeImage } = process._linkedBinding('electron_common_native_image');
export default nativeImage;

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

@ -1 +1 @@
export default process.electronBinding('shell');
export default process._linkedBinding('electron_common_shell');

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

@ -1,13 +0,0 @@
export function electronBindingSetup (binding: typeof process['_linkedBinding'], processType: typeof process['type']): typeof process['electronBinding'] {
return function electronBinding (name: string) {
try {
return binding(`electron_${processType}_${name}`);
} catch (error) {
if (/No such module/.test(error.message)) {
return binding(`electron_common_${name}`);
} else {
throw error;
}
}
};
}

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

@ -1,11 +1,7 @@
import * as util from 'util';
import { electronBindingSetup } from '@electron/internal/common/electron-binding-setup';
const timers = require('timers');
process.electronBinding = electronBindingSetup(process._linkedBinding, process.type);
type AnyFn = (...args: any[]) => any
// setImmediate and process.nextTick makes use of uv_check and uv_prepare to

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

@ -1,4 +1,4 @@
const { nativeImage, NativeImage } = process.electronBinding('native_image');
const { nativeImage, NativeImage } = process._linkedBinding('electron_common_native_image');
export function isPromise (val: any) {
return (

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

@ -2,9 +2,9 @@
/* global nodeProcess, isolatedWorld */
process.electronBinding = require('@electron/internal/common/electron-binding-setup').electronBindingSetup(nodeProcess._linkedBinding, 'renderer');
process._linkedBinding = nodeProcess._linkedBinding;
const v8Util = process.electronBinding('v8_util');
const v8Util = process._linkedBinding('electron_common_v8_util');
const webViewImpl = v8Util.getHiddenValue(isolatedWorld, 'web-view-impl');

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

@ -1,5 +1,5 @@
const { hasSwitch } = process.electronBinding('command_line');
const binding = process.electronBinding('context_bridge');
const { hasSwitch } = process._linkedBinding('electron_common_command_line');
const binding = process._linkedBinding('electron_renderer_context_bridge');
const contextIsolationEnabled = hasSwitch('context-isolation');

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

@ -1,7 +1,7 @@
import { invokeSync } from '../ipc-renderer-internal-utils';
import { deprecate } from 'electron';
const binding = process.electronBinding('crash_reporter');
const binding = process._linkedBinding('electron_renderer_crash_reporter');
export default {
start (options: Electron.CrashReporterStartOptions) {

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

@ -1,7 +1,7 @@
import { ipcRendererInternal } from '@electron/internal/renderer/ipc-renderer-internal';
import { deserialize } from '@electron/internal/common/type-utils';
const { hasSwitch } = process.electronBinding('command_line');
const { hasSwitch } = process._linkedBinding('electron_common_command_line');
const enableStacks = hasSwitch('enable-api-filtering-logging');

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

@ -1,6 +1,6 @@
import { EventEmitter } from 'events';
const { ipc } = process.electronBinding('ipc');
const { ipc } = process._linkedBinding('electron_renderer_ipc');
const internal = false;

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

@ -1,4 +1,4 @@
const v8Util = process.electronBinding('v8_util');
const v8Util = process._linkedBinding('electron_common_v8_util');
const enableRemoteModule = v8Util.getHiddenValue<boolean>(global, 'enableRemoteModule');

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

@ -6,9 +6,9 @@ import type { BrowserWindow, WebContents } from 'electron/main';
import { browserModuleNames } from '@electron/internal/browser/api/module-names';
import { commonModuleList } from '@electron/internal/common/api/module-list';
const v8Util = process.electronBinding('v8_util');
const { hasSwitch } = process.electronBinding('command_line');
const { NativeImage } = process.electronBinding('native_image');
const v8Util = process._linkedBinding('electron_common_v8_util');
const { hasSwitch } = process._linkedBinding('electron_common_command_line');
const { NativeImage } = process._linkedBinding('electron_common_native_image');
const callbacksRegistry = new CallbacksRegistry();
const remoteObjectCache = new Map();

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

@ -1,6 +1,6 @@
import { EventEmitter } from 'events';
const binding = process.electronBinding('web_frame');
const binding = process._linkedBinding('electron_renderer_web_frame');
class WebFrame extends EventEmitter {
constructor (public context: Window) {

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

@ -2,7 +2,7 @@ import { webFrame } from 'electron';
import * as ipcRendererUtils from '@electron/internal/renderer/ipc-renderer-internal-utils';
const v8Util = process.electronBinding('v8_util');
const v8Util = process._linkedBinding('electron_common_v8_util');
const IsolatedWorldIDs = {
/**

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

@ -36,7 +36,7 @@ require('../common/reset-search-paths');
require('@electron/internal/common/init');
// The global variable will be used by ipc for event dispatching
const v8Util = process.electronBinding('v8_util');
const v8Util = process._linkedBinding('electron_common_v8_util');
const { ipcRendererInternal } = require('@electron/internal/renderer/ipc-renderer-internal');
const ipcRenderer = require('@electron/internal/renderer/api/ipc-renderer').default;
@ -53,7 +53,7 @@ const { webFrameInit } = require('@electron/internal/renderer/web-frame-init');
webFrameInit();
// Process command line arguments.
const { hasSwitch, getSwitchValue } = process.electronBinding('command_line');
const { hasSwitch, getSwitchValue } = process._linkedBinding('electron_common_command_line');
const parseOption = function<T> (
name: string, defaultValue: T, converter?: (value: string) => T

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

@ -1,6 +1,6 @@
import { EventEmitter } from 'events';
const { ipc } = process.electronBinding('ipc');
const { ipc } = process._linkedBinding('electron_renderer_ipc');
const internal = true;

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

@ -1,4 +1,4 @@
const v8Util = process.electronBinding('v8_util');
const v8Util = process._linkedBinding('electron_common_v8_util');
export class CallbacksRegistry {
private nextId: number = 0

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

@ -8,7 +8,7 @@ import { syncMethods, asyncMethods, properties } from '@electron/internal/common
import { deserialize } from '@electron/internal/common/type-utils';
const { webFrame } = electron;
const v8Util = process.electronBinding('v8_util');
const v8Util = process._linkedBinding('electron_common_v8_util');
// ID generator.
let nextId = 0;

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

@ -1,6 +1,6 @@
import { ipcRendererInternal } from '@electron/internal/renderer/ipc-renderer-internal';
const v8Util = process.electronBinding('v8_util');
const v8Util = process._linkedBinding('electron_common_v8_util');
function handleFocusBlur (guestInstanceId: number) {
// Note that while Chromium content APIs have observer for focus/blur, they

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

@ -1,13 +1,12 @@
/* eslint no-eval: "off" */
/* global binding, Buffer */
import { electronBindingSetup } from '@electron/internal/common/electron-binding-setup';
import * as events from 'events';
const { EventEmitter } = events;
process.electronBinding = electronBindingSetup(binding.get, 'renderer');
process._linkedBinding = binding.get;
const v8Util = process.electronBinding('v8_util');
const v8Util = process._linkedBinding('electron_common_v8_util');
// Expose Buffer shim as a hidden value. This is used by C++ code to
// deserialize Buffer instances sent from browser process.
v8Util.setHiddenValue(global, 'Buffer', Buffer);
@ -34,7 +33,6 @@ const {
process.isRemoteModuleEnabled = isRemoteModuleEnabled;
// The electron module depends on process.electronBinding
const electron = require('electron');
const loadedModules = new Map<string, any>([
@ -77,8 +75,7 @@ v8Util.setHiddenValue(global, 'lifecycle', {
const { webFrameInit } = require('@electron/internal/renderer/web-frame-init');
webFrameInit();
// Pass different process object to the preload script(which should not have
// access to things like `process.electronBinding`).
// Pass different process object to the preload script.
const preloadProcess: NodeJS.Process = new EventEmitter() as any;
Object.assign(preloadProcess, binding.process);
@ -115,12 +112,12 @@ function preloadRequire (module: string) {
}
// Process command line arguments.
const { hasSwitch } = process.electronBinding('command_line');
const { hasSwitch } = process._linkedBinding('electron_common_command_line');
// Similar to nodes --expose-internals flag, this exposes electronBinding so
// Similar to nodes --expose-internals flag, this exposes _linkedBinding so
// that tests can call it to get access to some test only bindings
if (hasSwitch('unsafely-expose-electron-internals-for-testing')) {
preloadProcess.electronBinding = process.electronBinding;
preloadProcess._linkedBinding = process._linkedBinding;
}
const contextIsolation = hasSwitch('context-isolation');

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

@ -36,7 +36,7 @@ class ElectronBindings {
explicit ElectronBindings(uv_loop_t* loop);
virtual ~ElectronBindings();
// Add process.electronBinding function, which behaves like process.binding
// Add process._linkedBinding function, which behaves like process.binding
// but load native code from Electron instead.
void BindTo(v8::Isolate* isolate, v8::Local<v8::Object> process);

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

@ -11,7 +11,7 @@ import { closeWindow, closeAllWindows } from './window-helpers';
import { ifdescribe, ifit } from './spec-helpers';
import split = require('split')
const features = process.electronBinding('features');
const features = process._linkedBinding('electron_common_features');
const fixturesPath = path.resolve(__dirname, '../spec/fixtures');
@ -1298,7 +1298,7 @@ describe('app module', () => {
it('keeps references to the menu', () => {
app.dock.setMenu(new Menu());
const v8Util = process.electronBinding('v8_util');
const v8Util = process._linkedBinding('electron_common_v8_util');
v8Util.requestGarbageCollectionForTesting();
});
});

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

@ -7,7 +7,7 @@ import * as os from 'os';
import * as path from 'path';
import { AddressInfo } from 'net';
const features = process.electronBinding('features');
const features = process._linkedBinding('electron_common_features');
const fixturesPath = path.resolve(__dirname, 'fixtures');

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

@ -12,7 +12,7 @@ import { emittedOnce, emittedUntil } from './events-helpers';
import { ifit, ifdescribe } from './spec-helpers';
import { closeWindow, closeAllWindows } from './window-helpers';
const features = process.electronBinding('features');
const features = process._linkedBinding('electron_common_features');
const fixtures = path.resolve(__dirname, '..', 'spec', 'fixtures');
// Is the display's scale factor possibly causing rounding of pixel coordinate
@ -65,7 +65,7 @@ describe('BrowserWindow module', () => {
});
describe('garbage collection', () => {
const v8Util = process.electronBinding('v8_util');
const v8Util = process._linkedBinding('electron_common_v8_util');
afterEach(closeAllWindows);
it('window does not get garbage collected when opened', (done) => {

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

@ -2,7 +2,7 @@ import { expect } from 'chai';
import { CallbacksRegistry } from '../lib/renderer/remote/callbacks-registry';
import { ifdescribe } from './spec-helpers';
const features = process.electronBinding('features');
const features = process._linkedBinding('electron_common_features');
ifdescribe(features.isRemoteModuleEnabled())('CallbacksRegistry module', () => {
let registry: CallbacksRegistry;

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

@ -347,8 +347,8 @@ describe('contextBridge', () => {
if (!useSandbox) {
it('should release the global hold on methods sent across contexts', async () => {
await makeBindingWindow(() => {
require('electron').ipcRenderer.on('get-gc-info', e => e.sender.send('gc-info', { trackedValues: process.electronBinding('v8_util').getWeaklyTrackedValues().length }));
const { weaklyTrackValue } = process.electronBinding('v8_util');
require('electron').ipcRenderer.on('get-gc-info', e => e.sender.send('gc-info', { trackedValues: process._linkedBinding('electron_common_v8_util').getWeaklyTrackedValues().length }));
const { weaklyTrackValue } = process._linkedBinding('electron_common_v8_util');
contextBridge.exposeInMainWorld('example', {
getFunction: () => () => 123,
track: weaklyTrackValue
@ -375,8 +375,8 @@ describe('contextBridge', () => {
if (useSandbox) {
it('should not leak the global hold on methods sent across contexts when reloading a sandboxed renderer', async () => {
await makeBindingWindow(() => {
require('electron').ipcRenderer.on('get-gc-info', e => e.sender.send('gc-info', { trackedValues: process.electronBinding('v8_util').getWeaklyTrackedValues().length }));
const { weaklyTrackValue } = process.electronBinding('v8_util');
require('electron').ipcRenderer.on('get-gc-info', e => e.sender.send('gc-info', { trackedValues: process._linkedBinding('electron_common_v8_util').getWeaklyTrackedValues().length }));
const { weaklyTrackValue } = process._linkedBinding('electron_common_v8_util');
contextBridge.exposeInMainWorld('example', {
getFunction: () => () => 123,
track: weaklyTrackValue

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

@ -5,7 +5,7 @@ import { emittedOnce } from './events-helpers';
import { ifdescribe, ifit } from './spec-helpers';
import { closeAllWindows } from './window-helpers';
const features = process.electronBinding('features');
const features = process._linkedBinding('electron_common_features');
ifdescribe(!process.arch.includes('arm') && process.platform !== 'win32')('desktopCapturer', () => {
if (!features.isDesktopCapturerEnabled()) {

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

@ -4,7 +4,7 @@ import { BrowserWindow, ipcMain, IpcMainInvokeEvent, MessageChannelMain } from '
import { closeAllWindows } from './window-helpers';
import { emittedOnce } from './events-helpers';
const v8Util = process.electronBinding('v8_util');
const v8Util = process._linkedBinding('electron_common_v8_util');
describe('ipc module', () => {
describe('invoke', () => {
@ -307,7 +307,7 @@ describe('ipc module', () => {
await new Promise(resolve => {
port2.start();
(port2 as any).onclose = resolve;
process.electronBinding('v8_util').requestGarbageCollectionForTesting();
process._linkedBinding('electron_common_v8_util').requestGarbageCollectionForTesting();
});
}})()`);
});

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

@ -847,7 +847,7 @@ describe('Menu module', function () {
setTimeout(() => {
// Do garbage collection, since |menu| is not referenced in this closure
// it would be gone after next call.
const v8Util = process.electronBinding('v8_util');
const v8Util = process._linkedBinding('electron_common_v8_util');
v8Util.requestGarbageCollectionForTesting();
setTimeout(() => {
// Try to receive menu from weak reference.

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

@ -1399,7 +1399,7 @@ describe('net module', () => {
it('should free unreferenced, never-started request objects without crash', (done) => {
net.request('https://test');
process.nextTick(() => {
const v8Util = process.electronBinding('v8_util');
const v8Util = process._linkedBinding('electron_common_v8_util');
v8Util.requestGarbageCollectionForTesting();
done();
});
@ -1418,7 +1418,7 @@ describe('net module', () => {
const response = await getResponse(urlRequest);
process.nextTick(() => {
// Trigger a garbage collection.
const v8Util = process.electronBinding('v8_util');
const v8Util = process._linkedBinding('electron_common_v8_util');
v8Util.requestGarbageCollectionForTesting();
finishResponse!();
});
@ -1431,7 +1431,7 @@ describe('net module', () => {
});
const urlRequest = net.request(serverUrl);
process.nextTick(() => {
const v8Util = process.electronBinding('v8_util');
const v8Util = process._linkedBinding('electron_common_v8_util');
v8Util.requestGarbageCollectionForTesting();
});
const response = await getResponse(urlRequest);
@ -1447,7 +1447,7 @@ describe('net module', () => {
const urlRequest = net.request(serverUrl);
urlRequest.on('close', () => {
process.nextTick(() => {
const v8Util = process.electronBinding('v8_util');
const v8Util = process._linkedBinding('electron_common_v8_util');
v8Util.requestGarbageCollectionForTesting();
});
});
@ -1468,7 +1468,7 @@ describe('net module', () => {
const response = await getResponse(urlRequest);
await collectStreamBody(response);
process.nextTick(() => {
const v8Util = process.electronBinding('v8_util');
const v8Util = process._linkedBinding('electron_common_v8_util');
v8Util.requestGarbageCollectionForTesting();
});
});
@ -1482,7 +1482,7 @@ describe('net module', () => {
const urlRequest = net.request(serverUrl);
urlRequest.chunkedEncoding = true;
urlRequest.write(randomBuffer(kOneMegaByte));
const v8Util = process.electronBinding('v8_util');
const v8Util = process._linkedBinding('electron_common_v8_util');
v8Util.requestGarbageCollectionForTesting();
await collectStreamBody(await getResponse(urlRequest));
});
@ -1496,7 +1496,7 @@ describe('net module', () => {
const urlRequest = net.request(serverUrl);
urlRequest.on('close', () => {
process.nextTick(() => {
const v8Util = process.electronBinding('v8_util');
const v8Util = process._linkedBinding('electron_common_v8_util');
v8Util.requestGarbageCollectionForTesting();
});
});
@ -1513,7 +1513,7 @@ describe('net module', () => {
const urlRequest = net.request(serverUrl);
urlRequest.on('close', () => {
process.nextTick(() => {
const v8Util = process.electronBinding('v8_util');
const v8Util = process._linkedBinding('electron_common_v8_util');
v8Util.requestGarbageCollectionForTesting();
});
});

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

@ -9,7 +9,7 @@ import { NativeImage } from 'electron/common';
import { serialize, deserialize } from '../lib/common/type-utils';
import { nativeImage } from 'electron';
const features = process.electronBinding('features');
const features = process._linkedBinding('electron_common_features');
const expectPathsEqual = (path1: string, path2: string) => {
if (process.platform === 'win32') {
@ -1016,7 +1016,7 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
event.returnValue = obj;
});
await remotely(() => {
const { ipc } = process.electronBinding('ipc');
const { ipc } = process._linkedBinding('electron_renderer_ipc');
const originalSendSync = ipc.sendSync.bind(ipc) as any;
ipc.sendSync = (...args: any[]): any => {
const ret = originalSendSync(...args);

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

@ -12,7 +12,7 @@ import { ifdescribe, ifit } from './spec-helpers';
const pdfjs = require('pdfjs-dist');
const fixturesPath = path.resolve(__dirname, '..', 'spec', 'fixtures');
const features = process.electronBinding('features');
const features = process._linkedBinding('electron_common_features');
describe('webContents module', () => {
describe('getAllWebContents() API', () => {

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

@ -14,7 +14,7 @@ import { ifit, ifdescribe } from './spec-helpers';
import { AddressInfo } from 'net';
import { PipeTransport } from './pipe-transport';
const features = process.electronBinding('features');
const features = process._linkedBinding('electron_common_features');
const fixturesPath = path.resolve(__dirname, '..', 'spec', 'fixtures');
@ -722,7 +722,7 @@ describe('chromium features', () => {
process.once('uncaughtException', resolve);
});
expect(await w.webContents.executeJavaScript(`(${function () {
const ipc = process.electronBinding('ipc').ipc;
const { ipc } = process._linkedBinding('electron_renderer_ipc');
return ipc.sendSync(true, 'ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_OPEN', ['', '', ''])[0];
}})()`)).to.be.null();
const exception = await uncaughtException;

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

@ -8,7 +8,7 @@ import * as childProcess from 'child_process';
const Module = require('module');
const features = process.electronBinding('features');
const features = process._linkedBinding('electron_common_features');
const nativeModulesEnabled = !process.env.ELECTRON_SKIP_NATIVE_MODULE_TESTS;
describe('modules support', () => {

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

@ -6,7 +6,7 @@ import { emittedOnce } from './events-helpers';
import { ifdescribe, ifit } from './spec-helpers';
import { webContents, WebContents } from 'electron/main';
const features = process.electronBinding('features');
const features = process._linkedBinding('electron_common_features');
describe('node feature', () => {
const fixtures = path.join(__dirname, '..', 'spec', 'fixtures');

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

@ -6,7 +6,7 @@ import { closeWindow } from './window-helpers';
import { emittedOnce } from './events-helpers';
import { ifit, ifdescribe } from './spec-helpers';
const features = process.electronBinding('features');
const features = process._linkedBinding('electron_common_features');
ifdescribe(features.isBuiltinSpellCheckerEnabled())('spellchecker', () => {
let w: BrowserWindow;

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

@ -5,7 +5,7 @@ import { emittedOnce } from './events-helpers';
import { ifdescribe } from './spec-helpers';
import { expect } from 'chai';
const features = process.electronBinding('features');
const features = process._linkedBinding('electron_common_features');
async function loadWebView (w: WebContents, attributes: Record<string, string>, openDevTools: boolean = false): Promise<void> {
await w.executeJavaScript(`

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

@ -6,7 +6,7 @@ const temp = require('temp').track();
const util = require('util');
const nativeImage = require('electron').nativeImage;
const features = process.electronBinding('features');
const features = process._linkedBinding('electron_common_features');
async function expectToThrowErrorWithCode (func, code) {
let error;

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

@ -8,7 +8,7 @@ const ChildProcess = require('child_process');
const { ipcRenderer } = require('electron');
const { emittedOnce } = require('./events-helpers');
const { resolveGetters } = require('./expect-helpers');
const features = process.electronBinding('features');
const features = process._linkedBinding('electron_common_features');
/* Most of the APIs here don't use standard callbacks */
/* eslint-disable standard/no-callback-literal */
@ -26,7 +26,7 @@ describe('chromium feature', () => {
describe('heap snapshot', () => {
it('does not crash', function () {
process.electronBinding('v8_util').takeHeapSnapshot();
process._linkedBinding('electron_common_v8_util').takeHeapSnapshot();
});
});

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

@ -4,7 +4,7 @@ const fs = require('fs');
const path = require('path');
const os = require('os');
const { ipcRenderer } = require('electron');
const features = process.electronBinding('features');
const features = process._linkedBinding('electron_common_features');
const { emittedOnce } = require('./events-helpers');
const { ifit } = require('./spec-helpers');

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

@ -6,7 +6,7 @@ const { ipcRenderer } = require('electron');
const { emittedOnce, waitForEvent } = require('./events-helpers');
const { ifdescribe, ifit } = require('./spec-helpers');
const features = process.electronBinding('features');
const features = process._linkedBinding('electron_common_features');
const nativeModulesEnabled = process.env.ELECTRON_SKIP_NATIVE_MODULE_TESTS;
/* Most of the APIs here don't use standard callbacks */

18
typings/internal-ambient.d.ts поставляемый
Просмотреть файл

@ -89,21 +89,17 @@ declare namespace NodeJS {
}
interface Process {
/**
* DO NOT USE DIRECTLY, USE process.electronBinding
*/
_linkedBinding(name: string): any;
electronBinding(name: string): any;
electronBinding(name: 'features'): FeaturesBinding;
electronBinding(name: 'ipc'): { ipc: IpcRendererBinding };
electronBinding(name: 'v8_util'): V8UtilBinding;
electronBinding(name: 'app'): { app: Electron.App, App: Function };
electronBinding(name: 'command_line'): Electron.CommandLine;
electronBinding(name: 'desktop_capturer'): {
_linkedBinding(name: 'electron_renderer_ipc'): { ipc: IpcRendererBinding };
_linkedBinding(name: 'electron_common_v8_util'): V8UtilBinding;
_linkedBinding(name: 'electron_common_features'): FeaturesBinding;
_linkedBinding(name: 'electron_browser_app'): { app: Electron.App, App: Function };
_linkedBinding(name: 'electron_common_command_line'): Electron.CommandLine;
_linkedBinding(name: 'electron_browser_desktop_capturer'): {
createDesktopCapturer(): ElectronInternal.DesktopCapturer;
getMediaSourceIdForWebContents(requestWebContentsId: number, webContentsId: number): string;
};
electronBinding(name: 'net'): {
_linkedBinding(name: 'electron_browser_net'): {
isValidHeaderName: (headerName: string) => boolean;
isValidHeaderValue: (headerValue: string) => boolean;
Net: any;