Skip to content

Commit

Permalink
Implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Dec 10, 2014
1 parent f87fa81 commit 4186cc9
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

var flagsGetter = function flags() {
var str = String(this);
return str.slice(str.lastIndexOf('/') + 1);
};

var supportsDescriptors = (function () {
if (!Object.defineProperty) {
return false;
}
try {
Object.defineProperty({}, 'x', {});
return true;
} catch (e) { /* this is IE 8. */
return false;
}
}());

var flags = Function.call.bind(flagsGetter);

flags.shim = function flagsShim() {
if (!supportsDescriptors) {
throw new TypeError('RegExp.prototype.flags requires a true ES5 environment that supports property descriptors');
}
if (/a/mig.flags !== 'gim') {
Object.defineProperty(RegExp.prototype, 'flags', {
configurable: true,
enumerable: false,
get: flagsGetter
});
}
return flags;
};

module.exports = flags;

0 comments on commit 4186cc9

Please sign in to comment.