public GeckoNode SelectSingle(string xpath) { var r = EvaluateXPathInternal(xpath); nsIDOMNode singleNode = null; switch (r.GetResultTypeAttribute()) { case nsIDOMXPathResultConsts.UNORDERED_NODE_ITERATOR_TYPE: singleNode = r.IterateNext(); var test = r.IterateNext(); if (test != null) { Xpcom.FreeComObject(ref test); Xpcom.FreeComObject(ref singleNode); Xpcom.FreeComObject(ref r); throw new GeckoDomException("There are more than 1 nodes in Single selection"); } break; case nsIDOMXPathResultConsts.FIRST_ORDERED_NODE_TYPE: case nsIDOMXPathResultConsts.ANY_UNORDERED_NODE_TYPE: singleNode = r.GetSingleNodeValueAttribute(); break; } var ret = singleNode.Wrap(GeckoNode.Create); Xpcom.FreeComObject(ref r); return(ret); }
/// <summary> /// Working similar to SelectSingle but not throwing exceptions on error (simply return first result) /// </summary> /// <param name="xpath"></param> /// <returns></returns> public GeckoNode SelectFirst(string xpath) { var r = EvaluateXPathInternal(xpath); nsIDOMNode singleNode = null; using (var context = new AutoJSContext()) { var jsObject = context.ConvertCOMObjectToJSObject((nsISupports)r); // TODO: (Idenally I would generate these calls via a webidl-> C# compiler but for now just do it via manually written spidermonkey calls..) var resultType = SpiderMonkey.JS_GetProperty(context.ContextPointer, jsObject, "resultType").ToInteger(); switch (resultType) { case nsIDOMXPathResultConsts.UNORDERED_NODE_ITERATOR_TYPE: singleNode = (nsIDOMNode)SpiderMonkey.JS_CallFunctionName(context.ContextPointer, jsObject, "iterateNext", new JsVal[0]).ToComObject(context.ContextPointer); break; case nsIDOMXPathResultConsts.FIRST_ORDERED_NODE_TYPE: case nsIDOMXPathResultConsts.ANY_UNORDERED_NODE_TYPE: singleNode = (nsIDOMNode)SpiderMonkey.JS_GetProperty(context.ContextPointer, jsObject, "singleNodeValue").ToComObject(context.ContextPointer); break; } var ret = singleNode.Wrap(GeckoNode.Create); Xpcom.FreeComObject(ref r); return(ret); } }
public GeckoNode SelectSingle(string xpath) { var r = EvaluateXPathInternal(xpath); nsIDOMNode singleNode = null; using (var context = new AutoJSContext(Window)) using (var jsObject = context.ConvertCOMObjectToJSObject((nsISupports)r)) { // TODO: (Idenally I would generate these calls via a webidl-> C# compiler but for now just do it via manually written spidermonkey calls..) var resultType = SpiderMonkey.JS_GetProperty(context.ContextPointer, jsObject.JSObject, "resultType").ToInteger(); #if PORTFF60 switch (resultType) { case nsIDOMXPathResultConsts.UNORDERED_NODE_ITERATOR_TYPE: singleNode = (nsIDOMNode) SpiderMonkey.JS_CallFunctionName(context.ContextPointer, jsObject, "iterateNext", new JsVal[0]).ToComObject(context.ContextPointer); var test = (SpiderMonkey.JS_CallFunctionName(context.ContextPointer, jsObject, "iterateNext", new JsVal[0])); if (!test.IsNull) { Xpcom.FreeComObject(ref singleNode); Xpcom.FreeComObject(ref r); throw new GeckoDomException("There are more than 1 nodes in Single selection"); } break; case nsIDOMXPathResultConsts.FIRST_ORDERED_NODE_TYPE: case nsIDOMXPathResultConsts.ANY_UNORDERED_NODE_TYPE: singleNode = (nsIDOMNode) SpiderMonkey.JS_GetProperty(context.ContextPointer, jsObject, "singleNodeValue") .ToComObject(context.ContextPointer); break; } #endif throw new NotImplementedException(); } #if PORTFF60 var ret = singleNode.Wrap(GeckoNode.Create); Xpcom.FreeComObject(ref r); return(ret); #endif }
/// <summary> /// Working similar to SelectSingle but not throwing exceptions on error (simply return first result) /// </summary> /// <param name="xpath"></param> /// <returns></returns> public GeckoNode SelectFirst(string xpath) { var r = EvaluateXPathInternal(xpath); nsIDOMNode singleNode = null; switch (r.GetResultTypeAttribute()) { case nsIDOMXPathResultConsts.UNORDERED_NODE_ITERATOR_TYPE: singleNode = r.IterateNext(); break; case nsIDOMXPathResultConsts.FIRST_ORDERED_NODE_TYPE: case nsIDOMXPathResultConsts.ANY_UNORDERED_NODE_TYPE: singleNode = r.GetSingleNodeValueAttribute(); break; } var ret = singleNode.Wrap(GeckoNode.Create); Xpcom.FreeComObject(ref r); return(ret); }