refactor: prevent consistent early exception (#24191)
* refactor: prevent consistent early exception * Use _linkedBinding where possible * Remove dead electronBinding
This commit is contained in:
parent
4c77fe318d
commit
659e79fc08
78 changed files with 134 additions and 145 deletions
|
@ -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');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue