示例#1
0
        private static List <JsVal> ConvertTypes(object[] paramObjects, AutoJSContext context)
        {
            var collection = new List <JsVal>();

            foreach (var p in paramObjects)
            {
                JsVal val;
                if (p is nsAString || p is nsACString || p is nsAUTF8String || p is String)
                {
                    SpiderMonkey.JS_ExecuteScript(context.ContextPointer, '"' + p.ToString() + '"', out val);
                }
                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)
                    val = JsVal.FromPtr(context.ConvertCOMObjectToJSObject((nsISupports)p));
                }
                else if (p is bool)
                {
                    SpiderMonkey.JS_ExecuteScript(context.ContextPointer, ((bool)p) ? "true;" : "false;", out val);
                }
                else if (p is double)
                {
                    val = JsVal.FromDouble((double)p);
                }
                else
                {
                    SpiderMonkey.JS_ExecuteScript(context.ContextPointer, p.ToString(), out val);
                }
                collection.Add(val);
            }
            return(collection);
        }
示例#2
0
        public void FromPtr_JsObject_ConvertedToJsValOfExpectedObject()
        {
            var browser = new GeckoWebBrowser();
            var unused  = browser.Handle;

            Assert.IsNotNull(browser);
            browser.TestLoadHtml("hello world.");
            Assert.Null(browser.Editor);

            using (var context = new AutoJSContext(browser.Window))
            {
                var jsObject = context.ConvertCOMObjectToJSObject((nsISupports)browser.Document.DomObject);
                var jsVal    = JsVal.FromPtr(jsObject);

                Assert.IsTrue(jsVal.IsObject);
                Assert.AreEqual(JSType.JSTYPE_OBJECT, jsVal.Type);
                Assert.AreEqual("[object HTMLDocument]", jsVal.ToString());
                // Verify that converting back to ComObject yields expected object.
                var documentObject = (nsIDOMHTMLDocument)jsVal.ToObject();
                Assert.AreEqual(browser.Document.TextContent, new GeckoDocument(documentObject).TextContent);
            }

            browser.Dispose();
        }
示例#3
0
        public void JS_TypeOfValue()
        {
            if (Xpcom.IsLinux && IntPtr.Size == 8)
            {
                Assert.Ignore("unsafe test:seg faults on 64bit Linux");
            }

            using (AutoJSContext cx = new AutoJSContext(GlobalJSContextHolder.BackstageJSContext))
            {
                Assert.AreEqual(JSType.JSTYPE_NUMBER, SpiderMonkey.JS_TypeOfValue(cx.ContextPointer, JsVal.FromPtr(0)));
                Assert.AreEqual(JSType.JSTYPE_NUMBER, SpiderMonkey.JS_TypeOfValue(cx.ContextPointer, JsVal.FromPtr(0xffff0000ffffffff)));
                Assert.AreEqual(JSType.JSTYPE_BOOLEAN, SpiderMonkey.JS_TypeOfValue(cx.ContextPointer, JsVal.FromPtr(0xffffffffffffffff)));
            }
        }
示例#4
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);
        }