Inheritance: JsDictionaryObject
Example #1
0
 public JsFunction()
 {
     Arguments = new List<string>();
     Statement = new EmptyStatement();
     Scope = new JsScope();
     DeclaringScopes = new List<JsDictionaryObject>();
 }
Example #2
0
 public JsFunction()
 {
     Arguments       = new List <string>();
     Statement       = new EmptyStatement();
     Scope           = new JsScope();
     DeclaringScopes = new List <JsDictionaryObject>();
 }
Example #3
0
        /// <summary>
        /// Creates a new scope inside the specified scope
        /// </summary>
        /// <param name="outer">Scope inside which the new scope should be created</param>
        public JsScope(JsScope outer)
            : base(outer) {
            if (outer == null)
                throw new ArgumentNullException("outer");

            globalScope = outer.Global;
        }
Example #4
0
 public JsScope(JsScope outer, JsDictionaryObject bag)
     : base(outer) {
     if (outer == null)
         throw new ArgumentNullException("outer");
     if (bag == null)
         throw new ArgumentNullException("bag");
     globalScope = outer.Global;
     this.bag = bag;
 }
Example #5
0
 public JsScope(JsScope outer)
     : base((JsDictionaryObject)outer)
 {
     if (outer == null)
     {
         throw new ArgumentNullException(nameof(outer));
     }
     this.globalScope = outer.Global;
 }
Example #6
0
        /// <summary>
        /// Creates a new scope inside the specified scope
        /// </summary>
        /// <param name="outer">Scope inside which the new scope should be created</param>
        public JsScope(JsScope outer)
            : base(outer)
        {
            if (outer == null)
            {
                throw new ArgumentNullException("outer");
            }

            globalScope = outer.Global;
        }
        public ExecutionVisitor(Options options) {
            typeResolver = CachedTypeResolver.Default;

            Global = new JsGlobal(this, options);
            GlobalScope = new JsScope(Global as JsObject);

            EnterScope(GlobalScope);

            CallStack = new Stack<string>();
        }
Example #8
0
 public JsScope(JsScope outer, JsDictionaryObject bag)
     : base(outer)
 {
     if (outer == null)
     {
         throw new ArgumentNullException("outer");
     }
     if (bag == null)
     {
         throw new ArgumentNullException("bag");
     }
     globalScope = outer.Global;
     this.bag    = bag;
 }
        public ExecutionVisitor(IGlobal GlobalObject, JsScope Scope) {
            if (GlobalObject == null)
                throw new ArgumentNullException("GlobalObject");
            if (Scope == null)
                throw new ArgumentNullException("Scope");

            typeResolver = CachedTypeResolver.Default;

            Global = GlobalObject;
            GlobalScope = Scope.Global;
            MaxRecursions = 500;

            EnterScope(Scope);
            CallStack = new Stack<string>();
        }
Example #10
0
 /// <summary>
 /// Creates a new Global scope
 /// </summary>
 public JsScope()
     : base(JsNull.Instance)
 {
     globalScope = null;
 }
Example #11
0
        public void ExecuteFunction(JsFunction function, JsDictionaryObject that, JsInstance[] parameters, Type[] genericParameters)
        {
            if (function == null) {
                return;
            }

            if (recursionLevel++ > MaxRecursions) {
                throw new JsException(Global.ErrorClass.New("Too many recursions in the script."));
            }

            // ecma chapter 10.
            // TODO: move creation of the activation object to the JsFunction
            // create new argument object and instantinate arguments into it
            JsArguments args = new JsArguments(Global, function, parameters);

            // create new activation object and copy instantinated arguments to it
            // Activation should be before the function.Scope hierarchy
            JsScope functionScope = new JsScope(function.Scope ?? GlobalScope);

            for (int i = 0; i < function.Arguments.Count; i++)
                if (i < parameters.Length)
                    functionScope.DefineOwnProperty(
                        new LinkedDescriptor(
                            functionScope,
                            function.Arguments[i],
                            args.GetDescriptor(i.ToString()),
                            args
                        )
                    );
                else
                    functionScope.DefineOwnProperty(
                        new ValueDescriptor(
                            functionScope,
                            function.Arguments[i],
                            JsUndefined.Instance
                        )
                    );

            // define arguments variable
            if (HasOption(Options.Strict))
                functionScope.DefineOwnProperty(JsScope.ARGUMENTS, args);
            else
                args.DefineOwnProperty(JsScope.ARGUMENTS, args);

            // set this variable
            if (that != null)
                functionScope.DefineOwnProperty(JsScope.THIS, that);
            else
                functionScope.DefineOwnProperty(JsScope.THIS, that = Global as JsObject);

            // enter activation object
            EnterScope(functionScope);

            try {
                PermissionSet.PermitOnly();

                if (genericParameters != null && genericParameters.Length > 0)
                    Result = function.Execute(this, that, parameters, genericParameters);
                else
                    Result = function.Execute(this, that, parameters);

                // Resets the return flag
                if (exit) {
                    exit = false;
                }
            }
            finally {
                // return to previous execution state
                ExitScope();

                CodeAccessPermission.RevertPermitOnly();
                recursionLevel--;
            }
        }
Example #12
0
 protected void EnterScope(JsScope scope)
 {
     Scopes.Push(scope);
 }
Example #13
0
        public void Visit(JsonExpression json)
        {
            JsObject instance = Global.ObjectClass.New();

            JsScope scope = new JsScope() { Prototype = CurrentScope };
            scope.DefineOwnProperty(JsInstance.THIS, instance);
            EnterScope(scope);
            try
            {
                foreach (var item in json.Values)
                {
                    item.Value.Accept(this);
                    instance.DefineOwnProperty(item.Key, Result);
                }
            }
            finally
            {
                ExitScope();
            }

            Result = instance;
        }
Example #14
0
        public void ExecuteFunction(JsFunction function, JsDictionaryObject that, JsInstance[] parameters)
        {
            if (function == null)
            {
                return;
            }

            JsScope functionScope = new JsScope();
            JsArguments args = new JsArguments(Global, function, parameters);
            functionScope.Prototype = args;
            if (HasOption(Options.Strict))
                functionScope.DefineOwnProperty(JsInstance.ARGUMENTS, args);
            else
                functionScope.Prototype.DefineOwnProperty(JsInstance.ARGUMENTS, args);

            if (that != null)
                functionScope.DefineOwnProperty(JsInstance.THIS, that);
            functionScope.Extensible = false;

            //for (int i = function.DeclaringScopes.Count - 1; i >= 0; i--)
            //{
            //    EnterScope(function.DeclaringScopes[i]);
            //}

            EnterScope(function);
            EnterScope(functionScope);

            try
            {
                PermissionSet.PermitOnly();

                Result = function.Execute(this, that, parameters);

                // Resets the return flag
                if (exit)
                {
                    exit = false;
                }
            }
            finally
            {
                ExitScope();
                ExitScope();
                CodeAccessPermission.RevertPermitOnly();
            }
        }
Example #15
0
 /// <summary>
 /// Creates a new Global scope
 /// </summary>
 public JsScope()
     : base(JsNull.Instance)
 {
     globalScope = null;
 }
Example #16
0
 public JsScope()
     : base((JsDictionaryObject)JsNull.Instance)
 {
     this.globalScope = (JsScope)null;
 }