diff --git a/lib/std.js b/lib/std.js index 077eb9e..f09d59b 100644 --- a/lib/std.js +++ b/lib/std.js @@ -27,52 +27,41 @@ if (!Function.prototype.GetResource) { } } -if (!Enumerator.prototype.toArray) { - Enumerator.prototype.toArray = function() { - var items = []; - for (; !this.atEnd(); this.moveNext()) { - var item = this.item(); - try { - items.push(item); - } catch (e) {} - } - return items; - }; -} +// The provided code snippet has been corrected by ChatGPT. +// https://chat.openai.com/share/eaab056c-d265-4ee3-b355-9f29176a9caa +// Related issues: #75 #42 #30 +Enumerator.prototype.toArray = function() { + var result = []; + while (!this.atEnd()) { + var currentItem = this.item(); + var currentItemProperties = currentItem.Properties_; + var itemObject = {}; -if (!Enumerator.prototype.toArray2) { - Enumerator.prototype.toArray2 = function() { - var a = []; - for (; !this.atEnd(); this.moveNext()) { - var x = {}; - var b = new Enumerator(this.item().Properties_); - for (; !b.atEnd(); b.moveNext()) { - var c = b.item(); - if (typeof c.value !== "unknown") { + var propertiesEnumerator = new Enumerator(currentItemProperties); + while (!propertiesEnumerator.atEnd()) { + var property = propertiesEnumerator.item(); + if (typeof property.value !== "unknown") { // The type "Unknown" is Array + itemObject[property.name] = property.value; + } else { + var arrayValues = []; + var index = 0; + while (true) { try { - x[c.name] = c.value.toString(); + arrayValues.push(property.value(index)); + index++; } catch (e) { - x[c.name] = c.value; + break; } - } else { - var i = 0, - d = []; - while (true) { - try { - d.push(c.value(i)); - i++; - } catch (e) { - break; - } - } - x[c.name] = d; } + itemObject[property.name] = arrayValues; } - a.push(x); + propertiesEnumerator.moveNext(); } - return a; - }; -} + result.push(itemObject); + this.moveNext(); + } + return result; +}; ///////////////////////////////////////////////////////////////////////////////// // Global APIs @@ -535,7 +524,7 @@ global.splitLn = splitLn; global.addslashes = addslashes; 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.require = global.require; diff --git a/lib/wmi.js b/lib/wmi.js index 881a88c..1f09847 100644 --- a/lib/wmi.js +++ b/lib/wmi.js @@ -57,10 +57,6 @@ var WMIQueryObject = function() { this.fetchAll = function() { return this.cursor.toArray(); }; - - this.fetchAll2 = function() { - return this.cursor.toArray2(); - }; this.get = function(key) { if (key in this.current) { @@ -162,6 +158,6 @@ exports.create = create; exports.execQuery = execQuery; 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.require = global.require; diff --git a/testloader.js b/testloader.js index 0818d79..ba52b6c 100644 --- a/testloader.js +++ b/testloader.js @@ -260,9 +260,11 @@ var test_implements = { "system_get_network_interfaces": function() { var SYS = require("lib/system"); - - var net_interfaces = SYS.getNetworkInterfaces(); - console.log(JSON.stringify(net_interfaces)); + + var netInterfaces = SYS.getNetworkInterfaces(); + netInterfaces.forEach(function(x) { + console.log(x.Caption); + }); }, "system_get_process_list": function() { @@ -270,7 +272,7 @@ var test_implements = { var processList = SYS.getProcessList(); 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"); processList.forEach(function(x) { - console.log(x.Caption, x.ProcessID); + console.log(x.Caption, x.ProcessId); }); },