[a134] Fail when "for k, v in cls.Prototype.OwnProps()"

Report problems with documented functionality
User avatar
aseiot
Posts: 79
Joined: 05 Mar 2017, 04:25

[a134] Fail when "for k, v in cls.Prototype.OwnProps()"

Post by aseiot » 15 May 2021, 08:33

I found that ahk fail to enum properties of the prototype of a class when retrieve both name and value.
Following demonstrated it. Don't know whether this is intended.

Code: Select all

class a
{
	method1()=>""
	method2()=>""
}

for k in a.Prototype.OwnProps(){
	MsgBox k							; ok in this situation
}

for k, v in a.Prototype.OwnProps(){
	MsgBox k							; fail after first run
}

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: [a134] Fail when "for k, v in cls.Prototype.OwnProps()"

Post by swagfag » 15 May 2021, 09:12

yes, its by design:
  • If two variables were specified, the enumerator attempts to call the property's getter to retrieve the value.
    • ...
    • If Obj is a class prototype object, the getter should not (and in some cases cannot) be called; so the property is skipped.

User avatar
aseiot
Posts: 79
Joined: 05 Mar 2017, 04:25

Re: [a134] Fail when "for k, v in cls.Prototype.OwnProps()"

Post by aseiot » 15 May 2021, 09:29

Thanks. I understand it is reasonable to skipped it, but should it failed? And I found a work around method to get the methods defined in a class.

Code: Select all

class a
{
	method1()=>""
	method2()=>""
}

for k in a.Prototype.OwnProps(){
	if (k = "__Class") or (k = "__Init")
		continue
	if (v := a.Prototype.GetOwnPropDesc(k)) && v.HasProp("Call")
		MsgBox "Class HasMethod: " k  
}

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: [a134] Fail when "for k, v in cls.Prototype.OwnProps()"

Post by swagfag » 15 May 2021, 16:43

nothing is failing. to fail means an exception was thrown(which isnt whats happening here). u only get one iteration of the loop as a consequence of the documented behavior.

Post Reply

Return to “Bug Reports”