diff --git a/es6-shim.js b/es6-shim.js index 369ebba6..95ef318f 100644 --- a/es6-shim.js +++ b/es6-shim.js @@ -613,7 +613,13 @@ }, includes: function includes(searchString) { - var position = arguments.length > 1 ? arguments[1] : void 0; + if (Type.regex(searchString)) { + throw new TypeError('"includes" does not accept a RegExp'); + } + var position; + if (arguments.length > 1) { + position = arguments[1]; + } // Somehow this trick makes method 100% compat with the spec. return _indexOf(this, searchString, position) !== -1; }, diff --git a/test/string.js b/test/string.js index cab71e7e..a1feae5d 100644 --- a/test/string.js +++ b/test/string.js @@ -315,6 +315,10 @@ var runStringTests = function () { testObjectCoercible('includes'); }); + it('throws a TypeError when given a regex', function () { + expect(function () { 'foo'.includes(/a/g); }).to['throw'](TypeError); + }); + it('should be truthy on correct results', function () { expect('test'.includes('es')).to.equal(true); expect('abc'.includes('a')).to.equal(true);