Skip to content

Commit c6f5b9f

Browse files
committed
support VBArray
1 parent 6394a70 commit c6f5b9f

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ 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+
return JSArray2VBArray( jsArray);
14+
}
15+
1116
function decode( encoded) {
1217
var decoded;
1318
var item;
@@ -79,6 +84,7 @@ function encode( decoded) {
7984
return encoded;
8085
}
8186
// warning: intentional fall-through here!
87+
case 'unknown':
8288
case 'function':
8389
for( i in REFERENCES)
8490
if( REFERENCES[ i].value === decoded)

lib/wsh/host.vbs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Function JSArray2VBArray( jsArray)
2+
Dim vbArray()
3+
ReDim vbArray( jsArray.length)
4+
Dim i
5+
Dim x
6+
i = 0
7+
For Each x In jsArray
8+
vbArray( i) = x
9+
i = i + 1
10+
Next
11+
JSArray2VBArray = vbArray
12+
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( [ 'a', 'b', 'c']), 'function');
36+
} finally {
37+
await wsh.disconnect();
38+
}
39+
});

0 commit comments

Comments
 (0)