Example #1
0
        /// <exception cref="TjsException"></exception>
        /// <exception cref="VariantException"></exception>
        public void AddArrayElement(Variant val)
        {
            string ss_add = "add";

            Variant[] args = new Variant[1];
            args[0] = val;
            mVal.AsObjectClosure().FuncCall(0, ss_add, null, args, null);
        }
 /// <exception cref="TjsException"></exception>
 /// <exception cref="VariantException"></exception>
 protected internal static void GetPropertyDirect(Variant result, Variant target,
                                                  int member, Dispatch2 objthis, int flags)
 {
     if (target.IsObject())
     {
         VariantClosure clo  = target.AsObjectClosure();
         string         name = Sharpen.Extensions.ToString(member);
         int            hr   = clo.PropGet(flags, name, result, clo.mObjThis != null ? clo.mObjThis : objthis
                                           );
         if (hr < 0)
         {
             ThrowFrom_tjs_error(hr, name);
         }
     }
     else
     {
         if (target.IsString())
         {
             GetStringProperty(result, target, member);
         }
         else
         {
             if (target.IsOctet())
             {
                 GetOctetProperty(result, target, member);
             }
             else
             {
                 string mes = Error.VariantConvertErrorToObject.Replace("%1", Utils.VariantToReadableString
                                                                            (target));
                 throw new VariantException(mes);
             }
         }
     }
 }
 // setPropertyDirect( ra[ra_offset+ca[code+1]], da[ca[code+2]], ra[ra_offset+ca[code+3]], objthis, flags );
 // member は、固定值なので、事前に分岐判定出来るから、展开するようにした方がいいな
 /// <exception cref="TjsException"></exception>
 /// <exception cref="VariantException"></exception>
 protected internal static void SetPropertyDirect(Variant target, string member, Variant
                                                  param, Dispatch2 objthis, int flags)
 {
     if (target.IsObject())
     {
         VariantClosure clo = target.AsObjectClosure();
         int            hr  = clo.PropSet(flags, member, param, clo.mObjThis != null ? clo.mObjThis :
                                          objthis);
         if (hr < 0)
         {
             ThrowFrom_tjs_error(hr, member);
         }
     }
     else
     {
         if (target.IsString())
         {
             SetStringProperty(param, target, member);
         }
         else
         {
             if (target.IsOctet())
             {
                 SetOctetProperty(param, target, member);
             }
             else
             {
                 string mes = Error.VariantConvertErrorToObject.Replace("%1", Utils.VariantToReadableString
                                                                            (target));
                 throw new VariantException(mes);
             }
         }
     }
 }
        /// <exception cref="TjsException"></exception>
        /// <exception cref="VariantException"></exception>
        protected internal static void ThrowScriptException(Variant val, ScriptBlock block
                                                            , int srcpos)
        {
            string msg = null;

            if (val.IsObject())
            {
                VariantClosure clo = val.AsObjectClosure();
                if (clo.mObject != null)
                {
                    Variant v2           = new Variant();
                    string  message_name = "message";
                    int     hr           = clo.PropGet(0, message_name, v2, null);
                    if (hr >= 0)
                    {
                        msg = "script exception : " + v2.AsString();
                    }
                }
            }
            if (msg == null || msg.Length == 0)
            {
                msg = "script exception";
            }
            throw new TjsScriptException(msg, block, srcpos, val);
        }
