AsObjectClosure() public méthode

public AsObjectClosure ( ) : VariantClosure
Résultat VariantClosure
Exemple #1
0
 // オリジナルでは、强制的に int で返す(アドレスになるかもしれない)もののようだが……
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 private static int TryFuncCallViaPropGet(VariantClosure tvclosure, int flag, Variant
     result, Variant[] param, Dispatch2 objthis)
 {
     // retry using PropGet
     Variant tmp = new Variant();
     Dispatch2 disp = tvclosure.mObjThis != null ? tvclosure.mObjThis : objthis;
     int er = tvclosure.mObject.PropGet(0, null, tmp, disp);
     if (er >= 0)
     {
         tvclosure = tmp.AsObjectClosure();
         disp = tvclosure.mObjThis != null ? tvclosure.mObjThis : objthis;
         er = tvclosure.mObject.FuncCall(flag, null, result, param, disp);
     }
     return er;
 }
Exemple #2
0
        // class instance matching returns false or true
        /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
        /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
        public override int IsInstanceOf(int flag, string membername, string classname, Dispatch2
            objthis)
        {
            if (!GetValidity())
            {
                return Error.E_INVALIDOBJECT;
            }
            if (membername == null)
            {
                switch (mContextType)
                {
                    case ContextType.TOP_LEVEL:
                    case ContextType.PROPERTY_SETTER:
                    case ContextType.PROPERTY_GETTER:
                    case ContextType.SUPER_CLASS_GETTER:
                    {
                        break;
                    }

                    case ContextType.FUNCTION:
                    case ContextType.EXPR_FUNCTION:
                    {
                        if ("Function".Equals(classname))
                        {
                            return Error.S_TRUE;
                        }
                        break;
                    }

                    case ContextType.PROPERTY:
                    {
                        if ("Property".Equals(classname))
                        {
                            return Error.S_TRUE;
                        }
                        break;
                    }

                    case ContextType.CLASS:
                    {
                        if ("Class".Equals(classname))
                        {
                            return Error.S_TRUE;
                        }
                        break;
                    }
                }
            }
            int hr = base.IsInstanceOf(flag, membername, classname, objthis);
            if (membername != null && hr == Error.E_MEMBERNOTFOUND && mContextType == ContextType
                .CLASS && mSuperClassGetter != null)
            {
                // look up super class
                int[] pointer = mSuperClassGetter.mSuperClassGetterPointer;
                int count = pointer.Length;
                if (count != 0)
                {
                    Variant res = new Variant();
                    for (int i = count - 1; i >= 0; i--)
                    {
                        mSuperClassGetter.ExecuteAsFunction(null, null, res, pointer[i]);
                        VariantClosure clo = res.AsObjectClosure();
                        hr = clo.IsInstanceOf(flag, membername, classname, objthis);
                        if (hr != Error.E_MEMBERNOTFOUND)
                        {
                            break;
                        }
                    }
                }
            }
            return hr;
        }
Exemple #3
0
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 protected internal static int DefaultPropSet(int flag, Variant targ, Variant param
     , Dispatch2 objthis)
 {
     if ((flag & Interface.IGNOREPROP) == 0)
     {
         if (targ.IsObject())
         {
             // roughly the same as TJSDefaultPropGet
             VariantClosure tvclosure = targ.AsObjectClosure();
             int hr = Error.E_NOTIMPL;
             if (tvclosure.mObject != null)
             {
                 Dispatch2 disp = tvclosure.mObjThis != null ? tvclosure.mObjThis : objthis;
                 hr = tvclosure.mObject.PropSet(0, null, param, disp);
             }
             if (hr >= 0)
             {
                 return hr;
             }
             if (hr != Error.E_NOTIMPL && hr != Error.E_INVALIDTYPE && hr != Error.E_INVALIDOBJECT)
             {
                 return hr;
             }
         }
     }
     // normal substitution
     if (param == null)
     {
         return Error.E_INVALIDPARAM;
     }
     targ.CopyRef(param);
     return Error.S_OK;
 }
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 protected internal static void SetPropertyIndirect(Variant target, Variant member
     , Variant param, Dispatch2 objthis, int flags)
 {
     if (target.IsObject())
     {
         VariantClosure clo = target.AsObjectClosure();
         if (member.IsInteger() != true)
         {
             string str = member.AsString();
             int hr = clo.PropSet(flags, str, param, clo.mObjThis != null ? clo.mObjThis : objthis
                 );
             if (hr < 0)
             {
                 ThrowFrom_tjs_error(hr, str);
             }
         }
         else
         {
             int hr = clo.PropSetByNum(flags, member.AsInteger(), param, clo.mObjThis != null ?
                 clo.mObjThis : objthis);
             if (hr < 0)
             {
                 ThrowFrom_tjs_error_num(hr, member.AsInteger());
             }
         }
     }
     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="Kirikiri.Tjs2.TJSException"></exception>
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 protected internal static void TypeOfMemberDirect(Variant result, Variant target, 
     int member, Dispatch2 objthis, int flags)
 {
     if (target.IsObject())
     {
         int hr;
         VariantClosure clo = target.AsObjectClosure();
         string name = Sharpen.Extensions.ToString(member);
         hr = clo.PropGet(flags, name, 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, name);
                 }
             }
         }
     }
     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);
             }
         }
     }
 }
