Ejemplo n.º 1
0
        public static JSBool CoerceToBool(IJSObject a)
        {
            bool outcome;

            switch (a.Type)
            {
            case JSType.String:
                outcome = ((JSString)a).Value == "";
                break;

            case JSType.Boolean:
                outcome = ((JSBool)a).Value;
                break;

            case JSType.Number:
                outcome = ((JSNumber)a).Value == 0;
                break;

            case JSType.Null:
                outcome = false;
                break;

            case JSType.Undefined:
                outcome = false;
                break;

            default:
                outcome = true;
                break;
            }
            return(new JSBool(outcome));
        }
Ejemplo n.º 2
0
 public virtual void TrackObject(IJSObject obj)
 {
     this.jsCtx.ExecuteScriptFunction("CommonAPI.TrackObject", new object[]
     {
         this.jsCtx.EscapeJSObject(obj)
     });
 }
Ejemplo n.º 3
0
 public IEnumerator <T> GetEnumerator()
 {
     if (typeof(IJSObject).IsAssignableFrom(typeof(T)))
     {
         for (int i = 0; i < this.Count; i++)
         {
             object    value = Interop.ExecuteJavaScript("$0[$1]", this.UnderlyingJSInstance, i);
             IJSObject o     = (IJSObject)(object)Activator.CreateInstance <T>();
             o.UnderlyingJSInstance = value;
             yield return((T)(object)o);
         }
     }
     else
     //else if (JSObject.Helper_IsBuiltInType<T>())
     {
         for (int i = 0; i < this.Count; i++)
         {
             object value = Interop.ExecuteJavaScript("$0[$1]", this.UnderlyingJSInstance, i);
             yield return(JSObject.Helper_ConvertTo <T>(value));
         }
     }
     // ----------------
     // Disabled this portion of code because it doesn't work well once translated into js,
     // instead the value is directly cast and return, will throw anyway if it's not compatible
     // ----------------
     //else
     //    throw new Exception("The generic type parameter '" + typeof(T).Name + "' is not a built-in type or a JSObject.");
 }
Ejemplo n.º 4
0
 // -= COMPARISON =-
 // TODO: Alg. isn't absolutely perfect
 public static JSBool StrictlyEqual(IJSObject a, IJSObject b)
 {
     if (a.Type != b.Type)
     {
         return(new JSBool(false));
     }
     return(Equal(a, b));
 }
Ejemplo n.º 5
0
        public T this[int index]
        {
            get
            {
                if (index < 0 || index >= this.Count)
                {
                    throw new ArgumentOutOfRangeException();
                }

                object value = Interop.ExecuteJavaScript("$0[$1]", this.UnderlyingJSInstance, index);
                if (typeof(IJSObject).IsAssignableFrom(typeof(T)))
                {
                    IJSObject o = (IJSObject)(object)Activator.CreateInstance <T>();
                    o.UnderlyingJSInstance = value;
                    return((T)(object)o);
                }
                else
                {
                    return((T)value);
                }
                // ----------------
                // Disabled this portion of code because it doesn't work well once translated into js,
                // instead the value is directly cast and return, will throw anyway if it's not compatible
                // ----------------
                //
                //else if (JSObject.Helper_IsBuiltInType<T>())
                //    return JSObject.Helper_ConvertTo<T>(value);
                //else
                //    throw new Exception("The generic type parameter '" + typeof(T).Name + "' is not a built-in type or a JSObject.");
            }
            set
            {
                if (index < 0 || index >= this.Count)
                {
                    throw new ArgumentOutOfRangeException();
                }

                object _value;

                if (typeof(IJSObject).IsAssignableFrom(typeof(T)))
                {
                    _value = ((IJSObject)(object)value).UnderlyingJSInstance;
                }
                else
                {
                    _value = value;
                }
                // ----------------
                // Disabled this portion of code because it doesn't work well once translated into js,
                // instead the value is directly cast and return, will throw anyway if it's not compatible
                // ----------------
                //else if (JSObject.Helper_IsBuiltInType<T>())
                //    _value = value;
                //else
                //    throw new Exception("The generic type parameter '" + typeof(T).Name + "' is not a built-in type or a JSObject.");
                Interop.ExecuteJavaScriptAsync("$0[$1] = $2", this.UnderlyingJSInstance, index, _value);
            }
        }
