@@ -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 PROXY = Symbol ( ) ;
98const TRACE_REF = 1 ;
109
1110export class WindowsScriptingHost extends EventEmitter {
@@ -31,7 +30,7 @@ export class WindowsScriptingHost extends EventEmitter {
3130 get ( target , prop ) {
3231 if ( prop === Symbol . toPrimitive )
3332 return ( ) => `ref#${ target . ref } ` ;
34- const encodedTarget = this . wsh . #encode( target [ PROXY ] ) ;
33+ const encodedTarget = this . wsh . #encode( target . proxy ) ;
3534 const encodedProp = this . wsh . #encode( prop ) ;
3635 const output = JSON . parse ( this . wsh . #syncline. exchange ( JSON . stringify ( [ 'get' , encodedTarget , encodedProp ] ) ) ) ;
3736 switch ( output [ 0 ] ) {
@@ -42,7 +41,7 @@ export class WindowsScriptingHost extends EventEmitter {
4241 } ,
4342
4443 set ( target , prop , value ) {
45- const encodedTarget = this . wsh . #encode( target [ PROXY ] ) ;
44+ const encodedTarget = this . wsh . #encode( target . proxy ) ;
4645 const encodedProp = this . wsh . #encode( prop ) ;
4746 const encodedValue = this . wsh . #encode( value ) ;
4847 const output = JSON . parse ( this . wsh . #syncline. exchange ( JSON . stringify ( [ 'set' , encodedTarget , encodedProp , encodedValue ] ) ) ) ;
@@ -65,7 +64,7 @@ export class WindowsScriptingHost extends EventEmitter {
6564 } ,
6665
6766 apply ( target , thisArg , argumentList ) {
68- const encodedTarget = this . wsh . #encode( target [ PROXY ] ) ;
67+ const encodedTarget = this . wsh . #encode( target . proxy ) ;
6968 const encodedThisArg = this . wsh . #encode( thisArg ) ;
7069 const encodedArgumentList = this . wsh . #encode( argumentList ) ;
7170 const output = JSON . parse ( this . wsh . #syncline. exchange ( JSON . stringify ( [ 'apply' , encodedTarget , encodedThisArg , encodedArgumentList ] ) ) ) ;
@@ -77,7 +76,7 @@ export class WindowsScriptingHost extends EventEmitter {
7776 } ,
7877
7978 construct ( target , argumentList ) {
80- const encodedTarget = this . wsh . #encode( target [ PROXY ] ) ;
79+ const encodedTarget = this . wsh . #encode( target . proxy ) ;
8180 const encodedArgumentList = this . wsh . #encode( argumentList ) ;
8281 const output = JSON . parse ( this . wsh . #syncline. exchange ( JSON . stringify ( [ 'construct' , encodedTarget , encodedArgumentList ] ) ) ) ;
8382 switch ( output [ 0 ] ) {
@@ -144,7 +143,7 @@ export class WindowsScriptingHost extends EventEmitter {
144143
145144 const target = handler === this . #objectHandler? new RemoteObject ( ref ) : function ( ) { } ;
146145 const newProxy = new Proxy ( target , handler ) ;
147- target [ PROXY ] = newProxy ;
146+ target . proxy = newProxy ;
148147 this . #ref2proxy. set ( ref , new WeakRef ( newProxy ) ) ; // may be overwriting a dead WeakRef
149148 this . #proxy2ref. set ( newProxy , ref ) ;
150149 this . #finalizer. register ( newProxy , ref ) ;
@@ -252,6 +251,7 @@ export class WindowsScriptingHost extends EventEmitter {
252251class RemoteObject {
253252
254253 #ref;
254+ #proxy;
255255
256256 constructor ( ref ) {
257257 this . #ref = ref ;
@@ -260,4 +260,12 @@ class RemoteObject {
260260 get ref ( ) {
261261 return this . #ref;
262262 }
263+
264+ get proxy ( ) {
265+ return this . #proxy;
266+ }
267+
268+ set proxy ( proxy ) {
269+ this . #proxy = proxy ;
270+ }
263271}
0 commit comments