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

String#repeat called on undefined or null should throw #164

Closed
mathiasbynens opened this issue Dec 10, 2013 · 2 comments · Fixed by #165
Closed

String#repeat called on undefined or null should throw #164

mathiasbynens opened this issue Dec 10, 2013 · 2 comments · Fixed by #165
Labels

Comments

@mathiasbynens
Copy link
Contributor

This implementation fails the following tests taken from https://github.com/mathiasbynens/String.prototype.repeat/blob/master/tests/tests.js:

assertThrows(function() { String.prototype.repeat.call(undefined); }, TypeError);
assertThrows(function() { String.prototype.repeat.call(undefined, 4); }, TypeError);
assertThrows(function() { String.prototype.repeat.call(null); }, TypeError);
assertThrows(function() { String.prototype.repeat.call(null, 4); }, TypeError);

assertThrows(function() { String.prototype.repeat.apply(undefined); }, TypeError);
assertThrows(function() { String.prototype.repeat.apply(undefined, [4]); }, TypeError);
assertThrows(function() { String.prototype.repeat.apply(null); }, TypeError);
assertThrows(function() { String.prototype.repeat.apply(null, [4]); }, TypeError);
@paulmillr
Copy link
Owner

@mathiasbynens
Copy link
Contributor Author

function checkObjectCoercible(value) {
  if (value == null) { // `null` or `undefined`
    throw TypeError();
  }
  return value;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants