Expose builtin v8 modules to AtomSandboxedRendererClient
- Adapt node.cc code that implements `process.binding` to create a similar object in AtomSandboxedRendererClient. - Replace the ipc binding object passed to `lib/sandboxed_renderer/init.js` by the new binding object. - Refactor the initialization script to use this new object to fetch the ipc binding and store as a hidden value using the `v8_util` module. This change also required applying a patch to node.js, so the submodule commit was updated.
This commit is contained in:
parent
85d66d2413
commit
d78f3cae7b
7 changed files with 89 additions and 31 deletions
13
lib/common/atom-binding-setup.js
Normal file
13
lib/common/atom-binding-setup.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
module.exports = function atomBindingSetup (binding, processType) {
|
||||
return function atomBinding (name) {
|
||||
try {
|
||||
return binding(`atom_${processType}_${name}`)
|
||||
} catch (error) {
|
||||
if (/No such module/.test(error.message)) {
|
||||
return binding(`atom_common_${name}`)
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,18 +1,6 @@
|
|||
const timers = require('timers')
|
||||
|
||||
const {binding} = process
|
||||
|
||||
process.atomBinding = function (name) {
|
||||
try {
|
||||
return binding(`atom_${process.type}_${name}`)
|
||||
} catch (error) {
|
||||
if (/No such module/.test(error.message)) {
|
||||
return binding(`atom_common_${name}`)
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
process.atomBinding = require('./atom-binding-setup')(process.binding, process.type)
|
||||
|
||||
// setImmediate and process.nextTick makes use of uv_check and uv_prepare to
|
||||
// run the callbacks, however since we only run uv loop on requests, the
|
||||
|
|
|
@ -2,25 +2,32 @@
|
|||
// in filenames.gypi so they get built into the preload_bundle.js bundle
|
||||
|
||||
/* eslint no-eval: "off" */
|
||||
/* global binding, preloadPath, process, Buffer */
|
||||
/* global binding, preloadPath, Buffer */
|
||||
const events = require('events')
|
||||
|
||||
const atomBinding = require('../common/atom-binding-setup')(binding.get, 'renderer')
|
||||
|
||||
const v8Util = atomBinding('v8_util')
|
||||
const ipc = atomBinding('ipc')
|
||||
|
||||
const ipcRenderer = new events.EventEmitter()
|
||||
const proc = new events.EventEmitter()
|
||||
// eval in window scope:
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-10.4.2
|
||||
const geval = eval
|
||||
|
||||
require('../renderer/api/ipc-renderer-setup')(ipcRenderer, binding)
|
||||
require('../renderer/api/ipc-renderer-setup')(ipcRenderer, ipc)
|
||||
|
||||
binding.onMessage = function (channel, args) {
|
||||
ipc.onMessage = function (channel, args) {
|
||||
ipcRenderer.emit(channel, ...args)
|
||||
}
|
||||
|
||||
binding.onExit = function () {
|
||||
ipc.onExit = function () {
|
||||
proc.emit('exit')
|
||||
}
|
||||
|
||||
v8Util.setHiddenValue(global, 'ipc', ipc)
|
||||
|
||||
const preloadModules = new Map([
|
||||
['electron', {
|
||||
ipcRenderer: ipcRenderer
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue