diff --git a/lib/asar/fs-wrapper.ts b/lib/asar/fs-wrapper.ts index 5f0d0587a31f5..1c265e415e50f 100644 --- a/lib/asar/fs-wrapper.ts +++ b/lib/asar/fs-wrapper.ts @@ -3,7 +3,6 @@ import * as path from 'path'; import * as util from 'util'; const asar = process._linkedBinding('electron_common_asar'); -const v8Util = process._linkedBinding('electron_common_v8_util'); const Module = require('module'); @@ -787,6 +786,8 @@ export const wrapFsWithAsar = (fs: Record) => { overrideAPISync(childProcess, 'execFileSync'); }; + const asarReady = new WeakSet(); + // Lazily override the child_process APIs only when child_process is // fetched the first time. We will eagerly override the child_process APIs // when this env var is set so that stack traces generated inside node unit @@ -799,8 +800,8 @@ export const wrapFsWithAsar = (fs: Record) => { Module._load = (request: string, ...args: any[]) => { const loadResult = originalModuleLoad(request, ...args); if (request === 'child_process') { - if (!v8Util.getHiddenValue(loadResult, 'asar-ready')) { - v8Util.setHiddenValue(loadResult, 'asar-ready', true); + if (!asarReady.has(loadResult)) { + asarReady.add(loadResult); // Just to make it obvious what we are dealing with here const childProcess = loadResult; diff --git a/lib/browser/api/menu.ts b/lib/browser/api/menu.ts index 00dbe9f7ca25a..cdd3b73452f33 100644 --- a/lib/browser/api/menu.ts +++ b/lib/browser/api/menu.ts @@ -1,10 +1,11 @@ import { BaseWindow, MenuItem, webContents, Menu as MenuType, BrowserWindow, MenuItemConstructorOptions } from 'electron/main'; import { sortMenuItems } from '@electron/internal/browser/api/menu-utils'; +import { setApplicationMenuWasSet } from '@electron/internal/browser/default-menu'; -const v8Util = process._linkedBinding('electron_common_v8_util'); const bindings = process._linkedBinding('electron_browser_menu'); const { Menu } = bindings as { Menu: typeof MenuType }; +const checked = new WeakMap(); let applicationMenu: MenuType | null = null; let groupIdIndex = 0; @@ -60,7 +61,7 @@ Menu.prototype._menuWillShow = function () { // Ensure radio groups have at least one menu item selected for (const id of Object.keys(this.groupsMap)) { const found = this.groupsMap[id].find(item => item.checked) || null; - if (!found) v8Util.setHiddenValue(this.groupsMap[id][0], 'checked', true); + if (!found) checked.set(this.groupsMap[id][0], true); } }; @@ -169,7 +170,7 @@ Menu.setApplicationMenu = function (menu: MenuType) { } applicationMenu = menu; - v8Util.setHiddenValue(global, 'applicationMenuSet', true); + setApplicationMenuWasSet(); if (process.platform === 'darwin') { if (!menu) return; @@ -275,15 +276,15 @@ function insertItemByType (this: MenuType, item: MenuItem, pos: number) { this.groupsMap[item.groupId].push(item); // Setting a radio menu item should flip other items in the group. - v8Util.setHiddenValue(item, 'checked', item.checked); + checked.set(item, item.checked); Object.defineProperty(item, 'checked', { enumerable: true, - get: () => v8Util.getHiddenValue(item, 'checked'), + get: () => checked.get(item), set: () => { this.groupsMap[item.groupId].forEach(other => { - if (other !== item) v8Util.setHiddenValue(other, 'checked', false); + if (other !== item) checked.set(other, false); }); - v8Util.setHiddenValue(item, 'checked', true); + checked.set(item, true); } }); this.insertRadioItem(pos, item.commandId, item.label, item.groupId); diff --git a/lib/browser/default-menu.ts b/lib/browser/default-menu.ts index a84589a9eee3d..0c1013c0a8c3f 100644 --- a/lib/browser/default-menu.ts +++ b/lib/browser/default-menu.ts @@ -1,12 +1,16 @@ import { app, Menu } from 'electron/main'; import { shell } from 'electron/common'; -const v8Util = process._linkedBinding('electron_common_v8_util'); - const isMac = process.platform === 'darwin'; +let applicationMenuWasSet = false; + +export const setApplicationMenuWasSet = () => { + applicationMenuWasSet = true; +}; + export const setDefaultApplicationMenu = () => { - if (v8Util.getHiddenValue(global, 'applicationMenuSet')) return; + if (applicationMenuWasSet) return; const helpMenu: Electron.MenuItemConstructorOptions = { role: 'help', diff --git a/lib/sandboxed_renderer/init.ts b/lib/sandboxed_renderer/init.ts index 7d02a31f8f4d0..cd76c379afc81 100644 --- a/lib/sandboxed_renderer/init.ts +++ b/lib/sandboxed_renderer/init.ts @@ -1,4 +1,3 @@ -/* eslint no-eval: "off" */ /* global binding */ import * as events from 'events'; import { IPC_MESSAGES } from '@electron/internal/common/ipc-messages'; diff --git a/typings/internal-electron.d.ts b/typings/internal-electron.d.ts index 097ea1f2fc7d4..a3ffa431d5c1a 100644 --- a/typings/internal-electron.d.ts +++ b/typings/internal-electron.d.ts @@ -113,9 +113,7 @@ declare namespace Electron { _executeCommand(event: any, id: number): void; _menuWillShow(): void; commandsMap: Record; - groupsMap: Record; + groupsMap: Record; getItemCount(): number; popupAt(window: BaseWindow, x: number, y: number, positioning: number, callback: () => void): void; closePopupAt(id: number): void;