1
- /*global HTMLDocument*/
2
1
function getAttributes ( elm ) {
3
2
var attrs = elm . attributes ;
4
3
var result = { } ;
@@ -77,11 +76,7 @@ module.exports = {
77
76
name : 'DOMNode' ,
78
77
base : 'object' ,
79
78
identify : function ( obj ) {
80
- if ( ! obj ) {
81
- return false ;
82
- }
83
-
84
- return obj . nodeName && [ 2 , 3 , 4 , 5 , 6 , 7 , 9 , 10 , 11 , 12 ] . indexOf ( obj . nodeType ) > - 1 ;
79
+ return obj && obj . nodeName && [ 2 , 3 , 4 , 5 , 6 , 7 , 10 , 11 , 12 ] . indexOf ( obj . nodeType ) > - 1 ;
85
80
} ,
86
81
equal : function ( a , b ) {
87
82
return a . nodeValue === b . nodeValue ;
@@ -95,11 +90,7 @@ module.exports = {
95
90
name : 'DOMComment' ,
96
91
base : 'DOMNode' ,
97
92
identify : function ( obj ) {
98
- if ( ! obj ) {
99
- return false ;
100
- }
101
-
102
- return obj . nodeType === 8 ;
93
+ return obj && obj . nodeType === 8 ;
103
94
} ,
104
95
equal : function ( a , b ) {
105
96
return a . nodeValue === b . nodeValue ;
@@ -113,28 +104,15 @@ module.exports = {
113
104
name : 'HTMLDocument' ,
114
105
base : 'DOMNode' ,
115
106
identify : function ( obj ) {
116
- if ( 'HTMLDocument' in this ) {
117
- return obj instanceof HTMLDocument ;
118
- }
119
-
120
- if ( typeof window !== 'undefined' ) {
121
- return obj instanceof window . HTMLDocument ;
122
- }
123
-
124
- // Stupid duck typing case. Help :)
125
- return obj && obj . documentElement && obj . implementation ;
107
+ return obj && obj . nodeType === 9 && obj . documentElement && obj . implementation ;
126
108
}
127
109
} ) ;
128
110
129
111
expect . addType ( {
130
112
name : 'HTMLElement' ,
131
113
base : 'DOMNode' ,
132
114
identify : function ( obj ) {
133
- if ( ! obj ) {
134
- return false ;
135
- }
136
-
137
- return ! ! ( obj . nodeType === 1 && obj . nodeName && obj . attributes && obj . outerHTML ) ;
115
+ return obj && obj . nodeType === 1 && obj . nodeName && obj . attributes && obj . outerHTML ;
138
116
} ,
139
117
equal : function ( a , b ) {
140
118
return stringifyElement ( a ) === stringifyElement ( b ) ;
0 commit comments