Permalink
Browse files

chore: simplify code for modules internally using remote.require in s…

…andbox (#16104)
  • Loading branch information...
miniak authored and alexeykuzmin committed Dec 17, 2018
1 parent c64b4a3 commit 7a6fe00f494d79d738efdd015f94d9772cf23d54
@@ -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)
}

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -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')
}

0 comments on commit 7a6fe00

Please sign in to comment.