<?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>mrbkap&#039;s blog</title>
	<atom:link href="http://blog.mozilla.com/mrbkap/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mozilla.com/mrbkap</link>
	<description>A blog about wrappers</description>
	<lastBuildDate>Sat, 15 Aug 2009 10:03:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Working on the JS engine</title>
		<link>http://blog.mozilla.com/mrbkap/2009/06/30/working-on-the-js-engine/</link>
		<comments>http://blog.mozilla.com/mrbkap/2009/06/30/working-on-the-js-engine/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 22:00:02 +0000</pubDate>
		<dc:creator>mrbkap</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.mozilla.com/mrbkap/2009/06/30/working-on-the-js-engine/</guid>
		<description><![CDATA[Especially working on old branches without some of the nice debugging helpers that jorendorff has implemented, sometimes I look at my gdb session and just know that I&#8217;m working on the JS engine:
(gdb) p $.atom
$11 = (JSAtom *) 0xb194f984
(gdb) p/x *(JSString *)((int)$ &#38; ~7)
$12 = {length = 0x20000004, u = {chars = 0xaf434970, base = [...]]]></description>
			<content:encoded><![CDATA[<p>Especially working on old branches without some of the nice debugging helpers that jorendorff has implemented, sometimes I look at my gdb session and just <em>know</em> that I&#8217;m working on the JS engine:</p>
<pre>(gdb) p $.atom
$11 = (JSAtom *) 0xb194f984
(gdb) p/x *(JSString *)((int)$ &amp; ~7)
$12 = {length = 0x20000004, u = {chars = 0xaf434970, base = 0xaf434970}}
(gdb) x/4ch $.u.chars
0xaf434970:	97 'a'	98 'b'	99 'c'	100 'd'</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.mozilla.com/mrbkap/2009/06/30/working-on-the-js-engine/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Proving Difficult Assertions?</title>
		<link>http://blog.mozilla.com/mrbkap/2009/05/15/proving-difficult-assertions/</link>
		<comments>http://blog.mozilla.com/mrbkap/2009/05/15/proving-difficult-assertions/#comments</comments>
		<pubDate>Fri, 15 May 2009 08:29:01 +0000</pubDate>
		<dc:creator>mrbkap</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.mozilla.com/mrbkap/?p=13</guid>
		<description><![CDATA[Several times over the past couple of weeks, I have wanted to make some sort of assertion about an invariant in Mozilla. Now, some invariants are easier to prove than others. For example, if I wanted to prove that a particular variable (such as nsHTMLDocument::mWriteState) only ever has one of four values, I can enlist [...]]]></description>
			<content:encoded><![CDATA[<p>Several times over the past couple of weeks, I have wanted to make some sort of assertion about an invariant in Mozilla. Now, some invariants are easier to prove than others. For example, if I wanted to prove that a particular variable (such as <code>nsHTMLDocument::mWriteState</code>) only ever has one of four values, I can enlist the C++ type system and an <code>enum</code> to help check and enforce that for me. To me, the important point is not <em>how</em> the invariant is proven, just that it is proven.</p>
<p>For a more difficult example, I might want to show that, in a web page&#8217;s &lt;script&gt; tags, all scripted functions are allowed to access their scope chains. This might seem like a vacuous invariant to prove, but given that whether we either do or don&#8217;t perform security checks depends on this invariant, it seems worth the exercise. However, if you get the point and don&#8217;t want to slog through a fairly involved example involving <a href="http://mxr.mozilla.org/mozilla-central/source/js/src/">JS</a> and <a href="http://mxr.mozilla.org/mozilla-central/source/caps/src/">caps</a> you might want to skip to the last paragraph for the punchline.</p>
<p>Unlike the first example, the C++ type system cannot help us here. Instead, we first make an assumption: any time we compile JS code, the principal we compile that code with is equal to the principal of the scope chain (you can check this assumption by reading <code>nsScriptLoader::EvaluateScript</code>). Now, we note that in <code>nsScriptSecurityManager</code>, to compute the privileges (<em>principals</em>) of a function, there are two cases: functions are either cloned (in which case they inherit the principal from their parent) or not (in which case, we use the principal of their script). So, we can say that our invariant holds true for any non-cloned function (thanks to our assumption earlier).</p>
<p>Now, what about cloned functions? Well, since we only care about functions in the &lt;script&gt; element, we only have to see how these functions are cloned. Scanning through <code><nobr>js/src/*.cpp</nobr></code> we can see that the parent argument to <code>js_CloneFunctionObject</code> is always <code>cx->fp->scopeChain</code>. Great! To finish, we go check what a scripted function&#8217;s scope chain is set to when it&#8217;s called. A quick glance at <code>jsinterp.cpp</code> verifies that the function&#8217;s parent is used as the scope chain, and we&#8217;re done. For extra credit (and to make this particular example useful) you can also prove that functions cloned by <code>jsinterp.cpp</code> keep the same principal (which, with what we&#8217;ve shown here, tells us that it&#8217;s OK to not do security checks when looking stuff up on the scope chain).</p>
<p>Whew, so that wasn&#8217;t so bad, right? (Hah!) I have the advantage of having worked on this code for the past 3 years, I made some gigantic assumptions (that I can back up) and was able to do most of that without cracking open my editor. Furthermore, I don&#8217;t think that it&#8217;s possible to usefully put that invariant (and <em>why</em> it&#8217;s true) into the source code, either as a comment or as part of the code. I say this because there are millions of these assertions, some that cross module boundaries, like this one, and some that only hold true for single functions. As a programmer working on this code, fixing bugs and adding features requires figuring out which invariants are being broken, or which ones I might affect by adding new code.</p>
<p>And finally, this brings me to my question. <strong>How can we write code that makes answering a question like &#8220;can a scripted function always access its scope chain?&#8221; easier</strong>? Is it more comments? Better variable names? I ask because these two examples were relatively easy compared to some of the invariants I&#8217;ve been dealing with lately, and when you&#8217;re writing code in C++ (and when that code implements a security system for a web platform) they don&#8217;t get less important.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mozilla.com/mrbkap/2009/05/15/proving-difficult-assertions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A brief history of XPConnect</title>
		<link>http://blog.mozilla.com/mrbkap/2009/04/23/a-brief-history-of-xpconnect/</link>
		<comments>http://blog.mozilla.com/mrbkap/2009/04/23/a-brief-history-of-xpconnect/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 00:02:52 +0000</pubDate>
		<dc:creator>mrbkap</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.mozilla.com/mrbkap/?p=6</guid>
		<description><![CDATA[XPConnect has been around since the beginning of Gecko. However, at the beginning, it was only the bridge between JavaScript chrome code (chrome code is the code running in the browser itself, as opposed to content, web page code). In those early days, XPConnect-using JavaScript code looked a lot different. Because XPConnect didn&#8217;t know about [...]]]></description>
			<content:encoded><![CDATA[<p>XPConnect has been around since the beginning of Gecko. However, at the beginning, it was only the bridge between JavaScript <q>chrome</q> code (chrome code is the code running in the browser itself, as opposed to content, <q>web page</q> code). In those early days, XPConnect-using JavaScript code looked a lot different. Because XPConnect didn&#8217;t know about <code>nsIClassInfo</code> properties had to be addressed through their interfaces. So instead of saying <code>docShell.QueryInterface(Ci.nsIWebNavigation).canGoBack</code> one might say <code>docShell.nsIWebNavigation.canGoBack</code>. Obviously, this wouldn&#8217;t work for web pages, so there had to be another solution.</p>
<p>That other solution was midl.exe. This was a Windows-only program that generated gobs and gobs of C++ glue to connect DOM-facing objects to JavaScript from the <abbr title="interface definition language">IDL</abbr>. The generated stub code was put in <code>dom/src/*</code> and weighed in at over a megabyte. Because midl only ran on Windows, every time a developer wanted to change an <abbr>IDL</abbr> file, he would have to find a developer who ran on Windows to generate new stubs for the affected interfaces before proceeding.</p>
<p>In 2001, John Bandhauer (jband) and <a href="http://blog.mozilla.com/jst/">Johnny Stenback (jst)</a> started working to teach XPConnect about <code>nsIClassInfo</code> and to replace the midl generated code by simply calling functions through <code>xptcall</code>. This resulted in a significant codesize reduction and allowed people to change idl files, even if they didn&#8217;t run Windows. Furthermore, in order to support some of the weirder aspects of the DOM (such as setting <code>window.location</code> changing the currently shown page) the <code>nsIXPCScriptable</code> interface was fleshed out, allowing any C++ code to interact nicely with JavaScript code, instead of just the DOM code. For example, the storage code in Gecko now provides a nice enumeration API for JS to use for-in loops to iterate over query results. Without the magic of <code>nsIXPCScriptable</code>, JS would be forced to use uglier function calls.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mozilla.com/mrbkap/2009/04/23/a-brief-history-of-xpconnect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello from the bowels of Gecko</title>
		<link>http://blog.mozilla.com/mrbkap/2009/04/03/hello-from-the-bowels-of-gecko/</link>
		<comments>http://blog.mozilla.com/mrbkap/2009/04/03/hello-from-the-bowels-of-gecko/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 20:43:25 +0000</pubDate>
		<dc:creator>mrbkap</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Hello and welcome to another blog about the deep innards of Gecko. I&#8217;m Blake (known to many as mrbkap, pronounced Mr. Bee Kap) and I&#8217;ve been down here for about three years now. I&#8217;m look forward to joining the blogging ranks and all of the fame and fortune that obviously follows.
What do I mean by [...]]]></description>
			<content:encoded><![CDATA[<p>Hello and welcome to another blog about the deep innards of Gecko. I&#8217;m Blake (known to many as mrbkap, pronounced Mr. Bee Kap) and I&#8217;ve been down here for about three years now. I&#8217;m look forward to joining the blogging ranks and all of the fame and fortune that obviously follows.</p>
<p>What do I mean by <q>bowels,</q> exactly? When I started contributing to Mozilla (not yet FIrefox!), I started hacking on the <a href="http://mxr.mozilla.org/mozilla-central/source/parser/htmlparser/src/">HTML parser</a> and in particular, fixing <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=57724"><q>view source</q></a> to property display the HTML source code of web pages. Now, I mostly leave that code alone and work on the <a href="https://developer.mozilla.org/En/SpiderMonkey">JavaScript Engine</a> and the <a href="https://developer.mozilla.org/en/XPConnect">bridge between JavaScript and C++.</a> My work in these areas has led me to work on security bugs, in particular <a href="http://en.wikipedia.org/wiki/Cross-site_scripting">XSS</a> and privilege escalation bugs. At times, I also like to jump in and fix the hot new <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=485217">security</a> <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=485286">bugs,</a> though I prefer doing so <em>before</em> they&#8217;re made public.</p>
<p>My work on XPConnect has given me an association with <a href="https://developer.mozilla.org/En/XPConnect_wrappers">wrappers,</a> which is a topic that I hope to expand on in this very blog. Being extremely new to blogging, I don&#8217;t know what to expect from this, but jumping feet first into the cloud the way I am makes me want to put on my rain jacket. Although, this being the internet, I suppose I&#8217;d really want my <em>flame</em> jacket.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mozilla.com/mrbkap/2009/04/03/hello-from-the-bowels-of-gecko/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
