-
Notifications
You must be signed in to change notification settings - Fork 52
/
activex_filesystemobject_sample.js
41 lines (38 loc) · 1.27 KB
/
activex_filesystemobject_sample.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var win32ole = require('win32ole');
win32ole.print('activex_filesystemobject_sample\n');
var testfile = 'examples\\activex_filesystemobject_sample.js';
var activex_filesystemobject_sample = function(){
var withReadFile = function(filename, callback){
var fso = new ActiveXObject('Scripting.FileSystemObject');
var fullpath = fso.GetAbsolutePathName(filename);
var file = fso.OpenTextFile(fullpath, 1, false); // open to read
try{
callback(file);
}finally{
file.Close();
}
};
var withEachLine = function(filename, callback){
withReadFile(filename, function(file){
/*
In ParseUnaryExpression() < v8/src/parser.cc >
v8::Object::ToBoolean() is called directly for unary operator '!'
instead of v8::Object::valueOf()
so NamedPropertyHandler will not be called
Local<Boolean> ToBoolean(); // How to fake ? override v8::Value::ToBoolean
*/
// while(file.AtEndOfStream != true) // It works. (without unary operator !)
// while(!file.AtEndOfStream) // It does not work.
while(!file.AtEndOfStream._) // *** It works. oops!
callback(file.ReadLine());
});
};
withEachLine(testfile, function(line){
console.log(line);
});
};
try{
activex_filesystemobject_sample();
}catch(e){
console.log('*** exception cached ***\n' + e);
}