Skip to content

Commit a2e4fd4

Browse files
committed
support VBArray
1 parent 916b507 commit a2e4fd4

File tree

6 files changed

+37
-4
lines changed

6 files changed

+37
-4
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ jobs:
2323
shell: cmd
2424
run: chcp 65001
2525
- run: npm ci
26+
- run: cscript
2627
- 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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
// This file is in JScript, not in JavaScript. It is executed in Windows Scripting Host (WSH).
22

3+
function CreateVBArray( jsArray) {
4+
var dict = new ActiveXObject( 'Scripting.Dictionary');
5+
for( var i = 0; i < jsArray.length; i++)
6+
dict.Add( i, jsArray[ i]);
7+
dict.Add( 'length', jsArray.length);
8+
return Dict2VBArray( dict);
9+
}
10+
311
var FSO = new ActiveXObject( 'Scripting.FileSystemObject');
412
var OBJECT_TOSTRING = Object.toString();
513
var GLOBAL = this;
@@ -79,6 +87,7 @@ function encode( decoded) {
7987
return encoded;
8088
}
8189
// warning: intentional fall-through here!
90+
case 'unknown':
8291
case 'function':
8392
for( i in REFERENCES)
8493
if( REFERENCES[ i].value === decoded)

lib/wsh/host.vbs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Function Dict2VBArray( dict)
2+
Dim vbArray()
3+
ReDim vbArray( dict.Item( "length") - 1)
4+
Dim I
5+
For I = 0 To dict.Item( "length") - 1
6+
vbArray( I) = dict.Item( I)
7+
Next
8+
Dict2VBArray = vbArray
9+
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)