es6.regexp.to-string.js 826 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. require('./es6.regexp.flags');
  3. var anObject = require('./_an-object');
  4. var $flags = require('./_flags');
  5. var DESCRIPTORS = require('./_descriptors');
  6. var TO_STRING = 'toString';
  7. var $toString = /./[TO_STRING];
  8. var define = function (fn) {
  9. require('./_redefine')(RegExp.prototype, TO_STRING, fn, true);
  10. };
  11. // 21.2.5.14 RegExp.prototype.toString()
  12. if (require('./_fails')(function () { return $toString.call({ source: 'a', flags: 'b' }) != '/a/b'; })) {
  13. define(function toString() {
  14. var R = anObject(this);
  15. return '/'.concat(R.source, '/',
  16. 'flags' in R ? R.flags : !DESCRIPTORS && R instanceof RegExp ? $flags.call(R) : undefined);
  17. });
  18. // FF44- RegExp#toString has a wrong name
  19. } else if ($toString.name != TO_STRING) {
  20. define(function toString() {
  21. return $toString.call(this);
  22. });
  23. }