Ejemplo n.º 6
0
 public virtual void NotifyPropertyChanged(string trackCode, string propName, IJSObject propValue)
 {
     this.jsCtx.ExecuteScriptFunction("CommonAPI.NotifyPropertyChanged", new object[]
     {
         this.jsCtx.EscapeString(trackCode),
         this.jsCtx.EscapeString(propName),
         this.jsCtx.EscapeJSObject(propValue)
     });
 }
Ejemplo n.º 7
0
        public static string MakeJSID(this IJSObject thisObj)
        {
            Type typeFromHandle = typeof(IJSObjectHelpers);

            lock (typeFromHandle)
            {
                IJSObjectHelpers.lastJsId += 1UL;
            }
            return(thisObj.GetType().Name + "-" + IJSObjectHelpers.lastJsId);
        }
Ejemplo n.º 8
0
 // TIL: A _remainder_ operator is not quite a _modulo_ operator
 public static IJSObject Remainder(IJSObject a, IJSObject b)
 {
     if (a.Type == JSType.Number && b.Type == JSType.Number)
     {
         var aN = (JSNumber)a;
         var bN = (JSNumber)b;
         return(new JSNumber(aN.Value % bN.Value));
     }
     else
     {
         return(new JSNaN());
     }
 }
        public string EscapeJSObjectValue(object o)
        {
            IJSObject ijsobject = o as IJSObject;

            if (ijsobject != null)
            {
                return(this.EscapeJSObject(ijsobject));
            }
            IEnumerable <IJSObject> enumerable = o as IEnumerable <IJSObject>;

            if (enumerable != null)
            {
                return(this.EscapeArray(enumerable));
            }
            return(JavascriptSerializer.SerializeJavascriptObject(o));
        }
Ejemplo n.º 10
0
 // -= ARITHMETIC =-
 public static IJSObject Plus(IJSObject a, IJSObject b)
 {
     if (a.Type == JSType.Number && b.Type == JSType.Number)
     {
         var aN = (JSNumber)a;
         var bN = (JSNumber)b;
         return(new JSNumber(aN.Value + bN.Value));
     }
     else if (a.Type == JSType.String || b.Type == JSType.String)
     {
         return(new JSString($"{a.AsCSharpString}{b.AsCSharpString}"));
     }
     else
     {
         throw new NotImplementedException("Addition of those two types is not implemented");
     }
 }
        public string EscapeJSObject(IJSObject o)
        {
            ITrackableJSObject trackableJSObject = o as ITrackableJSObject;

            if (trackableJSObject != null)
            {
                if (trackableJSObject.IsTracked)
                {
                    return("CommonAPI.GetTrackedObject(" + JavascriptSerializer.Serialize(trackableJSObject.TrackingCode) + ")");
                }
                if (trackableJSObject.ConstructorFunction != null)
                {
                    return(this.CallJSConstructor(trackableJSObject));
                }
            }
            return(JavascriptSerializer.Serialize(o.ToJavascriptObject()));
        }