Exemple #6
0
 /// <summary>TJSGetExceptionObject : retrieves TJS 'Exception' object</summary>
 /// <exception cref="TJSException">TJSException</exception>
 /// <exception cref="VariantException">VariantException</exception>
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.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;
 }
 //getPropertyDirect( ra[ra_offset+ca[code+1]], ra[ra_offset+ca[code+2]], da[ca[code+3]], objthis, flags );
 // member は、固定值なので、事前に条件分岐できる、文字か数值で割り分け
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 protected internal static void GetPropertyDirect(Variant result, Variant target, 
     string member, Dispatch2 objthis, int flags)
 {
     if (target.IsObject())
     {
         VariantClosure clo = target.AsObjectClosure();
         int hr = clo.PropGet(flags, member, result, clo.mObjThis != null ? clo.mObjThis :
             objthis);
         if (hr < 0)
         {
             ThrowFrom_tjs_error(hr, member);
         }
     }
     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);
             }
         }
     }
 }
Exemple #8
0
 // get member count
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 public override int GetCount(IntWrapper result, string membername, Dispatch2 objthis
     )
 {
     int hr = base.GetCount(result, membername, objthis);
     if (membername != null && hr == Error.E_MEMBERNOTFOUND && mContextType == ContextType
         .CLASS && mSuperClassGetter != null)
     {
         // look up super class
         int[] pointer = mSuperClassGetter.mSuperClassGetterPointer;
         int count = pointer.Length;
         if (count != 0)
         {
             Variant res = new Variant();
             for (int i = count - 1; i >= 0; i--)
             {
                 mSuperClassGetter.ExecuteAsFunction(null, null, res, pointer[i]);
                 VariantClosure clo = res.AsObjectClosure();
                 hr = clo.GetCount(result, membername, objthis);
                 if (hr != Error.E_MEMBERNOTFOUND)
                 {
                     break;
                 }
             }
         }
     }
     return hr;
 }
Exemple #9
0
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 protected internal static int DefaultCreateNew(int flag, Variant targ, Holder<Dispatch2
     > result, Variant[] param, Dispatch2 objthis)
 {
     if (targ.IsObject())
     {
         VariantClosure tvclosure = targ.AsObjectClosure();
         if (tvclosure.mObject != null)
         {
             // bypass
             Dispatch2 disp = tvclosure.mObjThis != null ? tvclosure.mObjThis : objthis;
             return tvclosure.mObject.CreateNew(flag, null, result, param, disp);
         }
     }
     return Error.E_INVALIDTYPE;
 }
Exemple #10
0
 // create new object
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 public override int CreateNew(int flag, string membername, Holder<Dispatch2> result
     , Variant[] param, Dispatch2 objthis)
 {
     if (!GetValidity())
     {
         return Error.E_INVALIDOBJECT;
     }
     if (membername == null)
     {
         if (mContextType != ContextType.CLASS)
         {
             return Error.E_INVALIDTYPE;
         }
         Dispatch2 dsp = new CustomObject();
         ExecuteAsFunction(dsp, null, null, 0);
         FuncCall(0, mName, null, param, dsp);
         result.Set(dsp);
         return Error.S_OK;
     }
     int hr = base.CreateNew(flag, membername, result, param, objthis);
     if (membername != null && hr == Error.E_MEMBERNOTFOUND && mContextType == ContextType
         .CLASS && mSuperClassGetter != null)
     {
         // look up super class
         int[] pointer = mSuperClassGetter.mSuperClassGetterPointer;
         int count = pointer.Length;
         if (count != 0)
         {
             Variant res = new Variant();
             for (int i = count - 1; i >= 0; i--)
             {
                 mSuperClassGetter.ExecuteAsFunction(null, null, res, pointer[i]);
                 VariantClosure clo = res.AsObjectClosure();
                 hr = clo.CreateNew(flag, membername, result, param, objthis);
                 if (hr != Error.E_MEMBERNOTFOUND)
                 {
                     break;
                 }
             }
         }
     }
     return hr;
 }
