@@ -5,7 +5,6 @@ import { Syncline} from "@arcticnotes/syncline";
55const COMMAND = 'cscript.exe' ;
66const ARGS = [ '//E:jscript' , '//NoLogo' ] ;
77const SCRIPT_FILE = PATH . join ( PATH . dirname ( import . meta. dirname ) , 'wsh' , 'host.js' ) ;
8- const TRACE_REF = 1 ;
98
109export class WindowsScriptingHost extends EventEmitter {
1110
@@ -14,11 +13,10 @@ export class WindowsScriptingHost extends EventEmitter {
1413 const args = options . args || ARGS ;
1514 const scriptFile = options . scriptFile || SCRIPT_FILE ;
1615 const trace = options . trace || 0 ;
17- return new WindowsScriptingHost ( await Syncline . spawn ( command , [ ...args , scriptFile ] , { trace} ) , options ) ;
16+ return new WindowsScriptingHost ( await Syncline . spawn ( command , [ ...args , scriptFile ] , { trace} ) ) ;
1817 }
1918
2019 #syncline;
21- #trace;
2220 #finalizer = new FinalizationRegistry ( this . #finalized. bind ( this ) ) ;
2321 #ref2proxy = new Map ( ) ;
2422 #proxy2ref = new WeakMap ( ) ;
@@ -87,19 +85,11 @@ export class WindowsScriptingHost extends EventEmitter {
8785 } ,
8886 } ;
8987
90- #WScript;
91- #GetObject;
92- #Enumerator;
93-
94- constructor ( syncline , options ) {
88+ constructor ( syncline ) {
9589 super ( ) ;
9690 this . #syncline = syncline ;
9791 this . #syncline. on ( 'stderr' , line => console . log ( 'wsh:' , line ) ) ;
9892 this . #syncline. on ( 'stdout' , line => console . log ( 'wsh:' , line ) ) ;
99- this . #trace = options . trace ;
100- this . #WScript = this . #getOrCreateObject( 0 ) ;
101- this . #GetObject = this . #getOrCreateFunction( 1 ) ;
102- this . #Enumerator = this . #getOrCreateFunction( 2 ) ;
10393 }
10494
10595 get remoteObjects ( ) {
@@ -111,16 +101,13 @@ export class WindowsScriptingHost extends EventEmitter {
111101 } ;
112102 }
113103
114- get WScript ( ) {
115- return this . #WScript;
116- }
117-
118- get GetObject ( ) {
119- return this . #GetObject;
120- }
121-
122- get Enumerator ( ) {
123- return this . #Enumerator;
104+ global ( name ) {
105+ const output = JSON . parse ( this . #syncline. exchange ( JSON . stringify ( [ 'global' , name ] ) ) ) ;
106+ switch ( output [ 0 ] ) {
107+ case 'value' : return this . #decode( output [ 1 ] ) ;
108+ case 'error' : throw new Error ( output [ 1 ] ) ;
109+ default : throw new Error ( `unknown status: ${ output [ 0 ] } ` ) ;
110+ }
124111 }
125112
126113 async disconnect ( ) {
@@ -155,17 +142,6 @@ export class WindowsScriptingHost extends EventEmitter {
155142 if ( this . #ref2proxy. get ( ref ) . deref ( ) === undefined ) // otherwise, it's overwritten by a refreshed proxy
156143 this . #ref2proxy. delete ( ref ) ;
157144 const output = this . #syncline. exchange ( JSON . stringify ( [ 'unref' , ref ] ) ) ;
158- if ( this . #trace >= TRACE_REF )
159- switch ( output [ 0 ] ) {
160- case 'error' :
161- console . log ( `failed to unref: ${ ref } ` ) ;
162- break ;
163- case 'done' :
164- console . log ( `unreferenced: ${ ref } ` ) ;
165- break ;
166- default :
167- console . log ( `unknown response: ${ output [ 0 ] } ` ) ;
168- }
169145 this . emit ( 'unref' , ref ) ;
170146 }
171147
0 commit comments