Example #5
0
        /// <exception cref="VariantException"></exception>
        /// <exception cref="TjsException"></exception>
        public virtual void SaveStructuredData(AList <Dispatch2> stack, TextWriteStreamInterface
                                               stream, string indentstr)
        {
            stream.Write("(const) [\n");
            string indentstr2 = indentstr + " ";
            int    count      = mItems.Count;

            for (int i = 0; i < count; i++)
            {
                Variant v = mItems[i];
                stream.Write(indentstr2);
                if (v.IsObject())
                {
                    // object
                    VariantClosure clo = v.AsObjectClosure();
                    SaveStructuredDataForObject(clo.SelectObject(), stack, stream, indentstr2);
                }
                else
                {
                    stream.Write(Utils.VariantToExpressionString(v));
                }
                if (i != mItems.Count - 1)
                {
                    // unless last
                    stream.Write(",\n");
                }
                else
                {
                    stream.Write("\n");
                }
            }
            stream.Write(indentstr);
            stream.Write("]");
        }
 /// <exception cref="VariantException"></exception>
 /// <exception cref="TjsException"></exception>
 public virtual bool Callback(string name, int flags, Variant value)
 {
     if ((flags & Interface.HIDDENMEMBER) != 0)
     {
         return(true);
     }
     if (mCalled)
     {
         mStream.Write(",\n");
     }
     mCalled = true;
     mStream.Write(mIndentStr);
     mStream.Write("\"");
     mStream.Write(LexBase.EscapeC(name));
     mStream.Write("\" => ");
     if (value.IsObject())
     {
         // object
         VariantClosure clo = value.AsObjectClosure();
         ArrayNI.SaveStructuredDataForObject(clo.SelectObject(), mStack, mStream, mIndentStr
                                             );
     }
     else
     {
         mStream.Write(Utils.VariantToExpressionString(value));
     }
     return(true);
 }
 /// <exception cref="TjsException"></exception>
 /// <exception cref="VariantException"></exception>
 protected internal static void TypeOfMemberDirect(Variant result, Variant target,
                                                   string member, Dispatch2 objthis, int flags)
 {
     if (target.IsObject())
     {
         int            hr;
         VariantClosure clo = target.AsObjectClosure();
         hr = clo.PropGet(flags, member, result, clo.mObjThis != null ? clo.mObjThis : objthis
                          );
         if (hr == Error.S_OK)
         {
             TypeOf(result);
         }
         else
         {
             if (hr == Error.E_MEMBERNOTFOUND)
             {
                 result.Set("undefined");
             }
             else
             {
                 if (hr < 0)
                 {
                     ThrowFrom_tjs_error(hr, member);
                 }
             }
         }
     }
     else
     {
         if (target.IsString())
         {
             GetStringProperty(result, target, member);
             TypeOf(result);
         }
         else
         {
             if (target.IsOctet())
             {
                 GetOctetProperty(result, target, member);
                 TypeOf(result);
             }
             else
             {
                 string mes = Error.VariantConvertErrorToObject.Replace("%1", Utils.VariantToReadableString
                                                                            (target));
                 throw new VariantException(mes);
             }
         }
     }
 }
 // getPropertyIndirect( ra[ra_offset+ca[code+1]], ra[ra_offset+ca[code+2]], ra[ra_offset+ca[code+3]], objthis, flags );
 /// <exception cref="TjsException"></exception>
 /// <exception cref="VariantException"></exception>
 protected internal static void GetPropertyIndirect(Variant result, Variant target
                                                    , Variant member, Dispatch2 objthis, int flags)
 {
     if (target.IsObject())
     {
         VariantClosure clo = target.AsObjectClosure();
         if (member.IsInteger() != true)
         {
             string str = member.AsString();
             int    hr  = clo.PropGet(flags, str, result, clo.mObjThis != null ? clo.mObjThis : objthis
                                      );
             if (hr < 0)
             {
                 ThrowFrom_tjs_error(hr, str);
             }
         }
         else
         {
             int hr = clo.PropGetByNum(flags, member.AsInteger(), result, clo.mObjThis != null
                                          ? clo.mObjThis : objthis);
             if (hr < 0)
             {
                 ThrowFrom_tjs_error_num(hr, member.AsInteger());
             }
         }
     }
     else
     {
         if (target.IsString())
         {
             GetStringProperty(result, target, member);
         }
         else
         {
             if (target.IsOctet())
             {
                 GetOctetProperty(result, target, member);
             }
             else
             {
                 string mes = Error.VariantConvertErrorToObject.Replace("%1", Utils.VariantToReadableString
                                                                            (target));
                 throw new VariantException(mes);
             }
         }
     }
 }
