Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Commit c8760c4

Browse files
committed
Add checks and guards for nullable and unknown values
1 parent 88161d2 commit c8760c4

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

src/component/handlers/edit/editOnBlur.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ function editOnBlur(editor: DraftEditor, e: SyntheticEvent): void {
2828
// issue to be certain, checking whether the active element is `body`
2929
// to force it when blurring occurs within the window (as opposed to
3030
// clicking to another tab or window).
31-
var doc = e.target && e.target.ownerDocument || document;
31+
var doc = e.target && e.target.ownerDocument instanceof Document ?
32+
e.target.ownerDocument :
33+
document;
3234
var activeElement = getActiveElement(doc);
3335
if (isWebKit && activeElement === doc.body) {
3436
doc.defaultView.getSelection().removeAllRanges();

src/component/selection/getDraftEditorSelectionWithNodes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ function getPointForNonTextNode(
155155
// wrapper.
156156
if (editorRoot === node) {
157157
node = node.firstChild;
158+
var win = node && node.ownerDocument.defaultView;
158159
invariant(
159-
node instanceof node.ownerDocument.defaultView.Element && node.getAttribute('data-contents') === 'true',
160+
win && node instanceof win.Element && node.getAttribute('data-contents') === 'true',
160161
'Invalid DraftEditorContents structure.',
161162
);
162163
if (childOffset > 0) {

src/component/selection/getSelectionOffsetKeyForNode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
function getSelectionOffsetKeyForNode(node: Node): ?string {
2121
var win = node.ownerDocument.defaultView;
22-
if (node instanceof win.Element) {
22+
if (win && node instanceof win.Element) {
2323
var offsetKey = node.getAttribute('data-offset-key');
2424
if (offsetKey) {
2525
return offsetKey;

src/model/encoding/convertFromHTMLToContentBlocks.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ function processInlineTag(
231231
currentStyle: DraftInlineStyle,
232232
): DraftInlineStyle {
233233
var styleToCheck = inlineTags[tag];
234-
var win = node.ownerDocument.defaultView;
234+
var win = node.ownerDocument.defaultView || window;
235235
if (styleToCheck) {
236236
currentStyle = currentStyle.add(styleToCheck).toOrderedSet();
237237
} else if (node instanceof win.HTMLElement) {
@@ -318,7 +318,7 @@ function containsSemanticBlockMarkup(
318318
}
319319

320320
function hasValidLinkText(link: Node): boolean {
321-
const win = link.ownerDocument.defaultView;
321+
const win = link.ownerDocument.defaultView || window;
322322
invariant(
323323
link instanceof win.HTMLAnchorElement,
324324
'Link must be an HTMLAnchorElement.',
@@ -359,7 +359,7 @@ function genFragment(
359359
text = text.replace(REGEX_LF, SPACE);
360360
}
361361

362-
// save the last block so we can use it later
362+
// Save the last block so we can use it later
363363
lastBlock = nodeName;
364364

365365
return {
@@ -373,7 +373,7 @@ function genFragment(
373373
};
374374
}
375375

376-
// save the last block so we can use it later
376+
// Save the last block so we can use it later
377377
lastBlock = nodeName;
378378

379379
// BR tags
@@ -390,7 +390,7 @@ function genFragment(
390390
return {chunk: getSoftNewlineChunk(), entityMap};
391391
}
392392

393-
const win = node.ownerDocument.defaultView;
393+
const win = node.ownerDocument.defaultView || window;
394394

395395
// IMG tags
396396
if (

0 commit comments

Comments
 (0)