Ejemplo n.º 12
0
        // TODO: Implement this properly with type conversion
        //       For now we'll only support getting here through StrictEquality
        public static JSBool Equal(IJSObject a, IJSObject b)
        {
            bool areEqual;

            switch (a.Type)
            {
            case JSType.Number:
                areEqual = ((JSNumber)a).Value == ((JSNumber)b).Value;
                break;

            case JSType.String:
                areEqual = ((JSString)a).Value == ((JSString)b).Value;
                break;

            default:
                throw new NotImplementedException($"Equality between type {a.Type} and {b.Type} is not implemented");
            }

            return(new JSBool(areEqual));
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Creates a new <see cref="JSObjectHandle"/> for the provided object.
 /// </summary>
 /// <param name="target">The object to marshal to javascript</param>
 /// <returns></returns>
 public static JSObjectHandle Create(IJSObject target)
 => Create(target, JSObjectMetadataProvider.Get(target.GetType()));
Ejemplo n.º 14
0
 public void Callback(IJSObject Parent, IJSMethod Method)
 {
     if (m_Proc != null)
         m_Proc(Parent, Method);
 }
 partial void Initialize(IJSObject element, EditorOptions options)
 {
     base.Initialize();
 }
Ejemplo n.º 16
0
 internal void OnOnPropertyChangeEventHandler(IJSObject Sender, IJSProperty Prop)
 {
     if (OnPropertyChange != null)
     {
         JSPropertyChangeEventArgs args = new JSPropertyChangeEventArgs();
         args.Sender = Sender;
         args.Prop = Prop;
         OnPropertyChange(this, args);
     }
 }
Ejemplo n.º 17
0
 public void Set(IJSObject Parent, IJSProperty Prop)
 {
     if (m_Proc != null)
         m_Proc(Parent, Prop);
 }
Ejemplo n.º 18
0
 internal void OnExecuteMethodEventHandler(IJSObject Sender, IJSMethod Method)
 {
     if (OnExecuteMethod != null)
     {
         JSExecuteMethodEventArgs args = new JSExecuteMethodEventArgs();
         args.Sender = Sender;
         args.Method = Method;
         OnExecuteMethod(this, args);
     }
 }
Ejemplo n.º 19
0
 public void Dispose()
 {
     if (connectionPoint != null)
     {
         try
         {
             //connectionPoint.Unadvise(connectionCookie);
         }
         catch (Exception)
         {
         }
         connectionPoint = null;
         connectionCookie = 0;
     }
     if (m_JSObject != null)
         Marshal.ReleaseComObject(m_JSObject);
     m_JSObject = null;
 }
Ejemplo n.º 20
0
 partial void Initialize(IJSObject element, TreeViewOptions options)
 {
     this.Init();
     base.Initialize();
 }
Ejemplo n.º 21
0
 public virtual void NotifyElementReplaced(string trackCode, string collectionPropName, int position, IJSObject newElement)
 {
     this.jsCtx.ExecuteScriptFunction("CommonAPI.NotifyElementReplaced", new object[]
     {
         this.jsCtx.EscapeString(trackCode),
         this.jsCtx.EscapeString(collectionPropName),
         position,
         this.jsCtx.EscapeJSObject(newElement)
     });
 }
Ejemplo n.º 22
0
 public static object ToJavaScriptObject(this IJSObject o)
 {
     return(o.UnderlyingJSInstance);
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Creates a new <see cref="JSObjectHandle"/> for the provided object by specifying the <see cref="IJSObjectMetadata"/> of the target.
 /// </summary>
 /// <param name="target">The object to marshal to javascript</param>
 /// <param name="metadata">Metadat of the <paramref name="target"/>.</param>
 /// <returns></returns>
 public static JSObjectHandle Create(IJSObject target, IJSObjectMetadata metadata)
 => new JSObjectHandle(target, metadata);
Ejemplo n.º 24
0
 public void OnExecuteMethod(IJSObject Sender, IJSMethod Method)
 {
     m_JSObject.OnExecuteMethodEventHandler(Sender, Method);
 }
Ejemplo n.º 25
0
 public static JSBool StrictlyNotEqual(IJSObject a, IJSObject b)
 {
     return(new JSBool(
                !StrictlyEqual(a, b).Value
                ));
 }
Ejemplo n.º 26
0
 public void OnPropertyChange(IJSObject Sender, IJSProperty Prop)
 {
     m_JSObject.OnOnPropertyChangeEventHandler(Sender, Prop);
 }
Ejemplo n.º 27
0
 public static JSBool NotEqual(IJSObject a, IJSObject b)
 {
     return(new JSBool(
                !Equal(a, b).Value
                ));
 }
 partial void Initialize(IJSObject element, GridOptions options)
 {
     this.Init();
     base.Initialize();
 }