Version 1
[yaffs-website] / node_modules / core-js / modules / _fix-re-wks.js
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
8 module.exports = function(KEY, length, exec){
9   var SYMBOL   = wks(KEY)
10     , fns      = exec(defined, SYMBOL, ''[KEY])
11     , strfn    = fns[0]
12     , rxfn     = fns[1];
13   if(fails(function(){
14     var O = {};
15     O[SYMBOL] = function(){ return 7; };
16     return ''[KEY](O) != 7;
17   })){
18     redefine(String.prototype, KEY, strfn);
19     hide(RegExp.prototype, SYMBOL, length == 2
20       // 21.2.5.8 RegExp.prototype[@@replace](string, replaceValue)
21       // 21.2.5.11 RegExp.prototype[@@split](string, limit)
22       ? function(string, arg){ return rxfn.call(string, this, arg); }
23       // 21.2.5.6 RegExp.prototype[@@match](string)
24       // 21.2.5.9 RegExp.prototype[@@search](string)
25       : function(string){ return rxfn.call(string, this); }
26     );
27   }
28 };