Jump to content

booleans and Scripting.Dictionary objects


Recommended Posts

While debugging my JSON library, I've run into a situation where working with a Scripting.Dictionary object results in my boolean values being changed into numbers.

func testDictionary($a)
    local $d=objCreate('Scripting.Dictionary')
    for $i=0 to ubound($a)-1
        $d.add($i,$a[$i])
    next
    return $d
endfunc

local $aTest[2]=[false,true]

msgbox(0,default,$aTest[0]) ; displays false
msgbox(0,default,$aTest[1]) ; displays true

local $ignore=testDictionary($aTest)

msgbox(0,default,$aTest[0]) ; now displays 0 instead of false
msgbox(0,default,$aTest[1]) ; now displays 1 instead of true

Apparently, by just referencing the boolean values in the $d.add() call, they're converted into numbers within my array.

The only way I've found to avoid this problem is to make sure I have an immutable reference to my variables – in this case, by changing the top line to:

func testDictionary(const byRef $a)

[url='http://www.autoitscript.com/forum/index.php?showtopic=104150']JSON UDF Library (fully RFC4627-compliant)[/url][url='http://www.autoitscript.com/forum/index.php?showtopic=104325']Keep Windows Clear of Top Taskbar (for those who like their taskbar on top)[/url]

Link to comment
Share on other sites

It's a bit surprising that a COM object can mutate my variable types just by "looking" at them like this. This was nowhere on my radar screen when looking for bugs, and introduces another potential set of unexpected side-effects to watch out for.

Also, when dealing with JSON data, the distinction between "0" and "false" can indeed be significant.

That being said, I'm sure your explanation covers why this particular scenario may have gone unnoticed until now.

[url='http://www.autoitscript.com/forum/index.php?showtopic=104150']JSON UDF Library (fully RFC4627-compliant)[/url][url='http://www.autoitscript.com/forum/index.php?showtopic=104325']Keep Windows Clear of Top Taskbar (for those who like their taskbar on top)[/url]

Link to comment
Share on other sites

Opened a ticket for this issue: #1234

(…that's amazing, I've got the same combination on my luggage!):)

[url='http://www.autoitscript.com/forum/index.php?showtopic=104150']JSON UDF Library (fully RFC4627-compliant)[/url][url='http://www.autoitscript.com/forum/index.php?showtopic=104325']Keep Windows Clear of Top Taskbar (for those who like their taskbar on top)[/url]

Link to comment
Share on other sites

I love that movie... But they said 12345 :)

Details, details… :P

In related news, a recent phishing attack revealed that '12345' was the most popular phished Hotmail password. Apparently President Skroob uses Hotmail! :)

[url='http://www.autoitscript.com/forum/index.php?showtopic=104150']JSON UDF Library (fully RFC4627-compliant)[/url][url='http://www.autoitscript.com/forum/index.php?showtopic=104325']Keep Windows Clear of Top Taskbar (for those who like their taskbar on top)[/url]

Link to comment
Share on other sites

Details, details… :idea:

In related news, a recent phishing attack revealed that '12345' was the most popular phished Hotmail password. Apparently President Skroob uses Hotmail! :P

It's nice seeing Skroob is still alive after crashing on the "Planet of the Apes" :)

(I wonder how the apes got internet though :) )

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...