Exemple #11
0
        // Dispatch2 implementation
        // function invocation
        /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
        /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
        public override int FuncCall(int flag, string membername, Variant result, Variant
            [] param, Dispatch2 objthis)
        {
            if (!GetValidity())
            {
                return Error.E_INVALIDOBJECT;
            }
            if (membername == null)
            {
                switch (mContextType)
                {
                    case ContextType.TOP_LEVEL:
                    {
                        ExecuteAsFunction(objthis != null ? objthis : mBlock.GetTJS().GetGlobal(), null,
                            result, 0);
                        break;
                    }

                    case ContextType.FUNCTION:
                    case ContextType.EXPR_FUNCTION:
                    case ContextType.PROPERTY_GETTER:
                    case ContextType.PROPERTY_SETTER:
                    {
                        ExecuteAsFunction(objthis, param, result, 0);
                        break;
                    }

                    case ContextType.CLASS:
                    {
                        // on super class' initialization
                        ExecuteAsFunction(objthis, param, result, 0);
                        break;
                    }

                    case ContextType.PROPERTY:
                    {
                        return Error.E_INVALIDTYPE;
                    }
                }
                return Error.S_OK;
            }
            int hr = base.FuncCall(flag, membername, result, param, objthis);
            if (membername != null && hr == Error.E_MEMBERNOTFOUND && mContextType == ContextType
                .CLASS && mSuperClassGetter != null)
            {
                // look up super class
                int[] pointer = mSuperClassGetter.mSuperClassGetterPointer;
                int count = pointer.Length;
                if (count > 0)
                {
                    Variant res = new Variant();
                    for (int i = count - 1; i >= 0; i--)
                    {
                        int v = pointer[i];
                        mSuperClassGetter.ExecuteAsFunction(null, null, res, v);
                        VariantClosure clo = res.AsObjectClosure();
                        hr = clo.FuncCall(flag, membername, result, param, objthis);
                        if (hr != Error.E_MEMBERNOTFOUND)
                        {
                            break;
                        }
                    }
                }
            }
            return hr;
        }
Exemple #12
0
 // property set
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 public override int PropSet(int flag, string membername, Variant param, Dispatch2
     objthis)
 {
     if (!GetValidity())
     {
         return Error.E_INVALIDOBJECT;
     }
     if (membername == null)
     {
         if (mContextType == ContextType.PROPERTY)
         {
             // executed as a property setter
             if (mPropSetter != null)
             {
                 Variant[] @params = new Variant[1];
                 @params[0] = param;
                 return mPropSetter.FuncCall(0, null, null, @params, objthis);
             }
             else
             {
                 return Error.E_ACCESSDENYED;
             }
         }
     }
     // WARNING!! const tTJSVariant ** -> tTJSVariant** force casting
     int hr;
     if (membername != null && mContextType == ContextType.CLASS && mSuperClassGetter
         != null)
     {
         int pseudo_flag = (flag & Interface.IGNOREPROP) != 0 ? flag : (flag & ~Interface.
             MEMBERENSURE);
         // member ensuring is temporarily disabled unless Interface.IGNOREPROP
         hr = base.PropSet(pseudo_flag, membername, param, objthis);
         if (hr == Error.E_MEMBERNOTFOUND)
         {
             int[] pointer = mSuperClassGetter.mSuperClassGetterPointer;
             int count = pointer.Length;
             if (count != 0)
             {
                 Variant res = new Variant();
                 for (int i = count - 1; i >= 0; i--)
                 {
                     mSuperClassGetter.ExecuteAsFunction(null, null, res, pointer[i]);
                     VariantClosure clo = res.AsObjectClosure();
                     hr = clo.PropSet(pseudo_flag, membername, param, objthis);
                     if (hr != Error.E_MEMBERNOTFOUND)
                     {
                         break;
                     }
                 }
             }
         }
         if (hr == Error.E_MEMBERNOTFOUND && (flag & Interface.MEMBERENSURE) != 0)
         {
             // re-ensure the member for "this" object
             hr = base.PropSet(flag, membername, param, objthis);
         }
     }
     else
     {
         hr = base.PropSet(flag, membername, param, objthis);
     }
     return hr;
 }
