ToObject() public static method

public static ToObject ( Object value, VsaEngine engine ) : Object
value Object
engine Microsoft.JScript.Vsa.VsaEngine
return Object
Exemplo n.º 1
0
        internal override AST PartiallyEvaluate()
        {
            this.obj = this.obj.PartiallyEvaluate();
            WithObject wob;

            if (this.obj is ConstantWrapper)
            {
                Object ob = Convert.ToObject(this.obj.Evaluate(), this.Engine);
                wob = new WithObject(Globals.ScopeStack.Peek(), ob);
                if (ob is JSObject && ((JSObject)ob).noExpando)
                {
                    wob.isKnownAtCompileTime = true;
                }
            }
            else
            {
                wob = new WithObject(Globals.ScopeStack.Peek(), new JSObject(null, false));
            }
            Globals.ScopeStack.Push(wob);
            try{
                this.block = this.block.PartiallyEvaluate();
            }finally{
                Globals.ScopeStack.Pop();
            }
            return(this);
        }
Exemplo n.º 2
0
        internal override LateBinding EvaluateAsLateBinding()
        {
            LateBinding lb = this.lateBinding;

            if (lb == null)
            {
                if (this.member != null && !this.rootObjectInferredType.Equals(this.rootObject.InferType(null)))
                {
                    this.InvalidateBinding();
                }
                this.lateBinding = lb = new LateBinding(this.name, null, VsaEngine.executeForJSEE);
                lb.last_member   = this.member;
            }
            Object val = this.rootObject.Evaluate();

            try{
                lb.obj = val = Convert.ToObject(val, this.Engine);
                if (this.defaultMember == null && this.member != null)
                {
                    lb.last_object = val;
                }
            }catch (JScriptException e) {
                if (e.context == null)
                {
                    e.context = this.rootObject.context;
                }
                throw e;
            }
            return(lb);
        }
Exemplo n.º 3
0
        public static string toLocaleString(object thisObj)
        {
            // TODO: Shouldn't this be generic!?
            SemanticAnalyser.assert_type(thisObj, typeof(ArrayObject));
            ArrayObject array_obj = (ArrayObject)thisObj;

            string separator = CultureInfo.CurrentCulture.TextInfo.ListSeparator + " ";

            Hashtable     elems = array_obj.elems;
            uint          n     = (uint)array_obj.length;
            StringBuilder str   = new StringBuilder();
            bool          first = true;

            for (uint i = 0; i < n; i++)
            {
                ScriptObject elem = (ScriptObject)Convert.ToObject(elems [i], null);
                if (!first && elem != null)
                {
                    str.Append(separator);
                }
                first = false;
                if (elem != null)
                {
                    str.Append(Convert.ToString(elem.CallMethod("toLocaleString", new object [] { })));
                }
            }
            return(str.ToString());
        }
Exemplo n.º 4
0
        internal Object GetObject2()
        {
            Call c = this.expression as Call;

            if (c == null || !c.inBrackets)
            {
                return(Convert.ToObject(this.expression.Evaluate(), this.Engine));
            }
            else
            {
                return(Convert.ToObject(c.func.Evaluate(), this.Engine));
            }
        }
Exemplo n.º 5
0
        public static Object JScriptWith(Object withOb, VsaEngine engine)
        {
            Object ob = Convert.ToObject(withOb, engine);

            if (ob == null)
            {
                throw new JScriptException(JSError.ObjectExpected);
            }
            Globals glob = engine.Globals;

            glob.ScopeStack.GuardedPush(new WithObject(glob.ScopeStack.Peek(), ob));
            return(ob);
        }
Exemplo n.º 6
0
 // Push into a "with" scope and return the converted object.
 public static Object JScriptWith(Object withOb, VsaEngine engine)
 {
     withOb = Convert.ToObject(withOb, engine);
     if (withOb != null)
     {
         engine.PushScriptObjectChecked
             (new WithScope(engine.ScriptObjectStackTop(), withOb));
         return(withOb);
     }
     else
     {
         throw new JScriptException(JSError.ObjectExpected);
     }
 }
Exemplo n.º 7
0
 // Perform a constructor call on this object.
 internal override Object Construct(VsaEngine engine, Object[] args)
 {
     if (args.Length == 0)
     {
         return(ConstructNewObject(engine));
     }
     else if (args[0] == null || args[0] == DBNull.Value)
     {
         return(ConstructNewObject(engine));
     }
     else
     {
         return(Convert.ToObject(args[0], engine));
     }
 }
