mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-16 22:51:04 +00:00
Fix Enumerator.toArray method and related issues
This commit is contained in:
parent
da36ad57be
commit
4906799170
61
lib/std.js
61
lib/std.js
|
@ -27,52 +27,41 @@ if (!Function.prototype.GetResource) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Enumerator.prototype.toArray) {
|
// The provided code snippet has been corrected by ChatGPT.
|
||||||
Enumerator.prototype.toArray = function() {
|
// https://chat.openai.com/share/eaab056c-d265-4ee3-b355-9f29176a9caa
|
||||||
var items = [];
|
// Related issues: #75 #42 #30
|
||||||
for (; !this.atEnd(); this.moveNext()) {
|
Enumerator.prototype.toArray = function() {
|
||||||
var item = this.item();
|
var result = [];
|
||||||
try {
|
while (!this.atEnd()) {
|
||||||
items.push(item);
|
var currentItem = this.item();
|
||||||
} catch (e) {}
|
var currentItemProperties = currentItem.Properties_;
|
||||||
}
|
var itemObject = {};
|
||||||
return items;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Enumerator.prototype.toArray2) {
|
var propertiesEnumerator = new Enumerator(currentItemProperties);
|
||||||
Enumerator.prototype.toArray2 = function() {
|
while (!propertiesEnumerator.atEnd()) {
|
||||||
var a = [];
|
var property = propertiesEnumerator.item();
|
||||||
for (; !this.atEnd(); this.moveNext()) {
|
if (typeof property.value !== "unknown") { // The type "Unknown" is Array
|
||||||
var x = {};
|
itemObject[property.name] = property.value;
|
||||||
var b = new Enumerator(this.item().Properties_);
|
|
||||||
for (; !b.atEnd(); b.moveNext()) {
|
|
||||||
var c = b.item();
|
|
||||||
if (typeof c.value !== "unknown") {
|
|
||||||
try {
|
|
||||||
x[c.name] = c.value.toString();
|
|
||||||
} catch (e) {
|
|
||||||
x[c.name] = c.value;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
var i = 0,
|
var arrayValues = [];
|
||||||
d = [];
|
var index = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
d.push(c.value(i));
|
arrayValues.push(property.value(index));
|
||||||
i++;
|
index++;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
x[c.name] = d;
|
itemObject[property.name] = arrayValues;
|
||||||
}
|
}
|
||||||
|
propertiesEnumerator.moveNext();
|
||||||
}
|
}
|
||||||
a.push(x);
|
result.push(itemObject);
|
||||||
|
this.moveNext();
|
||||||
}
|
}
|
||||||
return a;
|
return result;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
// Global APIs
|
// Global APIs
|
||||||
|
@ -535,7 +524,7 @@ global.splitLn = splitLn;
|
||||||
global.addslashes = addslashes;
|
global.addslashes = addslashes;
|
||||||
global.AsyncFunction = AsyncFunction;
|
global.AsyncFunction = AsyncFunction;
|
||||||
|
|
||||||
exports.VERSIONINFO = "Standard Library (std.js) version 0.8.1";
|
exports.VERSIONINFO = "Standard Library (std.js) version 0.8.2";
|
||||||
exports.global = global;
|
exports.global = global;
|
||||||
exports.require = global.require;
|
exports.require = global.require;
|
||||||
|
|
||||||
|
|
|
@ -58,10 +58,6 @@ var WMIQueryObject = function() {
|
||||||
return this.cursor.toArray();
|
return this.cursor.toArray();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.fetchAll2 = function() {
|
|
||||||
return this.cursor.toArray2();
|
|
||||||
};
|
|
||||||
|
|
||||||
this.get = function(key) {
|
this.get = function(key) {
|
||||||
if (key in this.current) {
|
if (key in this.current) {
|
||||||
return this.current[key];
|
return this.current[key];
|
||||||
|
@ -162,6 +158,6 @@ exports.create = create;
|
||||||
exports.execQuery = execQuery;
|
exports.execQuery = execQuery;
|
||||||
exports.setClass = setClass;
|
exports.setClass = setClass;
|
||||||
|
|
||||||
exports.VERSIONINFO = "WMI interface (wmi.js) version 0.1.1";
|
exports.VERSIONINFO = "WMI interface (wmi.js) version 0.1.2";
|
||||||
exports.global = global;
|
exports.global = global;
|
||||||
exports.require = global.require;
|
exports.require = global.require;
|
||||||
|
|
|
@ -261,8 +261,10 @@ var test_implements = {
|
||||||
"system_get_network_interfaces": function() {
|
"system_get_network_interfaces": function() {
|
||||||
var SYS = require("lib/system");
|
var SYS = require("lib/system");
|
||||||
|
|
||||||
var net_interfaces = SYS.getNetworkInterfaces();
|
var netInterfaces = SYS.getNetworkInterfaces();
|
||||||
console.log(JSON.stringify(net_interfaces));
|
netInterfaces.forEach(function(x) {
|
||||||
|
console.log(x.Caption);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
"system_get_process_list": function() {
|
"system_get_process_list": function() {
|
||||||
|
@ -270,7 +272,7 @@ var test_implements = {
|
||||||
|
|
||||||
var processList = SYS.getProcessList();
|
var processList = SYS.getProcessList();
|
||||||
processList.forEach(function(x) {
|
processList.forEach(function(x) {
|
||||||
console.log(x.Caption, x.ProcessID);
|
console.log(x.Caption, x.ProcessId);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -279,7 +281,7 @@ var test_implements = {
|
||||||
|
|
||||||
var processList = SYS.getProcessListByName("explorer.exe");
|
var processList = SYS.getProcessListByName("explorer.exe");
|
||||||
processList.forEach(function(x) {
|
processList.forEach(function(x) {
|
||||||
console.log(x.Caption, x.ProcessID);
|
console.log(x.Caption, x.ProcessId);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user