Exemple #13
0
 // property get
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 public override int PropGet(int flag, string membername, Variant result, Dispatch2
     objthis)
 {
     if (!GetValidity())
     {
         return Error.E_INVALIDOBJECT;
     }
     if (membername == null)
     {
         if (mContextType == ContextType.PROPERTY)
         {
             // executed as a property getter
             if (mPropGetter != null)
             {
                 return mPropGetter.FuncCall(0, null, result, null, objthis);
             }
             else
             {
                 return Error.E_ACCESSDENYED;
             }
         }
     }
     int hr = base.PropGet(flag, membername, result, objthis);
     if (membername != null && hr == Error.E_MEMBERNOTFOUND && mContextType == ContextType
         .CLASS && mSuperClassGetter != null)
     {
         // look up super class
         int[] pointer = mSuperClassGetter.mSuperClassGetterPointer;
         int count = pointer.Length;
         if (count != 0)
         {
             Variant res = new Variant();
             for (int i = count - 1; i >= 0; i--)
             {
                 mSuperClassGetter.ExecuteAsFunction(null, null, res, pointer[i]);
                 VariantClosure clo = res.AsObjectClosure();
                 hr = clo.PropGet(flag, membername, result, objthis);
                 if (hr != Error.E_MEMBERNOTFOUND)
                 {
                     break;
                 }
             }
         }
     }
     return hr;
 }
Exemple #14
0
 // operation with member
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 public override int Operation(int flag, string membername, Variant result, Variant
     param, Dispatch2 objthis)
 {
     if (membername == null)
     {
         if (mContextType == ContextType.PROPERTY)
         {
             // operation for property object
             return base.DispatchOperation(flag, membername, result, param, objthis);
         }
         else
         {
             return base.Operation(flag, membername, result, param, objthis);
         }
     }
     int hr;
     if (membername != null && mContextType == ContextType.CLASS && mSuperClassGetter
         != null)
     {
         int pseudo_flag = (flag & Interface.IGNOREPROP) != 0 ? flag : (flag & ~Interface.
             MEMBERENSURE);
         hr = base.Operation(pseudo_flag, membername, result, param, objthis);
         if (hr == Error.E_MEMBERNOTFOUND)
         {
             // look up super class
             int[] pointer = mSuperClassGetter.mSuperClassGetterPointer;
             int count = pointer.Length;
             if (count != 0)
             {
                 Variant res = new Variant();
                 for (int i = count - 1; i >= 0; i--)
                 {
                     mSuperClassGetter.ExecuteAsFunction(null, null, res, pointer[i]);
                     VariantClosure clo = res.AsObjectClosure();
                     hr = clo.Operation(pseudo_flag, membername, result, param, objthis);
                     if (hr != Error.E_MEMBERNOTFOUND)
                     {
                         break;
                     }
                 }
             }
         }
         if (hr == Error.E_MEMBERNOTFOUND)
         {
             hr = base.Operation(flag, membername, result, param, objthis);
         }
         return hr;
     }
     else
     {
         return base.Operation(flag, membername, result, param, objthis);
     }
 }
Exemple #15
0
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 public static int DefaultIsInstanceOf(int flag, Variant targ, string name, Dispatch2
     objthis)
 {
     if (targ.IsVoid())
     {
         return Error.S_FALSE;
     }
     if ("Object".Equals(name))
     {
         return Error.S_TRUE;
     }
     if (targ.IsNumber())
     {
         if ("Number".Equals(name))
         {
             return Error.S_TRUE;
         }
         else
         {
             return Error.S_FALSE;
         }
     }
     else
     {
         if (targ.IsString())
         {
             if ("String".Equals(name))
             {
                 return Error.S_TRUE;
             }
             else
             {
                 return Error.S_FALSE;
             }
         }
         else
         {
             if (targ.IsOctet())
             {
                 if ("Octet".Equals(name))
                 {
                     return Error.S_TRUE;
                 }
                 else
                 {
                     return Error.S_FALSE;
                 }
             }
             else
             {
                 if (targ.IsObject())
                 {
                     VariantClosure tvclosure = targ.AsObjectClosure();
                     if (tvclosure.mObject != null)
                     {
                         // bypass
                         Dispatch2 disp = tvclosure.mObjThis != null ? tvclosure.mObjThis : objthis;
                         return tvclosure.mObject.IsInstanceOf(flag, null, name, disp);
                     }
                     return Error.S_FALSE;
                 }
             }
         }
     }
     return Error.S_FALSE;
 }
