public IDynamic Execute(ExecutableCode executableCode) { _stopWatch.Restart(); using (var context = EnterContext()) { context.ThisBinding = GlobalObject; context.VariableEnviroment = GlobalEnvironment; context.LexicalEnviroment = GlobalEnvironment; context.Strict = executableCode.Strict; BindFunctionDeclarations(executableCode.FunctionDeclarations, executableCode.Strict, true); BindVariableDeclarations(executableCode.VariableDeclarations, executableCode.Strict, true); var result = executableCode.Code(this, EmptyArgs); Output.Write("Execution Time: " + _stopWatch.Elapsed); return(result); } }
public virtual IDynamic Call(IEnvironment environment, IDynamic thisBinding, IArgs args) { var oldContext = environment.Context; var newEnvironment = Scope.NewDeclarativeEnvironment(); using (var newContext = environment.EnterContext()) { newContext.LexicalEnviroment = newEnvironment; newContext.VariableEnviroment = newEnvironment; newContext.Strict = ExecutableCode.Strict; if (ExecutableCode.Strict) { newContext.ThisBinding = thisBinding; } else { switch (thisBinding.TypeCode) { case LanguageTypeCode.Undefined: case LanguageTypeCode.Null: newContext.ThisBinding = Environment.GlobalObject; break; default: newContext.ThisBinding = thisBinding.ConvertToObject(); break; } } BindFormalParameters(args); Environment.BindFunctionDeclarations(ExecutableCode.FunctionDeclarations, ExecutableCode.Strict, true); BindArgumentsObject(args); Environment.BindVariableDeclarations(ExecutableCode.VariableDeclarations, ExecutableCode.Strict, true); return(ExecutableCode.Code(environment, args)); } }