зеркало из https://github.com/electron/electron.git
chore: simplify code for modules internally using remote.require in sandbox (#16104)
This commit is contained in:
Родитель
c64b4a3926
Коммит
7a6fe00f49
12
BUILD.gn
12
BUILD.gn
|
@ -62,14 +62,6 @@ npm_action("atom_browserify_sandbox") {
|
|||
"lib/sandboxed_renderer/init.js",
|
||||
"-r",
|
||||
"./lib/sandboxed_renderer/api/exports/electron.js:electron",
|
||||
"-r",
|
||||
"./lib/sandboxed_renderer/api/exports/fs.js:fs",
|
||||
"-r",
|
||||
"./lib/sandboxed_renderer/api/exports/os.js:os",
|
||||
"-r",
|
||||
"./lib/sandboxed_renderer/api/exports/path.js:path",
|
||||
"-r",
|
||||
"./lib/sandboxed_renderer/api/exports/child_process.js:child_process",
|
||||
"-t",
|
||||
"aliasify",
|
||||
]
|
||||
|
@ -80,10 +72,6 @@ npm_action("atom_browserify_sandbox") {
|
|||
# Use a script to generate all dependencies and put them here.
|
||||
"lib/sandboxed_renderer/init.js",
|
||||
"lib/sandboxed_renderer/api/exports/electron.js",
|
||||
"lib/sandboxed_renderer/api/exports/fs.js",
|
||||
"lib/sandboxed_renderer/api/exports/os.js",
|
||||
"lib/sandboxed_renderer/api/exports/path.js",
|
||||
"lib/sandboxed_renderer/api/exports/child_process.js",
|
||||
]
|
||||
outputs = [
|
||||
"$target_gen_dir/js2c/preload_bundle.js",
|
||||
|
|
|
@ -9,16 +9,16 @@ exports.getRemote = function (name) {
|
|||
return remote[name]
|
||||
}
|
||||
|
||||
exports.getRemoteFor = function (usage) {
|
||||
exports.remoteRequire = function (name) {
|
||||
if (!remote) {
|
||||
throw new Error(`${usage} requires remote, which is not enabled`)
|
||||
throw new Error(`${name} requires remote, which is not enabled`)
|
||||
}
|
||||
return remote
|
||||
return remote.require(name)
|
||||
}
|
||||
|
||||
exports.potentiallyRemoteRequire = function (name) {
|
||||
if (process.sandboxed) {
|
||||
return exports.getRemoteFor(name).require(name)
|
||||
return exports.remoteRequire(name)
|
||||
} else {
|
||||
return require(name)
|
||||
}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
'use strict'
|
||||
|
||||
const { deprecate } = require('electron')
|
||||
|
||||
deprecate.warn(`require('child_process')`, `remote.require('child_process')`)
|
||||
|
||||
const { getRemoteFor } = require('@electron/internal/renderer/remote')
|
||||
module.exports = getRemoteFor('child_process').require('child_process')
|
|
@ -1,8 +0,0 @@
|
|||
'use strict'
|
||||
|
||||
const { deprecate } = require('electron')
|
||||
|
||||
deprecate.warn(`require('fs')`, `remote.require('fs')`)
|
||||
|
||||
const { getRemoteFor } = require('@electron/internal/renderer/remote')
|
||||
module.exports = getRemoteFor('fs').require('fs')
|
|
@ -1,8 +0,0 @@
|
|||
'use strict'
|
||||
|
||||
const { deprecate } = require('electron')
|
||||
|
||||
deprecate.warn(`require('os')`, `remote.require('os')`)
|
||||
|
||||
const { getRemoteFor } = require('@electron/internal/renderer/remote')
|
||||
module.exports = getRemoteFor('os').require('os')
|
|
@ -1,8 +0,0 @@
|
|||
'use strict'
|
||||
|
||||
const { deprecate } = require('electron')
|
||||
|
||||
deprecate.warn(`require('path')`, `remote.require('path')`)
|
||||
|
||||
const { getRemoteFor } = require('@electron/internal/renderer/remote')
|
||||
module.exports = getRemoteFor('path').require('path')
|
|
@ -91,13 +91,16 @@ Object.defineProperty(preloadProcess, 'noDeprecation', {
|
|||
|
||||
process.on('exit', () => preloadProcess.emit('exit'))
|
||||
|
||||
const { remoteRequire } = require('@electron/internal/renderer/remote')
|
||||
|
||||
// This is the `require` function that will be visible to the preload script
|
||||
function preloadRequire (module) {
|
||||
if (loadedModules.has(module)) {
|
||||
return loadedModules.get(module)
|
||||
}
|
||||
if (remoteModules.has(module)) {
|
||||
return require(module)
|
||||
electron.deprecate.warn(`require('${module}')`, `remote.require('${module}')`)
|
||||
return remoteRequire(module)
|
||||
}
|
||||
throw new Error('module not found')
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче