IsObject() публичный Метод

public IsObject ( ) : bool
Результат bool
Пример #1
0
 /// <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);
 }
Пример #2
0
 /// <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);
             }
         }
     }
 }
Пример #3
0
 /// <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);
             }
         }
     }
 }
Пример #4
0
 //private Callback mCallback;
 //private VariantClosure mCallbackClosure;
 // a class to receive member callback from class
 // destination object
 /// <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)
 {
     // *param[0] = name   *param[1] = flags   *param[2] = value
     int flags = param[1].AsInteger();
     if ((flags & Interface.STATICMEMBER) == 0)
     {
         Variant val = new Variant(param[2]);
         if (val.IsObject())
         {
             // change object's objthis if the object's objthis is null
             if (val.AsObjectThis() == null)
             {
                 val.ChangeClosureObjThis(mDest);
             }
         }
         mDest.PropSet(Interface.MEMBERENSURE | Interface.IGNOREPROP | flags, param[0].AsString
             (), val, mDest);
     }
     if (result != null)
     {
         result.Set(1);
     }
     // returns true
     return Error.S_OK;
 }
Пример #5
0
 //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);
             }
         }
     }
 }
Пример #6
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;
 }
Пример #7
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;
 }
Пример #8
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;
 }
Пример #9
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;
 }
Пример #10
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;
 }
Пример #11
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;
 }
Пример #12
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;
 }
Пример #13
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;
 }
Пример #14
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;
 }
Пример #15
0
 /// <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);
             }
         }
     }
 }
Пример #16
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;
 }
Пример #17
0
 /// <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);
             }
         }
     }
 }
Пример #18
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 (value.IsObject())
     {
         // object
         Dispatch2 dsp = value.AsObject();
         // determin dsp's object type
         Variant val;
         if (dsp != null)
         {
             if (dsp.GetNativeInstance(DictionaryClass.ClassID) != null)
             {
                 // dictionary
                 bool objrec = false;
                 int count = mStack.Count;
                 for (int i = 0; i < count; i++)
                 {
                     Dispatch2 v = mStack[i];
                     if (v == dsp)
                     {
                         // object recursion detected
                         objrec = true;
                         break;
                     }
                 }
                 val = new Variant();
                 if (objrec)
                 {
                     val.SetObject(null);
                 }
                 else
                 {
                     // becomes null
                     Dispatch2 newobj = TJS.CreateDictionaryObject();
                     val.SetObject(newobj, newobj);
                     DictionaryNI newni;
                     if ((newni = (DictionaryNI)newobj.GetNativeInstance(DictionaryClass.ClassID)) !=
                         null)
                     {
                         newni.AssignStructure(dsp, mStack);
                     }
                 }
             }
             else
             {
                 if (dsp.GetNativeInstance(ArrayClass.ClassID) != null)
                 {
                     // array
                     bool objrec = false;
                     int count = mStack.Count;
                     for (int i = 0; i < count; i++)
                     {
                         Dispatch2 v = mStack[i];
                         if (v == dsp)
                         {
                             // object recursion detected
                             objrec = true;
                             break;
                         }
                     }
                     val = new Variant();
                     if (objrec)
                     {
                         val.SetObject(null);
                     }
                     else
                     {
                         // becomes null
                         Dispatch2 newobj = TJS.CreateArrayObject();
                         val.SetObject(newobj, newobj);
                         ArrayNI newni;
                         if ((newni = (ArrayNI)newobj.GetNativeInstance(ArrayClass.ClassID)) != null)
                         {
                             newni.AssignStructure(dsp, mStack);
                         }
                     }
                 }
                 else
                 {
                     val = value;
                 }
             }
         }
         else
         {
             // other object types
             val = value;
         }
         mDest.PropSet(Interface.MEMBERENSURE | Interface.IGNOREPROP, name, val, mDest);
     }
     else
     {
         // other types
         mDest.PropSet(Interface.MEMBERENSURE | Interface.IGNOREPROP, name, value, mDest);
     }
     return true;
 }