refactor: replace a few usages of V8 hidden properties (#29400)

This commit is contained in:
Milan Burda 2021-06-03 07:59:56 +02:00 committed by GitHub
parent bb6903543c
commit 8d0ed05c99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 17 deletions

View file

@ -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<string, any>) => {
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<string, any>) => {
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;