Example #9
0
        /// <summary>TJSGetExceptionObject : retrieves TJS 'Exception' object</summary>
        /// <exception cref="TjsException">TJSException</exception>
        /// <exception cref="VariantException">VariantException</exception>
        /// <exception cref="VariantException"></exception>
        /// <exception cref="TjsException"></exception>
        public static void GetExceptionObject(Tjs tjs, Variant res, Variant msg, Variant
                                              trace)
        {
            if (res == null)
            {
                return;
            }
            // not prcess
            // retrieve class "Exception" from global
            Dispatch2 global = tjs.GetGlobal();
            Variant   val    = new Variant();
            int       hr     = global.PropGet(0, EXCEPTION_NAME, val, global);

            if (hr < 0)
            {
                throw new TjsException(ExceptionNotFound);
            }
            // create an Exception object
            Holder <Dispatch2> excpobj = new Holder <Dispatch2>(null);
            VariantClosure     clo     = val.AsObjectClosure();

            Variant[] pmsg = new Variant[1];
            pmsg[0] = msg;
            hr      = clo.CreateNew(0, null, excpobj, pmsg, clo.mObjThis);
            if (hr < 0)
            {
                throw new TjsException(ExceptionNotFound);
            }
            Dispatch2 disp = excpobj.mValue;

            if (trace != null)
            {
                string trace_name = "trace";
                disp.PropSet(Interface.MEMBERENSURE, trace_name, trace, disp);
            }
            res.Set(disp, disp);
            excpobj = null;
        }
        /// <exception cref="VariantException"></exception>
        public static object[] VariantArrayToJavaObjectArray(Variant[] @params, Type[] types)
        {
            if (types.Length == 0)
            {
                return(null);
            }
            // 元々引数不要
            if (@params.Length < types.Length)
            {
                return(null);
            }
            // パラメータが少ない
            int count = types.Length;

            object[] ret = new object[count];
            for (int i = 0; i < count; i++)
            {
                Type    type  = types[i];
                Variant param = @params[i];
                if (type.GetTypeInfo().IsPrimitive)
                {
                    // プリミティブタイプの场合
                    if (type == typeof(int))
                    {
                        ret[i] = Extensions.ValueOf(param.AsInteger());
                    }
                    else if (type == typeof(double))
                    {
                        ret[i] = (param.AsDouble());
                    }
                    else if (type == typeof(bool))
                    {
                        ret[i] = Extensions.ValueOf(param.AsInteger() != 0);
                    }
                    else if (type == typeof(float))
                    {
                        ret[i] = ((float)param.AsDouble());
                    }
                    else if (type == typeof(long))
                    {
                        ret[i] = Extensions.ValueOf(param.AsInteger());
                    }
                    else if (type == typeof(char))
                    {
                        ret[i] = ((char)param.AsInteger());
                    }
                    else if (type == typeof(byte))
                    {
                        ret[i] = (unchecked ((byte)param.AsInteger()));
                    }
                    else if (type == typeof(short))
                    {
                        ret[i] = ((short)param.AsInteger());
                    }
                    else
                    {
                        // may be Void.TYPE
                        ret[i] = null;
                    }
                }
                else if (type == typeof(string))
                {
                    ret[i] = param.AsString();
                }
                else if (type == typeof(ByteBuffer))
                {
                    ret[i] = param.AsOctet();
                }
                else if (type == typeof(Variant))
                {
                    ret[i] = param;
                }
                else if (type == typeof(VariantClosure))
                {
                    ret[i] = param.AsObjectClosure();
                }
                else if (type == typeof(Dispatch2))
                {
                    ret[i] = param.AsObject();
                }
                else if (type == param.ToJavaObject().GetType())
                {
                    ret[i] = param.ToJavaObject();
                }
                else
                {
                    // その他 のクラス
                    ret[i] = null;
                }
            }
            return(ret);
        }
 /// <exception cref="VariantException"></exception>
 public static object VariantToJavaObject(Variant param, Type type)
 {
     if (type.GetTypeInfo().IsPrimitive)
     {
         // プリミティブタイプの场合
         if (type == typeof(int))
         {
             return(Extensions.ValueOf(param.AsInteger()));
         }
         if (type == typeof(double))
         {
             return(param.AsDouble());
         }
         if (type == typeof(bool))
         {
             return(Extensions.ValueOf(param.AsInteger() != 0));
         }
         if (type == typeof(float))
         {
             return((float)param.AsDouble());
         }
         if (type == typeof(long))
         {
             return(Extensions.ValueOf(param.AsInteger()));
         }
         if (type == typeof(char))
         {
             return((char)param.AsInteger());
         }
         if (type == typeof(byte))
         {
             return(unchecked ((byte)param.AsInteger()));
         }
         if (type == typeof(short))
         {
             return((short)param.AsInteger());
         }
         // may be Void.TYPE
         return(null);
     }
     if (type == typeof(string))
     {
         return(param.AsString());
     }
     if (type == typeof(ByteBuffer))
     {
         return(param.AsOctet());
     }
     if (type == typeof(Variant))
     {
         return(param);
     }
     if (type == typeof(VariantClosure))
     {
         return(param.AsObjectClosure());
     }
     if (type == typeof(Dispatch2))
     {
         return(param.AsObject());
     }
     if (type == param.ToJavaObject().GetType())
     {
         return(param.ToJavaObject());
     }
     // その他 のクラス
     return(null);
 }
