From 213065bd59b37325fb98f66c1d396db9bcfc53c9 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 24 Oct 2018 16:02:30 +0200 Subject: [PATCH] add exports global object --- src/app/panels/terminal.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/app/panels/terminal.js b/src/app/panels/terminal.js index c6612ea038..5c5f98c70a 100644 --- a/src/app/panels/terminal.js +++ b/src/app/panels/terminal.js @@ -93,7 +93,7 @@ class Terminal { self.registerFilter('script', basicFilter) self._jsSandboxContext = {} - self._jsSandbox = vm.createContext(self._jsSandboxContext) + self._jsSandboxRegistered = {} if (opts.shell) self._shell = opts.shell register(self) } @@ -377,10 +377,11 @@ class Terminal {
  • 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.
  • +
  • Use exports/.register(key, obj)/.remove(key)/.clear() to register and reuse object across script executions.
  • ` @@ -601,7 +602,7 @@ class Terminal { var self = this var context = domTerminalFeatures(self, scopedCommands) 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) self._jsSandboxContext = Object.assign(cmds, context) done(null, result) @@ -630,7 +631,12 @@ function domTerminalFeatures (self, scopedCommands) { return setInterval(() => { self._shell('(' + fn.toString() + ')()', scopedCommands, () => {}) }, time) }, clearTimeout: clearTimeout, - clearInterval: clearInterval + clearInterval: clearInterval, + exports: { + register: (key, obj) => { self._jsSandboxRegistered[key] = obj }, + remove: (key) => { delete self._jsSandboxRegistered[key] }, + clear: () => { self._jsSandboxRegistered = {} } + } } }