Updated JScript Enumerator (markdown)

Namhyeon, Go 2025-08-09 09:25:02 +09:00
parent 3a4623e98b
commit 64d3fcc7ef

@ -2,47 +2,7 @@
JScript has a class called Enumerator. This shows a small difference from the standard JavaScript.
For example, when accessing the value of an array, it is expressed as `arr(i)` instead of `arr[i]`. In this case, the type of array in JScript is marked as `unknown`, so in some cases, it has to be converted appropriately.
### Convert MS/JScript Enumerator to JSObject
```js
// The provided code snippet has been corrected by ChatGPT.
// https://chat.openai.com/share/eaab056c-d265-4ee3-b355-9f29176a9caa
// Related issues: welsonjs#75 welsonjs#42 welsonjs#30
Enumerator.prototype.toArray = function() {
var result = [];
while (!this.atEnd()) {
var currentItem = this.item();
var currentItemProperties = currentItem.Properties_;
var itemObject = {};
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 {
arrayValues.push(property.value(index));
index++;
} catch (e) {
break;
}
}
itemObject[property.name] = arrayValues;
}
propertiesEnumerator.moveNext();
}
result.push(itemObject);
this.moveNext();
}
return result;
};
```
Starting from WelsonJS version **0.2.7.54**, the `Array.from(<enumerator>)` method is supported for `Enumerator` objects.
### References
* https://stackoverflow.com/questions/23513680/why-does-swbemservices-execquery-return-more-properties-than-requested
@ -50,4 +10,5 @@ Enumerator.prototype.toArray = function() {
* http://www.java2s.com/Tutorial/JavaScript/0600__MS-JScript/Enumeratoritem.htm
* https://stackoverflow.com/questions/973016/jscript-enumerator-and-list-of-properties
* https://stackoverflow.com/questions/6346766/javascript-enumerator/6346909
* https://chat.openai.com/share/eaab056c-d265-4ee3-b355-9f29176a9caa
* https://chat.openai.com/share/eaab056c-d265-4ee3-b355-9f29176a9caa
* https://github.com/joncasey/modern-hta