-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't assume HTMLElement is in the global scope #91
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d124dbd
Don't assume HTMLElement is in the global scope
jetpacmonkey a0e89b7
More strenuous checks for if we're in a browser env
jetpacmonkey b65aa15
style: Make the linter happy
jetpacmonkey 9b2d462
clean up code
keithamus 5336711
fix up eslint workarounds
keithamus 5eb1885
fix up eval hacks to get "this"
keithamus 21ce92b
safely get window object without eval
keithamus b610c22
remove globalObject = window
keithamus c426e32
simplify `isDom` definition
shvaikalesh 971ce2c
style(lint): re-enable no-undef rule inside index.js
keithamus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,29 @@ | ||
'use strict'; | ||
|
||
/* ! | ||
* type-detect | ||
* Copyright(c) 2013 jake luer <jake@alogicalparadox.com> | ||
* MIT Licensed | ||
*/ | ||
var promiseExists = typeof Promise === 'function'; | ||
var globalObject = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : self; // eslint-disable-line | ||
var isDom = 'location' in globalObject && 'document' in globalObject; | ||
|
||
/* eslint-disable no-undef */ | ||
var isDom = false; | ||
var globalObject = typeof self === 'object' ? self : global; // eslint-disable-line id-blacklist | ||
|
||
/* | ||
* All of these attributes must be available on the global object for the current environment | ||
* to be considered a DOM environment (browser) | ||
*/ | ||
if (typeof window === 'object' && | ||
'document' in window && | ||
'navigator' in window && | ||
'HTMLElement' in window | ||
) { | ||
isDom = true; | ||
globalObject = window; // eslint-disable-line no-undef | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can remove this line: if we have |
||
} | ||
|
||
var symbolExists = typeof Symbol !== 'undefined'; | ||
var mapExists = typeof Map !== 'undefined'; | ||
var setExists = typeof Set !== 'undefined'; | ||
|
@@ -156,7 +173,7 @@ module.exports = function typeDetect(obj) { | |
* Test: `Object.prototype.toString.call(document.createElement('blockquote'))`` | ||
* - IE <=10 === "[object HTMLBlockElement]" | ||
*/ | ||
if (obj instanceof HTMLElement && obj.tagName === 'BLOCKQUOTE') { | ||
if (obj instanceof globalObject.HTMLElement && obj.tagName === 'BLOCKQUOTE') { | ||
return 'HTMLQuoteElement'; | ||
} | ||
|
||
|
@@ -172,7 +189,7 @@ module.exports = function typeDetect(obj) { | |
* - Firefox === "[object HTMLTableCellElement]" | ||
* - Safari === "[object HTMLTableCellElement]" | ||
*/ | ||
if (obj instanceof HTMLElement && obj.tagName === 'TD') { | ||
if (obj instanceof globalObject.HTMLElement && obj.tagName === 'TD') { | ||
return 'HTMLTableDataCellElement'; | ||
} | ||
|
||
|
@@ -188,7 +205,7 @@ module.exports = function typeDetect(obj) { | |
* - Firefox === "[object HTMLTableCellElement]" | ||
* - Safari === "[object HTMLTableCellElement]" | ||
*/ | ||
if (obj instanceof HTMLElement && obj.tagName === 'TH') { | ||
if (obj instanceof globalObject.HTMLElement && obj.tagName === 'TH') { | ||
return 'HTMLTableHeaderCellElement'; | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, forgot to re-enable this one. Can't right now - but will get to it later.