Don't call window.getSelection when it isn't defined.
Sadly, jsdom does not support `window.getSelection` yet, but `ExecutionEnvironment.canUseDOM` is `true` in a jsdom environment.
Ben Newman committed
Jul 18, 2014 at 10:03 UTC
2347abf75c2acb40b4b6ba10750f0461a5b837ad
1 file changed
+6
-3
src/browser/ui/ReactDOMSelection.js
+6
-3
@@ -70,9 +70,9 @@ function getIEOffsets(node) {
70
* @return {?object}
71
*/
72
function getModernOffsets(node) {
73
- var selection = window.getSelection();
73
+ var selection = window.getSelection && window.getSelection();
74
75
- if (selection.rangeCount === 0) {
75
+ if (!selection || selection.rangeCount === 0) {
76
return null;
77
}
78
@@ -161,8 +161,11 @@ function setIEOffsets(node, offsets) {
161
* @param {object} offsets
162
*/
163
function setModernOffsets(node, offsets) {
164
- var selection = window.getSelection();
164
+ if (!window.getSelection) {
165
+ return;
166
+ }
167
168
+ var selection = window.getSelection();
169
var length = node[getTextContentAccessor()].length;
170
var start = Math.min(offsets.start, length);
171
var end = typeof offsets.end === 'undefined' ?