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 committed by GitHub
parent 4c77fe318d
commit 659e79fc08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
78 changed files with 134 additions and 145 deletions

View file

@ -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');