paulmillr/es6-shim

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

Closed this issue · 2 comments

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);
function checkObjectCoercible(value) {
  if (value == null) { // `null` or `undefined`
    throw TypeError();
  }
  return value;
}