Exemple #16
0
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 protected internal static int DefaultFuncCall(int flag, Variant targ, Variant result
     , Variant[] param, Dispatch2 objthis)
 {
     if (targ.IsObject())
     {
         int er = Error.E_INVALIDTYPE;
         VariantClosure tvclosure = targ.AsObjectClosure();
         if (tvclosure.mObject != null)
         {
             // bypass
             Dispatch2 disp = tvclosure.mObjThis != null ? tvclosure.mObjThis : objthis;
             er = tvclosure.mObject.FuncCall(flag, null, result, param, disp);
             if (er == Error.E_INVALIDTYPE)
             {
                 // retry using PropGet
                 er = TryFuncCallViaPropGet(tvclosure, flag, result, param, objthis);
             }
         }
         return er;
     }
     return Error.E_INVALIDTYPE;
 }
Exemple #17
0
 /// <exception cref="Kirikiri.Tjs2.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;
 }
Exemple #18
0
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 protected internal static int DefaultInvalidate(int flag, Variant targ, Dispatch2
     objthis)
 {
     if (targ.IsObject())
     {
         VariantClosure tvclosure = targ.AsObjectClosure();
         if (tvclosure.mObject != null)
         {
             // bypass
             Dispatch2 disp = tvclosure.mObjThis != null ? tvclosure.mObjThis : objthis;
             return tvclosure.mObject.Invalidate(flag, null, disp);
         }
     }
     return Error.S_FALSE;
 }
