10.4.3 Entering Function Code

2010-05-11

Code: (Meta Ecma)
function EnterFunctionCode(F, thisArg, argumentsList) {
var curCtx = global.arrExecutionContexts[global.arrExecutionContexts.length-1];
if (F.strict) curCtx.ThisBinding = thisBinding;
else if (thisArg === null || thisArg === undefined) curCtx.ThisBinding = global;
else if (typeof thisArg != 'object') curCtx.ThisBinding = ToObject(thisArg);
else curCtx.ThisBinding = thisArg;

var localEnv = NewDeclarativeEnvironment(F.[[Scope]]);
curCtx.LexicalEnvironment = localEnv;
curCtx.VariableEnvironment = localEnv;

var code = F.[[Code]];
DeclarationBindingInstantiation(code, argumentList);
return curCtx;
}


The context depends on strict mode and the value of the supplied thisValue. In strict mode it's always the thisValue, as supplied. This plugs a few implicit global scope holes. Otherwise if the thisValue is null or undefined, the thisValue becomes the global object. If the thisValue is not an object, it is casted to an object. The resulting thisValue is used.