-
Notifications
You must be signed in to change notification settings - Fork 450
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
fix: Uncaught TypeError: Illegal invocation in chrome 51 #290
Conversation
in chrome 51, will throw error Uncaught TypeError: Illegal invocation
lib/logger/logger.js
Outdated
@@ -15,7 +15,7 @@ Logger.prototype.setMethods = function (overrides) { | |||
|
|||
SUPPORTED_METHODS.forEach(function (method) { | |||
if (typeof overrides[method] === 'function') { | |||
logger[method] = overrides[method]; | |||
logger[method] = overrides[method].bind(overrides); |
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.
Nice, but shouldn't this be:
logger[method] = overrides[method].bind(overrides); | |
logger[method] = overrides[method].bind(overrides[method]); |
And by that point, maybe we can tidy up the loop a bit:
SUPPORTED_METHODS.forEach(function (method) {
var override = overrides[method];
if (typeof override === 'function') {
logger[method] = override.bind(override);
}
});
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.
should be this:
SUPPORTED_METHODS.forEach(function (method) {
var override = overrides[method];
if (typeof override === 'function') {
logger[method] = override.bind(overrides);
}
});
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.
Why bind to the object of overrides rather than the function itself? Or actually, maybe more accurate would be:
logger[method] = override.bind(logger);
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.
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.
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.
You're getting that error because of this issue with Chrome. The correct thing to do is:
var logger = {};
var override = console.log.bind(console);
logger.log = override;
logger.log('test');
I'm closing this, because the correct usage should be: ShareDB.logger.setMethods({
log: console.log.bind(console),
}); |
Sorry, I just realised you mean this happens with the default I'm not sure that arbitrarily setting the function Logger() {
var defaultMethods = {};
SUPPORTED_METHODS.forEach(function (method) {
// Deal with Chrome issue: https://bugs.chromium.org/p/chromium/issues/detail?id=179628
defaultMethods[method] = console[method].bind(console);
});
this.setMethods(defaultMethods);
} |
@alecgibson Yes, I mean the default logger.. 😄 |
Deal with Chrome issue: https://bugs.chromium.org/p/chromium/issues/detail?id=179628
Thanks! Published in [email protected] |
in chrome 51, will throw error