Skip to content

Commit 690361d

Browse files
committed
support VBArray
1 parent 6394a70 commit 690361d

6 files changed

Lines changed: 36 additions & 4 deletions

File tree

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

3+
function CreateVBArray( jsArray) {
4+
return JSArray2VBArray( jsArray);
5+
}
6+
37
var FSO = new ActiveXObject( 'Scripting.FileSystemObject');
48
var OBJECT_TOSTRING = Object.toString();
59
var GLOBAL = this;
@@ -79,6 +83,7 @@ function encode( decoded) {
7983
return encoded;
8084
}
8185
// warning: intentional fall-through here!
86+
case 'unknown':
8287
case 'function':
8388
for( i in REFERENCES)
8489
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 - 1)
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( [ 1, 3, 5]), 'function');
36+
// } finally {
37+
// await wsh.disconnect();
38+
// }
39+
//});

0 commit comments

Comments
 (0)