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

Commit

Permalink
Add checks and guards for nullable and unknown values
Browse files Browse the repository at this point in the history
  • Loading branch information
acusti committed Dec 6, 2016
1 parent 1ff7ac4 commit ca12190
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/component/handlers/edit/editOnBlur.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ function editOnBlur(editor: DraftEditor, e: SyntheticEvent): void {
// issue to be certain, checking whether the active element is `body`
// to force it when blurring occurs within the window (as opposed to
// clicking to another tab or window).
var doc = e.target && e.target.ownerDocument || document;
var doc = e.target && e.target.ownerDocument instanceof Document ?
e.target.ownerDocument :
document;
var activeElement = getActiveElement(doc);
if (isWebKit && activeElement === doc.body) {
doc.defaultView.getSelection().removeAllRanges();
Expand Down
3 changes: 2 additions & 1 deletion src/component/selection/getDraftEditorSelectionWithNodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ function getPointForNonTextNode(
// wrapper.
if (editorRoot === node) {
node = node.firstChild;
var win = node && node.ownerDocument.defaultView;
invariant(
node instanceof node.ownerDocument.defaultView.Element && node.getAttribute('data-contents') === 'true',
win && node instanceof win.Element && node.getAttribute('data-contents') === 'true',
'Invalid DraftEditorContents structure.'
);
if (childOffset > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/component/selection/getSelectionOffsetKeyForNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
function getSelectionOffsetKeyForNode(node: Node): ?string {
var win = node.ownerDocument.defaultView;
if (node instanceof win.Element) {
if (win && node instanceof win.Element) {
var offsetKey = node.getAttribute('data-offset-key');
if (offsetKey) {
return offsetKey;
Expand Down
10 changes: 5 additions & 5 deletions src/model/encoding/convertFromHTMLToContentBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ function processInlineTag(
currentStyle: DraftInlineStyle
): DraftInlineStyle {
var styleToCheck = inlineTags[tag];
var win = node.ownerDocument.defaultView;
var win = node.ownerDocument.defaultView || window;
if (styleToCheck) {
currentStyle = currentStyle.add(styleToCheck).toOrderedSet();
} else if (node instanceof win.HTMLElement) {
Expand Down Expand Up @@ -318,7 +318,7 @@ function containsSemanticBlockMarkup(
}

function hasValidLinkText(link: Node): boolean {
const win = link.ownerDocument.defaultView;
const win = link.ownerDocument.defaultView || window;
invariant(
link instanceof win.HTMLAnchorElement,
'Link must be an HTMLAnchorElement.'
Expand Down Expand Up @@ -359,7 +359,7 @@ function genFragment(
text = text.replace(REGEX_LF, SPACE);
}

// save the last block so we can use it later
// Save the last block so we can use it later
lastBlock = nodeName;

return {
Expand All @@ -373,7 +373,7 @@ function genFragment(
};
}

// save the last block so we can use it later
// Save the last block so we can use it later
lastBlock = nodeName;

// BR tags
Expand All @@ -390,7 +390,7 @@ function genFragment(
return {chunk: getSoftNewlineChunk(), entityMap};
}

const win = node.ownerDocument.defaultView;
const win = node.ownerDocument.defaultView || window;

// IMG tags
if (
Expand Down

0 comments on commit ca12190

Please sign in to comment.