$.fix-re-wks.js 912 B

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