add exports global object

pull/1/head
yann300 6 years ago
parent 832fdb2dbd
commit 213065bd59
  1. 12
      src/app/panels/terminal.js

@ -93,7 +93,7 @@ class Terminal {
self.registerFilter('script', basicFilter) self.registerFilter('script', basicFilter)
self._jsSandboxContext = {} self._jsSandboxContext = {}
self._jsSandbox = vm.createContext(self._jsSandboxContext) self._jsSandboxRegistered = {}
if (opts.shell) self._shell = opts.shell if (opts.shell) self._shell = opts.shell
register(self) register(self)
} }
@ -381,6 +381,7 @@ class Terminal {
</ul> </ul>
</li> </li>
<li>Executing common command to interact with the Remix interface (see list of commands above). Note that these commands can also be included and run from a JavaScript script.</li> <li>Executing common command to interact with the Remix interface (see list of commands above). Note that these commands can also be included and run from a JavaScript script.</li>
<li>Use exports/.register(key, obj)/.remove(key)/.clear() to register and reuse object across script executions.</li>
</ul> </ul>
</div>` </div>`
@ -601,7 +602,7 @@ class Terminal {
var self = this var self = this
var context = domTerminalFeatures(self, scopedCommands) var context = domTerminalFeatures(self, scopedCommands)
try { try {
var cmds = vm.createContext(Object.assign(self._jsSandboxContext, context)) var cmds = vm.createContext(Object.assign(self._jsSandboxContext, context, self._jsSandboxRegistered))
var result = vm.runInContext(script, cmds) var result = vm.runInContext(script, cmds)
self._jsSandboxContext = Object.assign(cmds, context) self._jsSandboxContext = Object.assign(cmds, context)
done(null, result) done(null, result)
@ -630,7 +631,12 @@ function domTerminalFeatures (self, scopedCommands) {
return setInterval(() => { self._shell('(' + fn.toString() + ')()', scopedCommands, () => {}) }, time) return setInterval(() => { self._shell('(' + fn.toString() + ')()', scopedCommands, () => {}) }, time)
}, },
clearTimeout: clearTimeout, clearTimeout: clearTimeout,
clearInterval: clearInterval clearInterval: clearInterval,
exports: {
register: (key, obj) => { self._jsSandboxRegistered[key] = obj },
remove: (key) => { delete self._jsSandboxRegistered[key] },
clear: () => { self._jsSandboxRegistered = {} }
}
} }
} }

Loading…
Cancel
Save