Bug in sigslot when disconnecting a slot
Darren Hobbs <[email protected]> Fri, 27 Aug 2004 19:20:50 -0500
| Newsgroups | gmane.comp.windows.devel.netwindows |
|---|---|
| Message-ID | <OF56947696.0587B034-ON85256EFE.0000B6F5-85256EFE.0001D586@thoughtworks.com> |
This is a multipart message in MIME format.
--===============0730476066==
Content-Type: multipart/alternative;
boundary="=_alternative 0001D58085256EFE_="
This is a multipart message in MIME format.
--=_alternative 0001D58085256EFE_=
Content-Type: text/plain; charset="US-ASCII"
The sigslot framework appears to have a bug in the rmSlot method where it
doesn't remove the correct slot. I've included a version that addresses
the issue. The reassignment of the slots array removes any 'holes'. Not
knowing enough about javascript's memory management, this step may not be
needed - the code works fine without it, as it leaves empty array entries
as 'undefined' which always fail the equality check.
Regards,
-Darren
this.rmSlot = function(pobj, pfp){
if(__sig__.isSigFP(pfp)){
var tslot = __sig__.getSig(pfp);
var tsl = this.slots.length;
for(var x=(tsl-1); x>=0; x-=1){
if(this.slots[x]==tslot){
// Fix bug
delete this.slots[x];
// if only 2 arguments were passed, or the
third isn't "true", return.
if((arguments.length<3)||(arguments[2]!=true)){
// changed 'return true'
to break
break;
}
}
}
// Reassign slots to remove empty entries
var newSlots = [];
var m = 0;
for (var n=0; n < this.slots.length; n++) {
if (this.slots[n] != undefined) {
newSlots[m++] = this.slots[n];
}
}
this.slots = newSlots;
// End of slot reassignment
return true;
}else{
return false;
}
}
--=_alternative 0001D58085256EFE_=
Content-Type: text/html; charset="US-ASCII"
<br><font size=2 face="sans-serif">The sigslot framework appears to have
a bug in the rmSlot method where it doesn't remove the correct slot. I've
included a version that addresses the issue. The reassignment of
the slots array removes any 'holes'. Not knowing enough about javascript's
memory management, this step may not be needed - the code works fine without
it, as it leaves empty array entries as 'undefined' which always fail the
equality check.</font>
<br>
<br><font size=2 face="sans-serif">Regards,</font>
<br>
<br><font size=2 face="sans-serif">-Darren</font>
<br>
<br><font size=2><tt>this.rmSlot = function(pobj, pfp){<br>
if(__sig__.isSigFP(pfp)){<br>
var tslot
= __sig__.getSig(pfp);<br>
var tsl
= this.slots.length;<br>
for(var
x=(tsl-1); x>=0; x-=1){<br>
if(this.slots[x]==tslot){</tt></font>
<br><font size=2><tt>
// Fix bug<br>
delete this.slots[x];<br>
<br>
// if only 2 arguments were passed, or
the third isn't "true", return.<br>
if((arguments.length<3)||(arguments[2]!=true)){</tt></font>
<br><font size=2><tt>
// changed 'return true' to break<br>
break;<br>
}<br>
}<br>
}</tt></font>
<br><font size=2><tt>
// Reassign slots to remove empty entries<br>
var newSlots
= [];<br>
var m =
0;<br>
for (var
n=0; n < this.slots.length; n++) {<br>
if (this.slots[n] != undefined) {<br>
newSlots[m++] = this.slots[n];<br>
}<br>
}<br>
this.slots
= newSlots;</tt></font>
<br><font size=2><tt>
// End of slot reassignment<br>
<br>
return true;<br>
}else{<br>
return false;<br>
}<br>
}<br>
</tt></font>
--=_alternative 0001D58085256EFE_=--
--===============0730476066==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
The netWindows developers list: [email protected]
http://netwindows.org/mailman/listinfo/devel_netwindows.org
--===============0730476066==--