Regarding |evalGlobal|, when I talked about this with Mike Samuel from
the Google Caja team, he called it "Variable Laundering", drawing an
analogy to money laundering, where you make the source of money
untraceable. The idea is to muck up the scopes by introducing any
names into the evaled code's scope chain. By passing arguments into
evalGlobal variadically (through the arguments object), I don't
introduce a |willBeEvaledCode|, or simply |program|, variable into the
scope chain. This means that you're free to declare a global variable
with the same name and access it in any program run through
|evalGlobal|.
This the same reason for declaring |evalGlobal| in the arguments of
"module pattern" "enclosure". Since I declared the function in global
scope and passed it into the enclosure to be bound as the |evalGlobal|
argument variable, you are also free to declare an |evalGlobal|
function variable in global scope and use it in programs run through
<modules.js>'s |evalGlobal|.
As for returning the return value of |eval|, this allows the return
value of |evalGlobal| to mimic the specified return value of |eval|.
This is supposed to be the value of the last run statement in the
program. This feature is often used to insecurely but quickly parse
JSON from XHRs since it's a strict subset of JavaScript. I later use
|evalGlobal| in <json.js>.
Thanks for asking these questions; it's my pleasure to illuminate this
portion of the code.
Kris