Пример #1
0
 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;
     }
 }
Пример #2
0
 public FunctionDeclaration(string identifier, ReadOnlyList<string> formalParameterList, ExecutableCode executableCode)
 {
     Identifier = identifier;
     FormalParameterList = formalParameterList;
     ExecutableCode = executableCode;
 }
Пример #3
0
        public IObject CreateFunction(ExecutableCode executableCode, ReadOnlyList<string> formalParameters, ILexicalEnvironment scope)
        {
            // 13.2 Creating Function Objects

            var f = new NFunction(this);
            {
                f.Class = "Function";
                f.Extensible = true;
                f.Prototype = FunctionPrototype;
                f.ExecutableCode = executableCode;
                f.FormalParameters = formalParameters;
                f.Scope = scope;

                f.DefineOwnProperty("length", CreateDataDescriptor(CreateNumber(f.FormalParameters.Count), false, false ,false), false);
                f.DefineOwnProperty("constructor", CreateDataDescriptor(f, true, false, true), false);
                f.DefineOwnProperty("prototype", CreateDataDescriptor(ObjectConstructor.Op_Construct(EmptyArgs), true, false, false), false);

                if (executableCode.Strict)
                {
                    var desc = CreateAccessorDescriptor(ThrowTypeErrorFunction, ThrowTypeErrorFunction, false, false);
                    f.DefineOwnProperty("caller", desc, false);
                    f.DefineOwnProperty("arguments", desc, false);
                }
            }
            return f;
        }
Пример #4
0
 public FunctionDeclaration(string identifier, ReadOnlyList <string> formalParameterList, ExecutableCode executableCode)
 {
     Identifier          = identifier;
     FormalParameterList = formalParameterList;
     ExecutableCode      = executableCode;
 }