Skip to content
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

Preemptively error when required ES5 shim/shams are not available #1516

Merged
merged 1 commit into from
May 12, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/browser/ui/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,34 @@ if (__DEV__) {
'Download the React DevTools for a better development experience: ' +
'http://fb.me/react-devtools'
);

var expectedFeatures = [
// shims
Array.isArray,
Array.prototype.every,
Array.prototype.forEach,
Array.prototype.indexOf,
Array.prototype.map,
Date.now,
Function.prototype.bind,
Object.keys,
String.prototype.split,

// shams
Object.create,
Object.freeze
];

for (var i in expectedFeatures) {
if (!expectedFeatures[i]) {
console.error(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just sanity check: console.error() is available everywhere console is available, right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

95% sure yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petehunt Yes it is, even IE8 has it. While it is possible that some browser does not have it, it will still produce an appropriate error message (console.error not available) and we explicitly mention it next to the shims that the console.*-shim might be necessary. I could do (console.error || console.log) I guess to be on the really safe side, if you prefer (and add appropriate console.* methods to the list).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petehunt PS, you probably want to fb.me that link.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'One or more ES5 shim/shams expected by React are not available: ' +
'http://facebook.github.io/react/docs/working-with-the-browser.html' +
'#polyfills-needed-to-support-older-browsers'
);
break;
}
}
}
}

Expand Down