-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generalize setting / fixing regex / string well-known symbols, #83
- Loading branch information
Showing
8 changed files
with
94 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module.exports = function(KEY, exec){ | ||
var SYMBOL = require('./$.wks')(KEY) | ||
, methods = exec(SYMBOL, ''[KEY]); | ||
if(function(){ | ||
try { | ||
var O = {}; | ||
O[SYMBOL] = function(){ return 7; }; | ||
return ''[KEY](O) != 7; | ||
} catch(e){ | ||
return true; | ||
} | ||
}()){ | ||
require('./$.redef')(String.prototype, KEY, methods[0]); | ||
require('./$').hide(RegExp.prototype, SYMBOL, methods[1]); | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module.exports = function(KEY, exec){ | ||
var SYMBOL = require('./$.wks')(KEY) | ||
, methods = exec(SYMBOL, ''[KEY]); | ||
if(function(){ | ||
try { | ||
var O = {}; | ||
O[SYMBOL] = function(){ return 7; }; | ||
return ''[KEY](O) != 7; | ||
} catch(e){ | ||
return true; | ||
} | ||
}()){ | ||
require('./$.redef')(String.prototype, KEY, methods[0]); | ||
require('./$').hide(RegExp.prototype, SYMBOL, methods[1]); | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
if(require('./$.need-fix-re-wks')('match')){ | ||
var $match = ''.match | ||
, MATCH = require('./$.wks')('match'); | ||
// 21.1.3.11 String.prototype.match(regexp) | ||
require('./$.redef')(String.prototype, 'match', function match(regexp){ | ||
var str = String(this) | ||
, fn = regexp == undefined ? undefined : regexp[MATCH]; | ||
return fn !== undefined ? fn.call(regexp, str) : new RegExp(regexp)[MATCH](str); | ||
}); | ||
// 21.2.5.6 RegExp.prototype[@@match](string) | ||
require('./$').hide(RegExp.prototype, MATCH, function(string){ | ||
return $match.call(string, this); | ||
}); | ||
} | ||
// @@match logic | ||
require('./$.fix-re-wks')('match', function(MATCH, $match){ | ||
return [ | ||
// 21.1.3.11 String.prototype.match(regexp) | ||
function match(regexp){ | ||
var str = String(this) | ||
, fn = regexp == undefined ? undefined : regexp[MATCH]; | ||
return fn !== undefined ? fn.call(regexp, str) : new RegExp(regexp)[MATCH](str); | ||
}, | ||
// 21.2.5.6 RegExp.prototype[@@match](string) | ||
function(string){ | ||
return $match.call(string, this); | ||
} | ||
]; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
if(require('./$.need-fix-re-wks')('replace')){ | ||
var $replace = ''.replace | ||
, REPLACE = require('./$.wks')('replace'); | ||
// 21.1.3.14 String.prototype.replace(searchValue, replaceValue) | ||
require('./$.redef')(String.prototype, 'replace', function replace(searchValue, replaceValue){ | ||
var str = String(this) | ||
, fn = searchValue == undefined ? undefined : searchValue[REPLACE]; | ||
return fn !== undefined | ||
? fn.call(searchValue, str, replaceValue) | ||
: $replace.call(str, searchValue, replaceValue); | ||
}); | ||
// 21.2.5.8 RegExp.prototype[@@replace](string, replaceValue) | ||
require('./$').hide(RegExp.prototype, REPLACE, function(string, replaceValue){ | ||
return $replace.call(string, this, replaceValue); | ||
}); | ||
} | ||
// @@replace logic | ||
require('./$.fix-re-wks')('replace', function(REPLACE, $replace){ | ||
return [ | ||
// 21.1.3.14 String.prototype.replace(searchValue, replaceValue) | ||
function replace(searchValue, replaceValue){ | ||
var str = String(this) | ||
, fn = searchValue == undefined ? undefined : searchValue[REPLACE]; | ||
return fn !== undefined | ||
? fn.call(searchValue, str, replaceValue) | ||
: $replace.call(str, searchValue, replaceValue); | ||
}, | ||
// 21.2.5.8 RegExp.prototype[@@replace](string, replaceValue) | ||
function(string, replaceValue){ | ||
return $replace.call(string, this, replaceValue); | ||
} | ||
]; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
if(require('./$.need-fix-re-wks')('search')){ | ||
var $search = ''.search | ||
, SEARCH = require('./$.wks')('search'); | ||
// 21.1.3.15 String.prototype.search(regexp) | ||
require('./$.redef')(String.prototype, 'search', function search(regexp){ | ||
var str = String(this) | ||
, fn = regexp == undefined ? undefined : regexp[SEARCH]; | ||
return fn !== undefined ? fn.call(regexp, str) : new RegExp(regexp)[SEARCH](str); | ||
}); | ||
// 21.2.5.9 RegExp.prototype[@@search](string) | ||
require('./$').hide(RegExp.prototype, SEARCH, function(string){ | ||
return $search.call(string, this); | ||
}); | ||
} | ||
// @@search logic | ||
require('./$.fix-re-wks')('search', function(SEARCH, $search){ | ||
return [ | ||
// 21.1.3.15 String.prototype.search(regexp) | ||
function search(regexp){ | ||
var str = String(this) | ||
, fn = regexp == undefined ? undefined : regexp[SEARCH]; | ||
return fn !== undefined ? fn.call(regexp, str) : new RegExp(regexp)[SEARCH](str); | ||
}, | ||
// 21.2.5.9 RegExp.prototype[@@search](string) | ||
function(string){ | ||
return $search.call(string, this); | ||
} | ||
]; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
if(require('./$.need-fix-re-wks')('split')){ | ||
var $split = ''.split | ||
, SPLIT = require('./$.wks')('split'); | ||
// 21.1.3.17 String.prototype.split(separator, limit) | ||
require('./$.redef')(String.prototype, 'split', function split(separator, limit){ | ||
var str = String(this) | ||
, fn = separator == undefined ? undefined : separator[SPLIT]; | ||
return fn !== undefined ? fn.call(separator, str, limit) : $split.call(str, separator, limit); | ||
}); | ||
// 21.2.5.11 RegExp.prototype[@@split](string, limit) | ||
require('./$').hide(RegExp.prototype, SPLIT, function(string, limit){ | ||
return $split.call(string, this, limit); | ||
}); | ||
} | ||
// @@split logic | ||
require('./$.fix-re-wks')('split', function(SPLIT, $split){ | ||
return [ | ||
// 21.1.3.17 String.prototype.split(separator, limit) | ||
function split(separator, limit){ | ||
var str = String(this) | ||
, fn = separator == undefined ? undefined : separator[SPLIT]; | ||
return fn !== undefined ? fn.call(separator, str, limit) : $split.call(str, separator, limit); | ||
}, | ||
// 21.2.5.11 RegExp.prototype[@@split](string, limit) | ||
function(string, limit){ | ||
return $split.call(string, this, limit); | ||
} | ||
]; | ||
}); |