Exemplo n.º 1
0
        private static List <JsVal> ConvertTypes(object[] paramObjects, AutoJSContext context, out DisposablCollection toDispose)
        {
            List <IDisposable> list = new List <IDisposable>();

            toDispose = new DisposablCollection(list);
            var collection = new List <JsVal>();

            if (paramObjects == null)
            {
                return(collection);
            }

            foreach (var p in paramObjects)
            {
                JsVal val;
                if (p is nsAString || p is nsACString || p is nsAUTF8String || p is String)
                {
                    val = SpiderMonkey.StringToJsVal(context.ContextPointer, p.ToString());
                }
                else if (p is nsISupports)
                {
                    // This returns a  [xpconnect wrapped nsISupports] - why may or may not be good enought - if not could try and access the objects wrappedJSObject property?
                    // val = SpiderMonkey.JS_CallFunctionName(context.ContextPointer, jsObject, "valueOf");
                    // Replaced CallFunctionName 'valueOf' method with 'managed convert' (for speed reasons)
                    var jso = context.ConvertCOMObjectToJSObject((nsISupports)p, false);
                    list.Add(jso);
                    val = JsVal.FromPtr(jso.JSObject);
                }
                else if (p is bool)
                {
                    val = CreateBoolJsVal(context, (bool)p);
                }
                else if (p is double)
                {
                    val = JsVal.FromDouble((double)p);
                }

                else if (p is int)
                {
                    val = JsVal.FromDouble(Convert.ToDouble(p));
                }
                else if (p is WebIDLUnionBase)
                {
                    WebIDLUnionBase b = (WebIDLUnionBase)p;
                    if (b.IsNull())
                    {
                        SpiderMonkey.JS_ExecuteScript(context.ContextPointer, "null", out val);
                    }
                    else if (b.IsComObject())
                    {
                        var item = ((WebIDLUnionBase)p).ToComObject();
                        var jso  = context.ConvertCOMObjectToJSObject(item, false);
                        list.Add(jso);
                        val = JsVal.FromPtr(jso.JSObject);
                    }
                    else if (b.IsBool())
                    {
                        val = CreateBoolJsVal(context, b.ToBool());
                    }
                    else
                    {
                        throw new NotImplementedException("WebIDLUnion are currently only supported for nsISupport and bool types and null's.");
                    }
                }
                else
                {
                    SpiderMonkey.JS_ExecuteScript(context.ContextPointer, (p ?? "null").ToString(), out val);
                }
                collection.Add(val);
            }
            return(collection);
        }