_fix-re-wks.js 937 B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. var hide = require('./_hide');
  3. var redefine = require('./_redefine');
  4. var fails = require('./_fails');
  5. var defined = require('./_defined');
  6. var wks = require('./_wks');
  7. module.exports = function (KEY, length, exec) {
  8. var SYMBOL = wks(KEY);
  9. var fns = exec(defined, SYMBOL, ''[KEY]);
  10. var strfn = fns[0];
  11. var rxfn = fns[1];
  12. if (fails(function () {
  13. var O = {};
  14. O[SYMBOL] = function () { return 7; };
  15. return ''[KEY](O) != 7;
  16. })) {
  17. redefine(String.prototype, KEY, strfn);
  18. hide(RegExp.prototype, SYMBOL, length == 2
  19. // 21.2.5.8 RegExp.prototype[@@replace](string, replaceValue)
  20. // 21.2.5.11 RegExp.prototype[@@split](string, limit)
  21. ? function (string, arg) { return rxfn.call(string, this, arg); }
  22. // 21.2.5.6 RegExp.prototype[@@match](string)
  23. // 21.2.5.9 RegExp.prototype[@@search](string)
  24. : function (string) { return rxfn.call(string, this); }
  25. );
  26. }
  27. };