Exemple #19
0
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 public static object VariantToJavaObject(Variant param, Type type)
 {
     if (type.IsPrimitive)
     {
         // プリミティブタイプの场合
         if (type.Equals(typeof(int)))
         {
             return Sharpen.Extensions.ValueOf(param.AsInteger());
         }
         else
         {
             if (type.Equals(typeof(double)))
             {
                 return (param.AsDouble());
             }
             else
             {
                 if (type.Equals(typeof(bool)))
                 {
                     return Sharpen.Extensions.ValueOf(param.AsInteger() != 0 ? true : false);
                 }
                 else
                 {
                     if (type.Equals(typeof(float)))
                     {
                         return ((float)param.AsDouble());
                     }
                     else
                     {
                         if (type.Equals(typeof(long)))
                         {
                             return Sharpen.Extensions.ValueOf(param.AsInteger());
                         }
                         else
                         {
                             if (type.Equals(typeof(char)))
                             {
                                 return ((char)param.AsInteger());
                             }
                             else
                             {
                                 if (type.Equals(typeof(byte)))
                                 {
                                     return (unchecked((byte)param.AsInteger()));
                                 }
                                 else
                                 {
                                     if (type.Equals(typeof(short)))
                                     {
                                         return ((short)param.AsInteger());
                                     }
                                     else
                                     {
                                         // may be Void.TYPE
                                         return null;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     else
     {
         if (type.Equals(typeof(string)))
         {
             return param.AsString();
         }
         else
         {
             if (type.Equals(typeof(ByteBuffer)))
             {
                 return param.AsOctet();
             }
             else
             {
                 if (type.Equals(typeof(Variant)))
                 {
                     return param;
                 }
                 else
                 {
                     if (type.Equals(typeof(VariantClosure)))
                     {
                         return param.AsObjectClosure();
                     }
                     else
                     {
                         if (type.Equals(typeof(Dispatch2)))
                         {
                             return param.AsObject();
                         }
                         else
                         {
                             if (type.Equals(param.ToJavaObject().GetType()))
                             {
                                 return param.ToJavaObject();
                             }
                             else
                             {
                                 // その他 のクラス
                                 return null;
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Exemple #20
0
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 protected internal static int DefaultIsValid(int flag, Variant targ, Dispatch2 objthis
     )
 {
     if (targ.IsObject())
     {
         VariantClosure tvclosure = targ.AsObjectClosure();
         if (tvclosure.mObject != null)
         {
             // bypass
             Dispatch2 disp = tvclosure.mObjThis != null ? tvclosure.mObjThis : objthis;
             return tvclosure.mObject.IsValid(flag, null, disp);
         }
     }
     // the target type is not tvtObject
     return Error.S_TRUE;
 }
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 protected internal static void SetPropertyDirect(Variant target, int member, Variant
     param, Dispatch2 objthis, int flags)
 {
     if (target.IsObject())
     {
         VariantClosure clo = target.AsObjectClosure();
         string name = Sharpen.Extensions.ToString(member);
         int hr = clo.PropSet(flags, name, param, clo.mObjThis != null ? clo.mObjThis : objthis
             );
         if (hr < 0)
         {
             ThrowFrom_tjs_error(hr, name);
         }
     }
     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);
             }
         }
     }
 }
Exemple #22
0
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 protected internal static int DefaultOperation(int flag, Variant targ, Variant result
     , Variant param, Dispatch2 objthis)
 {
     int op = flag & OP_MASK;
     if (op != OP_INC && op != OP_DEC && param == null)
     {
         return Error.E_INVALIDPARAM;
     }
     if (op < OP_MIN || op > OP_MAX)
     {
         return Error.E_INVALIDPARAM;
     }
     if (targ.IsObject())
     {
         // the member may be a property handler if the member's type is "tvtObject"
         // so here try to access the object.
         int hr;
         VariantClosure tvclosure = targ.AsObjectClosure();
         if (tvclosure.mObject != null)
         {
             Dispatch2 ot = tvclosure.mObjThis != null ? tvclosure.mObjThis : objthis;
             Variant tmp = new Variant();
             hr = tvclosure.mObject.PropGet(0, null, tmp, ot);
             if (hr >= 0)
             {
                 DoVariantOperation(op, tmp, param);
                 hr = tvclosure.mObject.PropSet(0, null, tmp, ot);
                 if (hr < 0)
                 {
                     return hr;
                 }
                 if (result != null)
                 {
                     result.CopyRef(tmp);
                 }
                 return Error.S_OK;
             }
             else
             {
                 if (hr != Error.E_NOTIMPL && hr != Error.E_INVALIDTYPE && hr != Error.E_INVALIDOBJECT)
                 {
                     return hr;
                 }
             }
         }
     }
     // normal operation is proceeded if "PropGet" is failed.
     DoVariantOperation(op, targ, param);
     if (result != null)
     {
         result.CopyRef(targ);
     }
     return Error.S_OK;
 }
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 /// <exception cref="Kirikiri.Tjs2.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);
 }
Exemple #24
0
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 protected internal static int DefaultPropGet(int flag, Variant targ, Variant result
     , Dispatch2 objthis)
 {
     if ((flag & Interface.IGNOREPROP) == 0)
     {
         // if IGNOREPROP is not specified
         // if member's type is tvtObject, call the object's PropGet with "member=NULL"
         //  ( default member invocation ). if it is succeeded, return its return value.
         // if the PropGet's return value is TJS_E_ACCESSDENYED,
         // return as an error, otherwise return the member itself.
         if (targ.IsObject())
         {
             VariantClosure tvclosure = targ.AsObjectClosure();
             int hr = Error.E_NOTIMPL;
             if (tvclosure.mObject != null)
             {
                 Dispatch2 disp = tvclosure.mObjThis != null ? tvclosure.mObjThis : objthis;
                 hr = tvclosure.mObject.PropGet(0, null, result, disp);
             }
             if (hr >= 0)
             {
                 return hr;
             }
             if (hr != Error.E_NOTIMPL && hr != Error.E_INVALIDTYPE && hr != Error.E_INVALIDOBJECT)
             {
                 return hr;
             }
         }
     }
     // return the member itself
     if (result == null)
     {
         return Error.E_INVALIDPARAM;
     }
     result.CopyRef(targ);
     return Error.S_OK;
 }
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 protected internal static void TypeOfMemberIndirect(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 == Error.S_OK)
             {
                 TypeOf(result);
             }
             else
             {
                 if (hr == Error.E_MEMBERNOTFOUND)
                 {
                     result.Set("undefined");
                 }
                 else
                 {
                     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 == Error.S_OK)
             {
                 TypeOf(result);
             }
             else
             {
                 if (hr == Error.E_MEMBERNOTFOUND)
                 {
                     result.Set("undefined");
                 }
                 else
                 {
                     if (hr < 0)
                     {
                         ThrowFrom_tjs_error_num(hr, member.AsInteger());
                     }
                 }
             }
         }
     }
     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);
             }
         }
     }
 }
Exemple #26
0
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.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;
 }