Skip to content

Commit 01d52d3

Browse files
committed
support VBArray
1 parent 6394a70 commit 01d52d3

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed

lib/node/node-wsh.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import PATH from 'node:path';
33
import { Syncline} from "@arcticnotes/syncline";
44

55
const COMMAND = 'cscript.exe';
6-
const ARGS = [ '//E:jscript', '//NoLogo'];
7-
const SCRIPT_FILE = PATH.join( PATH.dirname( import.meta.dirname), 'wsh', 'host.js');
6+
const ARGS = [ '//NoLogo'];
7+
const SCRIPT_FILE = PATH.join( PATH.dirname( import.meta.dirname), 'wsh', 'host.wsf');
88

99
export class WindowsScriptingHost extends EventEmitter {
1010

lib/wsh/host.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ var nextRefId = 0;
88

99
eval( FSO.OpenTextFile( FSO.BuildPath( FSO.GetParentFolderName( WScript.ScriptFullName), 'json2.js')).ReadAll());
1010

11+
function CreateVBArray( jsArray) {
12+
WScript.StdErr.WriteLine( 'jsArray=' + JSON.stringify( jsArray));
13+
var vbArray = JSArray2VBArray( jsArray);
14+
WScript.StdErr.WriteLine( 'vbArray=' + vbArray);
15+
return vbArray;
16+
}
17+
1118
function decode( encoded) {
1219
var decoded;
1320
var item;
@@ -79,6 +86,7 @@ function encode( decoded) {
7986
return encoded;
8087
}
8188
// warning: intentional fall-through here!
89+
case 'unknown':
8290
case 'function':
8391
for( i in REFERENCES)
8492
if( REFERENCES[ i].value === decoded)

lib/wsh/host.vbs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Function JSArray2VBArray( jsArray)
2+
Dim vbArray()
3+
ReDim vbArray( jsArray.length - 1)
4+
Dim i
5+
Dim x
6+
WScript.StdErr.WriteLine "vbs: jsArray=" & jsArray
7+
WScript.StdErr.WriteLine "vbs: jsArray.length=" & jsArray.length
8+
i = 0
9+
For Each x In jsArray
10+
vbArray( i) = x
11+
WScript.StdErr.WriteLine "vbs: vbArray(" & i & ")=" & x
12+
i = i + 1
13+
Next
14+
WScript.StdErr.WriteLine "vbs: almost done"
15+
JSArray2VBArray = vbArray
16+
WScript.StdErr.WriteLine "vbs: done"
17+
End Function

lib/wsh/host.wsf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<job>
2+
<script language="VBScript" src="host.vbs" />
3+
<script language="JScript" src="host.js" />
4+
</job>

test/test.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { WindowsScriptingHost} from '@arcticnotes/node-wsh';
44

55
TEST( 'smoke-test', async() => {
66
const wsh = await WindowsScriptingHost.connect();
7-
wsh.on( 'ref', ( ref, obj) => console.log( 'ref', ref, obj));
8-
wsh.on( 'unref', ref => console.log( 'unref', ref));
97
try {
8+
wsh.on( 'ref', ( ref, obj) => console.log( 'ref', ref, obj));
9+
wsh.on( 'unref', ref => console.log( 'unref', ref));
1010
const WScript = wsh.global( 'WScript');
1111
const GetObject = wsh.global( 'GetObject');
1212
const Enumerator = wsh.global( 'Enumerator');
@@ -27,3 +27,13 @@ TEST( 'smoke-test', async() => {
2727
await wsh.disconnect();
2828
}
2929
});
30+
31+
TEST( 'vbarray', async() => {
32+
const wsh = await WindowsScriptingHost.connect();
33+
try {
34+
const CreateVBArray = wsh.global( 'CreateVBArray');
35+
ASSERT.equal( typeof CreateVBArray( [ 1, 3, 5]), 'function');
36+
} finally {
37+
await wsh.disconnect();
38+
}
39+
});

0 commit comments

Comments
 (0)