Example #12
0
        /// <exception cref="VariantException"></exception>
        public static string VariantToReadableString(Variant val, int maxlen)
        {
            string ret = null;

            if (val == null || val.IsVoid())
            {
                ret = "(void)";
            }
            else
            {
                if (val.IsInteger())
                {
                    ret = "(int)" + val.AsString();
                }
                else
                {
                    if (val.IsReal())
                    {
                        ret = "(real)" + val.AsString();
                    }
                    else
                    {
                        if (val.IsString())
                        {
                            ret = "(string)\"" + LexBase.EscapeC(val.AsString()) + "\"";
                        }
                        else
                        {
                            if (val.IsOctet())
                            {
                                ret = "(octet)<% " + Variant.OctetToListString(val.AsOctet()) + " %>";
                            }
                            else
                            {
                                if (val.IsObject())
                                {
                                    VariantClosure c   = (VariantClosure)val.AsObjectClosure();
                                    StringBuilder  str = new StringBuilder(128);
                                    str.Append("(object)");
                                    str.Append('(');
                                    if (c.mObject != null)
                                    {
                                        str.Append('[');
                                        if (c.mObject is NativeClass)
                                        {
                                            str.Append(((NativeClass)c.mObject).GetClassName());
                                        }
                                        else
                                        {
                                            if (c.mObject is InterCodeObject)
                                            {
                                                str.Append(((InterCodeObject)c.mObject).GetName());
                                            }
                                            else
                                            {
                                                if (c.mObject is CustomObject)
                                                {
                                                    string name = ((CustomObject)c.mObject).GetClassNames();
                                                    if (name != null)
                                                    {
                                                        str.Append(name);
                                                    }
                                                    else
                                                    {
                                                        str.Append(c.mObject.GetType().FullName);
                                                    }
                                                }
                                                else
                                                {
                                                    str.Append(c.mObject.GetType().FullName);
                                                }
                                            }
                                        }
                                        str.Append(']');
                                    }
                                    else
                                    {
                                        str.Append("0x00000000");
                                    }
                                    if (c.mObjThis != null)
                                    {
                                        str.Append('[');
                                        if (c.mObjThis is NativeClass)
                                        {
                                            str.Append(((NativeClass)c.mObjThis).GetClassName());
                                        }
                                        else
                                        {
                                            if (c.mObjThis is InterCodeObject)
                                            {
                                                str.Append(((InterCodeObject)c.mObjThis).GetName());
                                            }
                                            else
                                            {
                                                if (c.mObjThis is CustomObject)
                                                {
                                                    string name = ((CustomObject)c.mObjThis).GetClassNames();
                                                    if (name != null)
                                                    {
                                                        str.Append(name);
                                                    }
                                                    else
                                                    {
                                                        str.Append(c.mObjThis.GetType().FullName);
                                                    }
                                                }
                                                else
                                                {
                                                    str.Append(c.mObjThis.GetType().FullName);
                                                }
                                            }
                                        }
                                        str.Append(']');
                                    }
                                    else
                                    {
                                        str.Append(":0x00000000");
                                    }
                                    str.Append(')');
                                    ret = str.ToString();
                                }
                                else
                                {
                                    // native object ?
                                    ret = "(octet) [" + val.GetType().FullName + "]";
                                }
                            }
                        }
                    }
                }
            }
            if (ret != null)
            {
                if (ret.Length > maxlen)
                {
                    return(Sharpen.Runtime.Substring(ret, 0, maxlen));
                }
                else
                {
                    return(ret);
                }
            }
            return(string.Empty);
        }