Beispiel #1
0
        public void GetWrappedNativePrototype()
        {
            _browser.TestLoadHtml("<span id='a'>hello world</span>");
            var element = _browser.Document.GetHtmlElementById("a");

            using (AutoJSContext context = new AutoJSContext(_browser.Window.JSContext))
            {
                IntPtr globalObject   = SpiderMonkey.JS_GetGlobalForScopeChain(context.ContextPointer);
                var    jsobjectholder = m_instance.GetWrappedNativePrototype(context.ContextPointer, globalObject, new MyClassInfo());

                string result;
                Console.WriteLine(context.EvaluateScript("this", (nsISupports)jsobjectholder, out result));
                Console.WriteLine(result);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Unittest helper method to create a String JsVal
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private static JsVal CreateJsVal(string jscript)
        {
            using (AutoJSContext cx = new AutoJSContext(GlobalJSContextHolder.BackstageJSContext))
            {
                var ptr = new JsVal();
                var _securityManager = Xpcom.GetService <nsIScriptSecurityManager>("@mozilla.org/scriptsecuritymanager;1");
                var _systemPrincipal = _securityManager.GetSystemPrincipal();

                IntPtr globalObject = SpiderMonkey.JS_GetGlobalForScopeChain(cx.ContextPointer);
                bool   ret          = SpiderMonkey.JS_EvaluateScript(cx.ContextPointer, globalObject, jscript, (uint)jscript.Length, "script", 1, ref ptr);
                Assert.IsTrue(ret);
                Marshal.ReleaseComObject(_securityManager);

                return(ptr);
            }
        }