Permalink
Browse files

XMLUtils JS : add methods tests to avoid lazy exception catching.

  • Loading branch information...
1 parent 095529d commit b2bf0a823f93f327e9eeefbccd886aee4e0ed959 @cdujeu cdujeu committed Jun 20, 2016
Showing with 17 additions and 13 deletions.
  1. +17 −13 core/src/plugins/gui.ajax/res/js/es6/util/XMLUtils.es6
@@ -37,10 +37,12 @@ class XMLUtils{
* @signature function(element, query)
*/
static XPathSelectSingleNode(element, query){
- try{
- var res = element.selectSingleNode(query);
- if(res) return res;
- }catch(e){}
+ if(element.selectSingleNode){
+ try{
+ var res = element.selectSingleNode(query);
+ if(res) return res;
+ }catch(e){}
+ }
if(!XMLUtils.__xpe) {
try{
@@ -74,17 +76,19 @@ class XMLUtils{
* @signature function(element, query)
*/
static XPathSelectNodes(element, query){
- try{
+ if(element.selectNodes){
try{
- if(element.ownerDocument){
- element.ownerDocument.setProperty("SelectionLanguage", "XPath");
- }else{
- element.setProperty("SelectionLanguage", "XPath");
- }
+ try{
+ if(element.ownerDocument && element.ownerDocument.setProperty){
+ element.ownerDocument.setProperty("SelectionLanguage", "XPath");
+ }else if(element.setProperty){
+ element.setProperty("SelectionLanguage", "XPath");
+ }
+ }catch(e){}
+ var res = Array.from(element.selectNodes(query));
+ if(res) return res;
}catch(e){}
- var res = Array.from(element.selectNodes(query));
- if(res) return res;
- }catch(e){}
+ }
var xpe = XMLUtils.__xpe;

0 comments on commit b2bf0a8

Please sign in to comment.