Forum: IronRuby agdlr test w/ ruby string

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
740c85b27e1a80c5f908d81dca5d4fbf?d=identicon&s=25 Jb Evain (Guest)
on 2009-04-01 15:16
(Received via mailing list)
Hey,

Moonlight currently fails the following agldr test:

it 'verifies SetProperty works' do
  new_ctl = HtmlPage.Document.CreateElement('div')
  new_value = "This is added by Merlin SL Test!"
  new_ctl.SetProperty("innerHTML", new_value)
  new_ctl.GetProperty("innerHTML").should.equal new_value.to_clr_string
end

it passes if I change the SetProperty line to:

  new_ctl.SetProperty("innerHTML", new_value.to_clr_string)

SetProperty's signature is `void SetProperty(string name, object
value)`, so I'd except it to convert the name "innerHTML" to a
clr_string, but not the value argument.

Is IronRuby doing some conversion here, or is it Silverlight doing
interesting things when marshalling the value?
Cb51033949ffccd982ae32c9f890f25a?d=identicon&s=25 Tomas Matousek (Guest)
on 2009-04-01 18:28
(Received via mailing list)
SetProperty converts Ruby string "innerHTML" to CLR string because its
first parameter is strongly typed to CLR string. The second parameter is
not and hence no conversion occurs.

This should work:

new_ctl.SetProperty("innerHTML", new_value)
new_ctl.GetProperty("innerHTML").should.equal new_value

The current implementation "==" compares Ruby strings and CLR strings by
value.
The implementation of "eql?" doesn't:

>>> x = 'str'
=> "str"
>>> y = x.to_clr_string
=> 'str'
>>> x == y
=> true
>>> x.eql? y
=> false

Which is similar to numerics in MRI:

irb(main):001:0> 1 == 1.0
=> true
irb(main):002:0> 1.eql? 1.0
=> false
irb(main):003:0> exit


Would it be better to override "eql?" on string to compare Ruby string
and CRL string equal if they have the same value?

Tomas
740c85b27e1a80c5f908d81dca5d4fbf?d=identicon&s=25 Jb Evain (Guest)
on 2009-04-01 19:21
(Received via mailing list)
Hey Tomas,

On 4/1/09, Tomas Matousek <Tomas.Matousek@microsoft.com> wrote:
> SetProperty converts Ruby string "innerHTML" to CLR string because its first parameter 
is strongly typed to CLR string. The second parameter is not and hence no conversion 
occurs.

Alright that's what I expected.

> The current implementation "==" compares Ruby strings and CLR strings by value.

>>> "" == "".to_clr_string
=> false

I see :) Now to fix it in Mono.

Thanks,
740c85b27e1a80c5f908d81dca5d4fbf?d=identicon&s=25 Jb Evain (Guest)
on 2009-04-02 10:24
(Received via mailing list)
On 4/1/09, Jb Evain <jb@nurv.fr> wrote:
>  Is IronRuby doing some conversion here, or is it Silverlight doing
>  interesting things when marshalling the value?

Alright, so for the curious, after an update, the string comparison
works ok on Moonlight.

The issue is indeed marshaling in Silverlight, which decides that
innerHTML is a string property, so it stringifies whatever you give it
to. Not obvious :)
This topic is locked and can not be replied to.