Skip to content

Commit

Permalink
RegExp() should not throw. Fixes #350.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jun 17, 2015
1 parent 7b27b38 commit e7a8904
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,9 @@
var OrigRegExp = RegExp;
var RegExpShim = function RegExp(pattern, flags) {
var calledWithNew = this instanceof RegExp;
if (!calledWithNew && (Type.regex(pattern) || pattern.constructor === RegExp)) {
if (!calledWithNew && arguments.length === 0) {
return new RegExp();
} else if (!calledWithNew && (Type.regex(pattern) || pattern.constructor === RegExp)) {
return pattern;
}
if (Type.regex(pattern) && Type.string(flags)) {
Expand Down
6 changes: 6 additions & 0 deletions test/regexp.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ describe('RegExp', function () {
expect(exported.RegExp).to.equal(RegExp);
});

it('can be called with no arguments', function () {
var regex = RegExp();
expect(String(regex)).to.equal(String(RegExp.prototype));
expect(regex).to.be.an.instanceOf(RegExp);
});

describe('constructor', function () {
it('allows a regex as the pattern', function () {
var a = /a/g;
Expand Down

0 comments on commit e7a8904

Please sign in to comment.