Пример #1
0
        /// <summary>
        /// Gets the nsIXPCComponents which is the javascript 'Components' objects
        /// The Components objects is the main object XPConnect object.
        /// </summary>
        /// <returns></returns>
        internal nsIXPCComponents GetComponentsObject()
        {
            if (_nsIXPCComponents == null)
            {
                var jsValue = new JsVal();
                SpiderMonkey.JS_ExecuteScript(ContextPointer, "this.myfunc = function(p1) { return Components; };",
                                              out jsValue);

                jsValue = SpiderMonkey.JS_CallFunctionName(ContextPointer, _globalJSObject, "myfunc", new[] { jsValue });

                _nsIXPCComponents = Xpcom.QueryInterface <nsIXPCComponents>(jsValue.ToObject());
                if (_nsIXPCComponents == null)
                {
                    throw new GeckoException(String.Format(
                                                 "Components object does not implement nsIXPCComponents. {0}", jsValue));
                }
            }

            return(_nsIXPCComponents);
        }