Orel, I wanted to follow up on this, in case others find this mailing list and have similar questions:
When you declare `var x` outside of any functions, it's stored directly in the 'global' scope object, and thereby not serialized.
An easy workaround is to wrap your script in a function closure. Assuming your script is stored in a String called `script`, you can run
cx.executeScriptWithContinuations(cx.compileString("(function() { " + script + "})();", "my script", 1, null), globalScope)
I believe this behavior violates the expectations set in the API, so we could work towards improving it.