Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion src/jsutils/instanceOf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,41 @@ declare function instanceOf(
constructor: mixed,
): boolean %checks(value instanceof constructor);

function getGlobal() {
/* global window self */
if (
typeof self !== 'undefined' &&
self.self === self &&
self.Array === Array &&
self.setInterval === setInterval
) {
return self;
}
if (
typeof window !== 'undefined' &&
window.window === window &&
window.Array === Array &&
window.setInterval === setInterval
) {
return window;
}
if (
typeof global !== 'undefined' &&
global.global === global &&
global.Array === Array &&
global.setInterval === setInterval
) {
return global;
}
throw new Error('Cannot find the global object');
}

const production =
getGlobal().process && getGlobal().process.env.NODE_ENV === 'production';

// See: https://expressjs.com/en/advanced/best-practice-performance.html#set-node_env-to-production
// See: https://webpack.js.org/guides/production/
export default (process.env.NODE_ENV === 'production'
export default (production
? // eslint-disable-next-line no-shadow
function instanceOf(value: mixed, constructor: mixed) {
return value instanceof constructor;
Expand Down