Glue-free JSCall#

One of my goals during this rewriting of VandalSniper as a more general-purpose browser has been to reduce or eliminate the dependency on platform-specific glue libraries. JSCall# uses a C/C++ library to interact with the DOM, and this is just one more hurdle to be jumped over on the road to portability. Who wants to set up a build environment against Mozilla on Windows? Not me.

So I started fiddling around with Gecko# some, and discovered that it's possible -- and simple, really -- to eliminate the glue library. To place a call to JavaScript from the CLI, it's as simple as calling WebControl.LoadUrl() passing a string like "javascript:someFunction()". This does change the return from WebControl.Location, but this can be worked around easily enough.

To make calls back, I copied an idea from JSCall#. The call is placed by constructing a string containing the function name and argument list, and the document title is set to this string, then immediately set back to what it was. This is picked up by the WebControl.TitleChange event handler, where the pieces are pulled apart into an array, the function name mapped to a delegate, and the delegate invoked with the arguments.

One of the cool things about the "javascript:" method of calling functions is that it seems to work just as well for whole function libraries, even those with newlines in them. The only caveat I've discovered is that if there is any //-style comment in the JavaScript, everything after it will be ignored. It seems that while embedded newlines are okay, they aren't really treated as newlines. WikiBench does nothing to correct for this; it's assumed that addins know about this. While I'd love to have it strip such comments out, that would require some parsing work ("//" can be embedded in a string safely, for example).

It's one big kludge, but it works remarkably well.