Skip to content

Commit 253d265

Browse files
committed
support VBArray
1 parent 6394a70 commit 253d265

File tree

6 files changed

+50
-6
lines changed

6 files changed

+50
-6
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ jobs:
1010
strategy:
1111
matrix:
1212
node-version:
13-
- 20.x
1413
- 22.x
15-
- 24.x
1614
steps:
1715
- uses: actions/checkout@v4
1816
- uses: actions/setup-node@v4
@@ -23,4 +21,5 @@ jobs:
2321
shell: cmd
2422
run: chcp 65001
2523
- run: npm ci
24+
- run: cscript
2625
- run: node --expose-gc --test

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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
// This file is in JScript, not in JavaScript. It is executed in Windows Scripting Host (WSH).
22

3+
WScript.StdErr.WriteLine( '>>>>>>>>>>>>>>>>> before');
4+
JSArray2VBArray( [ 1, 2, 3]);
5+
WScript.StdErr.WriteLine( '>>>>>>>>>>>>>>>>> after');
6+
7+
function CreateVBArray( jsArray) {
8+
WScript.StdErr.WriteLine( 'jsArray=' + JSON.stringify( jsArray));
9+
var vbArray = JSArray2VBArray( jsArray);
10+
WScript.StdErr.WriteLine( 'vbArray=' + vbArray);
11+
return vbArray;
12+
}
13+
314
var FSO = new ActiveXObject( 'Scripting.FileSystemObject');
415
var OBJECT_TOSTRING = Object.toString();
516
var GLOBAL = this;
@@ -79,6 +90,7 @@ function encode( decoded) {
7990
return encoded;
8091
}
8192
// warning: intentional fall-through here!
93+
case 'unknown':
8294
case 'function':
8395
for( i in REFERENCES)
8496
if( REFERENCES[ i].value === decoded)

lib/wsh/host.vbs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
WScript.StdErr.WriteLine "vbs: start iteration"
10+
For Each x In jsArray
11+
WScript.StdErr.WriteLine "vbs: vbArray(" & i & ") <- " & x
12+
vbArray( i) = x
13+
WScript.StdErr.WriteLine "vbs: vbArray(" & i & ") == " & x
14+
i = i + 1
15+
Next
16+
WScript.StdErr.WriteLine "vbs: almost done"
17+
JSArray2VBArray = vbArray
18+
WScript.StdErr.WriteLine "vbs: done"
19+
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)