<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>crowder's blog &#187; software</title>
	<atom:link href="http://blog.mozilla.com/bcrowder/category/software/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mozilla.com/bcrowder</link>
	<description>what I'm doing, what I'm interested in, random junk</description>
	<lastBuildDate>Fri, 18 Feb 2011 16:59:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>jswrap (C++ love for Spidermonkey)</title>
		<link>http://blog.mozilla.com/bcrowder/2008/09/17/jswrap-c-love-for-spidermonkey/</link>
		<comments>http://blog.mozilla.com/bcrowder/2008/09/17/jswrap-c-love-for-spidermonkey/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 19:50:08 +0000</pubDate>
		<dc:creator>bcrowder</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://blog.mozilla.com/bcrowder/?p=19</guid>
		<description><![CDATA[A couple of years ago I started and then abandoned a project that implemented what I thought then were a couple of cute ideas to do with using boost (the outstanding C++ libraries found at boost.org) to automatically generate wrappers for C++ objects to be used in Spidermonkey. I&#8217;ve shared pieces of the code before, [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of years ago I started and then abandoned a project that implemented what I thought then were a couple of cute ideas to do with using boost (the outstanding C++ libraries found at <a href="http://www.boost.org">boost.org</a>) to automatically generate wrappers for C++ objects to be used in Spidermonkey.  I&#8217;ve shared pieces of the code before, to people who needed a C++-style error-reporter for Spidermonkey, or whatever, but I&#8217;ve never bothered actually sharing the whole thing.  Well, that seems silly, so I&#8217;m <a href="http://people.mozilla.com/~bcrowder/wrapdemo.tar.gz">sharing it now</a>.</p>
<p>There is a lot left to be done here; as I said, I abandoned the project.  All I&#8217;ve done since then is a tweak here or there, and a couple of cleanups I made today.</p>
<p>As I said, though, it implements some cute ideas:</p>
<ul>
<li>You can get a simple JS program running in two or three lines of C++ code (snipped from demo.cpp):
<pre>
<code>
    jswrap::jswrap_ptr js = jswrap::jswrap_ptr(new jswrap());
    jsval rval;
    js->runfile("test.js", &#038;rval);
</code>
</pre>
</li>
<li>Wrapping member function calls is a matter of one line of code, and can happen right inside your JSFunctionSpec array (this example is taken from pgsqljs.cpp):
<pre><code>
    { "status", cmember0&lt;PGconn_wrap, int,
      &#038;PGconn_wrap::status&gt;().call,
      0, DEF_PROP_FLAGS, 0 },
    { "transaction_status", cmember0&lt;PGconn_wrap, int,
      &#038;PGconn_wrap::transaction_status&gt;().call,
      0, DEF_PROP_FLAGS, 0 },
    { "parameter_status", cmember1&lt;PGconn_wrap, const char *, const char *,
      &#038;PGconn_wrap::parameter_status&gt;().call,
      1, DEF_PROP_FLAGS, 0 },
</code></pre>
<p>Essentially, I am creating template-classes (I couldn&#8217;t figure out how to make this magic work with template-functions &#8212; help wanted!) for each member function.  The instantiated template class has one static function which knows how to marshall parameters and return values.  I also handles exceptions by propagating JS-exceptions as C++-exceptions, and vice versa.  This is a little hairy, but I think is an interesting approach.  It means no IDL and no external help (other than some rather egregious abuse of the C pre-processor, thanks largely to help from Boost.Preprocessor).  It also means you don&#8217;t have to maintain a separate call-through layer by hand.  Better still, this actually works for C++ member-functions of C++ objects, not only static member functions, so foo.bar() in C++ is still foo.bar() in JS.</li>
<li>It includes a sample embedding of the C PostgreSQL API, encapsulated in a C++ class.</li>
<li>It handles rooting for you (or at least, I think it does, I haven&#8217;t tested very carefully).</li>
<li>It provides an error-reporter and a stack-dumping facility, written in C++; both of which can be handy for debugging, or just as &#8220;recipes&#8221; for external projects.  Steal at will.</li>
<li>It&#8217;s amazingly terse, compared to the usual process for embedding spidermonkey.  I&#8217;d love to see it get even moreso, while retaining flexibility.</li>
</ul>
<p>It needs some cleanup and extension.  It could also benefit from some additional love in the template department.  I&#8217;d really like the member function spec lines to look like this, instead:</p>
<pre><code>    { "status", wrappedfunc&lt;&#038;PGconn_wrap::status&gt;, 0, DEF_PROP_FLAGS, 0 },
    { "transaction_status", wrappedfunc&lt;&#038;PGconn_wrap::transaction_status&gt;, 0, DEF_PROP_FLAGS, 0 },
    { "parameter_status", wrappedfunc&lt;&#038;PGconn_wrap::parameter_status&gt;(), 1, DEF_PROP_FLAGS, 0 },</code></pre>
<p>I&#8217;d really like to have a better story for properties (ie., data-members) of C++ objects.<br />
I&#8217;d really like to have an autoconf-based build environment that works with Mozilla-build (+boost?).<br />
I wrote a boost::asio wrapper.  It isn&#8217;t included here, but it would be neat to get it back on its feet and wrapped a little more cleanly than I had it before.<br />
It needs more testing and feedback (which is why I am releasing it.)</p>
<p><a href="http://people.mozilla.com/~bcrowder/wrapdemo.tar.gz">Here it is</a>.  I&#8217;m pretty sure you&#8217;ll need Boost 1.35 (at a minimum) to build it, and you&#8217;ll have to tweak the Jamfile and some other spots to suit your own directory structure (look for the string &#8220;crowder&#8221;) and file/library locations.  Feedback and patches are welcome and appreciated.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mozilla.com/bcrowder/2008/09/17/jswrap-c-love-for-spidermonkey/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>extend this!</title>
		<link>http://blog.mozilla.com/bcrowder/2008/07/18/extend-this/</link>
		<comments>http://blog.mozilla.com/bcrowder/2008/07/18/extend-this/#comments</comments>
		<pubDate>Sat, 19 Jul 2008 03:23:07 +0000</pubDate>
		<dc:creator>bcrowder</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://blog.mozilla.com/bcrowder/?p=18</guid>
		<description><![CDATA[I&#8217;ve been working on something fun for the last couple of days (in between patch-revs on other bugs I can&#8217;t talk about yet), and I thought I&#8217;d blog about it. It&#8217;s cool (at least to me) and useful: John Resig and others involved in the standardization process for the new ECMAScript language proposals have been [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=433351">been working on</a> something fun for the last couple of days (in between patch-revs on other bugs I can&#8217;t talk about yet), and I thought I&#8217;d blog about it.  It&#8217;s cool (at least to me) and useful:</p>
<p>John Resig and others involved in the standardization process for the new ECMAScript language proposals have been going back and forth lately over the design of a new language library feature, to facilitate copying properties of one object to another.  Object.extend() &#8212; essentially you pass an object (the one you mean to extend), and a series of objects (from which you want properties copied), and you get a new object with all the goodness of the others:</p>
<p>From the spidermonkey JS shell:<br />
<code>js&gt; var a = { get x () { print("foo"); return 3 } }<br />
js&gt; var b = [ 1, 2, 3 ]<br />
js&gt; var c = { foo: "bar" }<br />
js&gt; var result = Object.extend({}, a, b, c)<br />
js&gt; result.toSource()<br />
({get x () {print("foo");return 3;}, 0:1, 1:2, 2:3, foo:"bar"})</code><br />
Notice the getter itself is copied, not the result of its evaluation.</p>
<p>I hope this feature makes it into the standard(s), I think it&#8217;s a very powerful, useful, and flexible one.  So much so that many of the existing AJAX libraries already have a 5-or-10 line version of it included, under <a href="https://mail.mozilla.org/pipermail/es3.x-discuss/2008-July/000361.html">any of a number of names</a>, and with a few variations in semantics.  In my opinion, a number of the other features being discussed in lieu of it (like Object.clone) can be implemented trivially in terms of it).  A good, consistent semantic for a feature this convenient seems like a great thing for the &#8220;library&#8221; side of JS, to me.  I&#8217;d love to land this for 1.9.1, it seems like it would, at least, be handy for extension authors.  I hope it survives the committees!</p>
<p>Also, thanks to John for writing a nice test-suite for the feature.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mozilla.com/bcrowder/2008/07/18/extend-this/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>elinks</title>
		<link>http://blog.mozilla.com/bcrowder/2007/07/12/11/</link>
		<comments>http://blog.mozilla.com/bcrowder/2007/07/12/11/#comments</comments>
		<pubDate>Thu, 12 Jul 2007 22:45:43 +0000</pubDate>
		<dc:creator>bcrowder</dc:creator>
				<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://blog.mozilla.com/bcrowder/2007/07/12/11/</guid>
		<description><![CDATA[A text-mode browser that does JavaScript (using Spidermonkey)? Neat.]]></description>
			<content:encoded><![CDATA[<p>A text-mode browser that does JavaScript (using Spidermonkey)?  <a href="http://elinks.or.cz/">Neat</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mozilla.com/bcrowder/2007/07/12/11/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>checking my work</title>
		<link>http://blog.mozilla.com/bcrowder/2007/04/30/checking-my-work/</link>
		<comments>http://blog.mozilla.com/bcrowder/2007/04/30/checking-my-work/#comments</comments>
		<pubDate>Tue, 01 May 2007 00:18:45 +0000</pubDate>
		<dc:creator>bcrowder</dc:creator>
				<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://blog.mozilla.com/bcrowder/2007/04/30/checking-my-work/</guid>
		<description><![CDATA[So I have been using this little tool for a while to look at the output of &#8220;cvs diff -up8&#8243; as HTML before submitting patches to bugzilla. It seems to be working pretty well for me, so I thought I&#8217;d go ahead and make it more widely available. I would love to get feedback and/or [...]]]></description>
			<content:encoded><![CDATA[<p>So I have been using this little tool for a while to look at the output of &#8220;cvs diff -up8&#8243; as HTML before submitting patches to bugzilla.  It seems to be working pretty well for me, so I thought I&#8217;d go ahead and make it more widely available.  I would love to get feedback and/or patches for it.  I worked up some fixes today to make its output validate as XHTML 1.0 Strict.  Since I can&#8217;t upload anything but images, I&#8217;ve hosted it <a href="http://www.fiverocks.com/code/diff2html.pl">elsewhere</a>.  And yes, I realize it&#8217;s relatively ugly perl-code.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mozilla.com/bcrowder/2007/04/30/checking-my-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

