Ejemplo n.º 1
0
        internal override AST PartiallyEvaluate()
        {
            VsaEngine    engine = this.Engine;
            ScriptObject scope  = Globals.ScopeStack.Peek();

            if (engine.doFast)
            {
                engine.PushScriptObject(new BlockScope(scope));
            }
            else
            {
                while (scope is WithObject || scope is BlockScope)
                {
                    if (scope is BlockScope)
                    {
                        ((BlockScope)scope).isKnownAtCompileTime = false;
                    }
                    scope = scope.GetParent();
                }
            }
            try{
                this.operand = this.operand.PartiallyEvaluate();
                if (this.enclosingFunctionScope != null && this.enclosingFunctionScope.owner == null)
                {
                    this.context.HandleError(JSError.NotYetImplemented);
                }
                return(this);
            }finally{
                if (engine.doFast)
                {
                    this.Engine.PopScriptObject();
                }
            }
        }
        internal ScriptFunction Construct(Object[] args, VsaEngine engine)
        {
            StringBuilder func_string = new StringBuilder("function anonymous(");

            for (int i = 0, n = args.Length - 2; i < n; i++)
            {
                func_string.Append(Convert.ToString(args[i]));
                func_string.Append(", ");
            }
            if (args.Length > 1)
            {
                func_string.Append(Convert.ToString(args[args.Length - 2]));
            }
            func_string.Append(") {\n");
            if (args.Length > 0)
            {
                func_string.Append(Convert.ToString(args[args.Length - 1]));
            }
            func_string.Append("\n}");
            Context  context = new Context(new DocumentContext("anonymous", engine), func_string.ToString());
            JSParser p       = new JSParser(context);

            engine.PushScriptObject(((IActivationObject)engine.ScriptObjectStackTop()).GetGlobalScope());
            try{
                return((ScriptFunction)p.ParseFunctionExpression().PartiallyEvaluate().Evaluate());
            }finally{
                engine.PopScriptObject();
            }
        }
Ejemplo n.º 3
0
        internal override AST PartiallyEvaluate()
        {
            VsaEngine    engine = this.Engine;
            ScriptObject scope  = Globals.ScopeStack.Peek();

            ClassScope cscope = ClassScope.ScopeOfClassMemberInitializer(scope);

            if (null != cscope)
            {
                if (cscope.inStaticInitializerCode)
                {
                    cscope.staticInitializerUsesEval = true;
                }
                else
                {
                    cscope.instanceInitializerUsesEval = true;
                }
            }

            if (engine.doFast)
            {
                engine.PushScriptObject(new BlockScope(scope));
            }
            else
            {
                while (scope is WithObject || scope is BlockScope)
                {
                    if (scope is BlockScope)
                    {
                        ((BlockScope)scope).isKnownAtCompileTime = false;
                    }
                    scope = scope.GetParent();
                }
            }
            try
            {
                this.operand = this.operand.PartiallyEvaluate();
                if (this.unsafeOption != null)
                {
                    this.unsafeOption = this.unsafeOption.PartiallyEvaluate();
                }
                if (this.enclosingFunctionScope != null && this.enclosingFunctionScope.owner == null)
                {
                    this.context.HandleError(JSError.NotYetImplemented);
                }
                return(this);
            }
            finally
            {
                if (engine.doFast)
                {
                    this.Engine.PopScriptObject();
                }
            }
        }
Ejemplo n.º 4
0
        internal override AST PartiallyEvaluate()
        {
            AST          ast;
            VsaEngine    engine = base.Engine;
            ScriptObject parent = base.Globals.ScopeStack.Peek();
            ClassScope   scope  = ClassScope.ScopeOfClassMemberInitializer(parent);

            if (scope != null)
            {
                if (scope.inStaticInitializerCode)
                {
                    scope.staticInitializerUsesEval = true;
                }
                else
                {
                    scope.instanceInitializerUsesEval = true;
                }
            }
            if (!engine.doFast)
            {
                while ((parent is WithObject) || (parent is BlockScope))
                {
                    if (parent is BlockScope)
                    {
                        ((BlockScope)parent).isKnownAtCompileTime = false;
                    }
                    parent = parent.GetParent();
                }
            }
            else
            {
                engine.PushScriptObject(new BlockScope(parent));
            }
            try
            {
                this.operand = this.operand.PartiallyEvaluate();
                if (this.unsafeOption != null)
                {
                    this.unsafeOption = this.unsafeOption.PartiallyEvaluate();
                }
                if ((this.enclosingFunctionScope != null) && (this.enclosingFunctionScope.owner == null))
                {
                    base.context.HandleError(JSError.NotYetImplemented);
                }
                ast = this;
            }
            finally
            {
                if (engine.doFast)
                {
                    base.Engine.PopScriptObject();
                }
            }
            return(ast);
        }
Ejemplo n.º 5
0
 private static Object DoEvaluate(Object source, VsaEngine engine, bool isUnsafe)
 {
     if (engine.doFast)
     {
         engine.PushScriptObject(new BlockScope(engine.ScriptObjectStackTop()));
     }
     try{
         Context  context = new Context(new DocumentContext("eval code", engine), ((IConvertible)source).ToString());
         JSParser p       = new JSParser(context);
         if (!isUnsafe)
         {
             new SecurityPermission(SecurityPermissionFlag.Execution).PermitOnly();
         }
         return(((Completion)p.ParseEvalBody().PartiallyEvaluate().Evaluate()).value);
     }finally{
         if (engine.doFast)
         {
             engine.PopScriptObject();
         }
     }
 }
