node-activex icon indicating copy to clipboard operation
node-activex copied to clipboard

DispObject support for ES6 "iterable protocol"

Open rtweeks opened this issue 4 years ago • 0 comments

It would be nice if DispObject::NodeGet implemented the ES6 "iterable protocol" when the target DispObject is wrapping a COM object implementing COM's idea of iterability. This way, the DispObject would be compatible with the ES6 for (...of...) loop construct when the underlying COM object is iterable.

It could implement this by responding to the name @@iterator by returning a function that attempts to send DISPID -4 to self->disp->ptr->Invoke(...) to get the "_NewEnum" IUknown* which should be queryable for IEnumVARIANT*. If it successfully finds an IEnumVARIANT*, wrap that up in a JavaScript object implementing the "iterator protocol" -- i.e. a next() method returning objects that provide done and value. If there is no IEnumVARIANT* available this way, it could just ~return an undefined value in response to @@iterator~ throw a TypeError. (Edited because I realized @@iterator actually needs to return a function.)

rtweeks avatar May 09 '20 14:05 rtweeks