@@ -34,7 +34,8 @@ class Application extends events.EventEmitter {
3434
3535 createSandbox ( ) {
3636 const introspection = async ( ) => [ ...this . api . keys ( ) ] ;
37- const application = { security, api : { introspection } } ;
37+ const context = Object . freeze ( { } ) ;
38+ const application = { security, api : { introspection } , context } ;
3839 for ( const name of this . namespaces ) application [ name ] = this [ name ] ;
3940 const sandbox = { console : this . logger , application, Buffer, api } ;
4041 sandbox . global = sandbox ;
@@ -51,7 +52,7 @@ class Application extends events.EventEmitter {
5152 const data = await fsp . readFile ( fileName , 'utf8' ) ;
5253 const code = data . startsWith ( '({' ) ? data :
5354 `({ access: 'logged', method: ${ data . trim ( ) . slice ( 0 , - 1 ) } });` ;
54- const src = `'use strict';\ncontext => ${ code } ` ;
55+ const src = `'use strict';\n ${ code } ` ;
5556 const options = { filename : fileName , lineOffset : - 1 } ;
5657 try {
5758 return new vm . Script ( src , options ) ;
@@ -61,7 +62,8 @@ class Application extends events.EventEmitter {
6162 }
6263 }
6364
64- runScript ( methodName , sandbox = this . sandbox ) {
65+ runScript ( methodName , session ) {
66+ const sandbox = session ? session . sandbox : this . sandbox ;
6567 const script = this . api . get ( methodName ) ;
6668 if ( ! script ) return null ;
6769 return script . runInContext ( sandbox , SCRIPT_OPTIONS ) ;
0 commit comments