Exemplo n.º 8
0
        public static object CallValue(object thisObj, object val, object [] arguments,
                                       bool construct, bool brackets, VsaEngine engine)
        {
            if (construct)
            {
                if (brackets)
                {
                }

                if (val is Closure)
                {
                    return(((Closure)val).func.CreateInstance(arguments));
                }
                else if (val is FunctionObject)
                {
                    return(((FunctionObject)val).CreateInstance(arguments));
                }
            }
            else if (brackets)
            {
                object first_arg = arguments.Length > 0 ? arguments [0] : null;
                return(GetObjectProperty((ScriptObject)Convert.ToObject(val, engine), Convert.ToString(first_arg)));
            }
            else
            {
                if (val is Closure)
                {
                    return(((Closure)val).func.Invoke(thisObj, arguments));
                }
                else if (val is FunctionObject)
                {
                    return(((FunctionObject)val).Invoke(thisObj, arguments));
                }
                else if (val is RegExpObject)
                {
                    object first_arg = arguments.Length > 0 ? arguments [0] : null;
                    return(RegExpPrototype.exec(val, first_arg));
                }
                else
                {
                    return(null);
                }
            }

            Console.WriteLine("CallValue: construct = {0}, brackets = {1}, this = {2}, val = {3} ({4}), arg[0] = {5}",
                              construct, brackets, thisObj.GetType(), val, val.GetType(), arguments [0]);
            throw new NotImplementedException();
        }
Exemplo n.º 9
0
 public Object Invoke(params Object[] args)
 {
     if (args == null || args.Length == 0)
     {
         return(ConstructObject());
     }
     else
     {
         object arg = args [0];
         if (arg == null || arg == DBNull.Value)
         {
             return(ConstructObject());
         }
         else
         {
             return(Convert.ToObject(arg, null));
         }
     }
 }
Exemplo n.º 10
0
        public new Object CreateInstance(params object [] args)
        {
            if (args == null || args.Length == 0)
            {
                return(ConstructObject());
            }
            else
            {
                object value = args [0];

                if (value == null || value == DBNull.Value)
                {
                    return(ConstructObject());
                }
                else
                {
                    return(Convert.ToObject(value, null));
                }
            }
        }
Exemplo n.º 11
0
 protected override Object GetObject()
 {
     return(Convert.ToObject(this.rootObject.Evaluate(), this.Engine));
 }
Exemplo n.º 12
0
 public static Object JScriptWith(object withObj, VsaEngine engine)
 {
     engine.PushScriptObject((ScriptObject)Convert.ToObject(withObj, engine));
     return(withObj);
 }
Exemplo n.º 13
0
        internal static object [] assemble_args(object obj, bool has_engine, bool has_var_args, bool has_this,
                                                Type [] arg_types, object [] arguments, VsaEngine engine)
        {
            ArrayList arg_list     = new ArrayList(arguments);
            int       req_argc     = arg_types.Length;
            int       missing_args = req_argc - arg_list.Count;

            // Add missing args
            for (int i = 0; i < missing_args; i++)
            {
                arg_list.Add(null);
            }

            // Convert types of argument to match method signature if necessary
            for (int i = 0; i < req_argc; i++)
            {
                Type   arg_type = arg_types [i];
                object arg      = arg_list [i];
                if (!arg_type.IsInstanceOfType(arg))
                {
                    object new_arg = null;
                    if (arg_type == typeof(object))
                    {
                        if (arg != null && arg != DBNull.Value)
                        {
                            new_arg = Convert.ToObject(arg, engine);
                        }
                        else
                        {
                            new_arg = arg;
                        }
                    }
                    else if (arg_type == typeof(double))
                    {
                        new_arg = Convert.ToNumber(arg);
                    }
                    else if (arg_type == typeof(string))
                    {
                        new_arg = Convert.ToString(arg);
                    }
                    else
                    {
                        Console.WriteLine("assemble_args: Can not convert to type {0}", arg_type);
                        throw new NotImplementedException();
                    }

                    arg_list [i] = new_arg;
                }
            }

            if (!has_var_args)
            {
                // Remove unneeded args
                int added_args = -missing_args;

                /*if (added_args > 0)
                 *      Console.WriteLine ("warning JS1148: There are too many arguments. The extra arguments will be ignored");*/
                for (int i = 0; i < added_args; i++)
                {
                    arg_list.RemoveAt(arg_list.Count - 1);
                }
            }
            else
            {
                int va_idx = req_argc;
                if (!has_this)
                {
                    va_idx--;
                }
                int va_count = arg_list.Count - va_idx;

                object [] var_args = new object [va_count];

                int    j = va_idx;
                object arg;
                for (int i = 0; i < va_count; i++, j++)
                {
                    arg = arg_list [j];
                    if (arg != null)
                    {
                        var_args [i] = arg;
                    }
                }

                arg_list.RemoveRange(va_idx, va_count);
                arg_list.Add(var_args);
            }

            return(build_args(obj, arg_list.ToArray(), engine, has_engine, has_this));
        }