Ejemplo n.º 6
0
 public static Object JScriptEvaluate(Object source, VsaEngine engine)
 {
     if (Convert.GetTypeCode(source) != TypeCode.String)
     {
         return(source);
     }
     if (engine.doFast)
     {
         engine.PushScriptObject(new BlockScope(engine.ScriptObjectStackTop()));
     }
     try{
         Context  context = new Context(new DocumentContext("eval code", engine), ((IConvertible)source).ToString());
         JSParser p       = new JSParser(context);
         return(((Completion)p.ParseEvalBody().PartiallyEvaluate().Evaluate()).value);
     }finally{
         if (engine.doFast)
         {
             engine.PopScriptObject();
         }
     }
 }
Ejemplo n.º 7
0
        private static object DoEvaluate(object source, VsaEngine engine, bool isUnsafe)
        {
            object obj2;

            if (engine.doFast)
            {
                engine.PushScriptObject(new BlockScope(engine.ScriptObjectStackTop()));
            }
            try
            {
                Context  context = new Context(new DocumentContext("eval code", engine), ((IConvertible)source).ToString());
                JSParser parser  = new JSParser(context);
                obj2 = ((Completion)parser.ParseEvalBody().PartiallyEvaluate().Evaluate()).value;
            }
            finally
            {
                if (engine.doFast)
                {
                    engine.PopScriptObject();
                }
            }
            return(obj2);
        }
        internal ScriptFunction Construct(object[] args, VsaEngine engine)
        {
            ScriptFunction function;
            StringBuilder  builder = new StringBuilder("function anonymous(");
            int            index   = 0;
            int            num2    = args.Length - 2;

            while (index < num2)
            {
                builder.Append(Microsoft.JScript.Convert.ToString(args[index]));
                builder.Append(", ");
                index++;
            }
            if (args.Length > 1)
            {
                builder.Append(Microsoft.JScript.Convert.ToString(args[args.Length - 2]));
            }
            builder.Append(") {\n");
            if (args.Length > 0)
            {
                builder.Append(Microsoft.JScript.Convert.ToString(args[args.Length - 1]));
            }
            builder.Append("\n}");
            Context  context = new Context(new DocumentContext("anonymous", engine), builder.ToString());
            JSParser parser  = new JSParser(context);

            engine.PushScriptObject(((IActivationObject)engine.ScriptObjectStackTop()).GetGlobalScope());
            try
            {
                function = (ScriptFunction)parser.ParseFunctionExpression().PartiallyEvaluate().Evaluate();
            }
            finally
            {
                engine.PopScriptObject();
            }
            return(function);
        }
Ejemplo n.º 9
0
        public Object CreateInstance(params Object [] args)
        {
            Type t = this.GetType();

            // Built-in constructor?
            if (t != typeof(FunctionObject))
            {
                MethodInfo method = t.GetMethod("CreateInstance");
                return(method.Invoke(this, new object [] { args }));
            }

            Type prototype = SemanticAnalyser.map_to_prototype(this.prototype);

            MemberInfo []  members = prototype.GetMember("constructor");
            PropertyInfo   field   = members [0] as PropertyInfo;
            ScriptFunction ctr     = field.GetValue(prototype, null) as ScriptFunction;

            if (ctr == null)
            {
                Console.WriteLine("No constructor for {0}", this);
            }
            ScriptObject new_obj = ctr.CreateInstance(args) as ScriptObject;

            new_obj._proto = this.prototype;

            vsa_engine.PushScriptObject(new_obj);
            Invoke(new_obj, args);
            //
            // NOTE: I think the result of calling an user function as a constructor
            // should not be the return value of the user function. I think it should
            // always be the newly constructed object.
            //
            // TODO: This has yet to be verified.
            //
            return(vsa_engine.PopScriptObject());
        }
Ejemplo n.º 10
0
        // Evaluate a JScript expression in the context of a specific engine.
        public static Object JScriptEvaluate(Object source, VsaEngine engine)
        {
            Object value = null;

            // Bail out if we weren't supplied a string.
            if (!(source is String))
            {
                return(source);
            }

            // Parse the "eval" statement.
            Context context = new Context((String)source);

            context.codebase = new CodeBase("eval code", null);
            JSParser parser = new JSParser(context);
            JNode    node   = parser.ParseSource(true);

            // Push a scope for use during evaluation.
            engine.PushScriptObject
                (new BlockScope(engine.ScriptObjectStackTop(),
                                new JSObject(null, engine)));

            // Evaluate the statement.
            try
            {
                value = node.Eval(engine);
                if (value == Empty.Value)
                {
                    value = null;
                }
            }
            catch (JScriptException e)
            {
                // Attach the context information to low-level exceptions.
                if (e.context == null)
                {
                    e.context = context;
                }
                throw;
            }
            catch (BreakJumpOut brk)
            {
                // "break" used incorrectly.
                throw new JScriptException(JSError.BadBreak, brk.context);
            }
            catch (ContinueJumpOut cont)
            {
                // "continue" used incorrectly.
                throw new JScriptException(JSError.BadContinue,
                                           cont.context);
            }
            catch (ReturnJumpOut ret)
            {
                // "return" used incorrectly.
                throw new JScriptException(JSError.BadReturn, ret.context);
            }
            finally
            {
                // Pop the script scope.
                engine.PopScriptObject();
            }

            // Return the result of the evaluation to the caller.
            return(value);
        }
Ejemplo n.º 11
0
 public static void PushHandlerScope(VsaEngine engine, string id, int scopeId)
 {
     engine.PushScriptObject(new BlockScope(engine.ScriptObjectStackTop(), id, scopeId));
 }
Ejemplo n.º 12
0
 public static Object JScriptWith(object withObj, VsaEngine engine)
 {
     engine.PushScriptObject((ScriptObject)Convert.ToObject(withObj, engine));
     return(withObj);
 }