'use strict';
module.exports = function(KEY, length, exec){
  var SYMBOL   = require('./$.wks')(KEY)
    , original = ''[KEY];
  if(function(){
    try {
      var O = {};
      O[SYMBOL] = function(){ return 7; };
      return ''[KEY](O) != 7;
    } catch(e){
      return true;
    }
  }()){
    require('./$.redef')(String.prototype, KEY, exec(SYMBOL, original));
    require('./$.hide')(RegExp.prototype, SYMBOL, length == 2
      // 21.2.5.8 RegExp.prototype[@@replace](string, replaceValue)
      // 21.2.5.11 RegExp.prototype[@@split](string, limit)
      ? function(string, arg){ return original.call(string, this, arg); }
      // 21.2.5.6 RegExp.prototype[@@match](string)
      // 21.2.5.9 RegExp.prototype[@@search](string)
      : function(string){ return original.call(string, this); }
    );
  }
};