mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-23 00:45:16 +00:00
27 lines
1.0 KiB
JavaScript
27 lines
1.0 KiB
JavaScript
|
'use strict';
|
||
|
var redefine = require('../internals/redefine');
|
||
|
var anObject = require('../internals/an-object');
|
||
|
var $toString = require('../internals/to-string');
|
||
|
var fails = require('../internals/fails');
|
||
|
var flags = require('../internals/regexp-flags');
|
||
|
|
||
|
var TO_STRING = 'toString';
|
||
|
var RegExpPrototype = RegExp.prototype;
|
||
|
var nativeToString = RegExpPrototype[TO_STRING];
|
||
|
|
||
|
var NOT_GENERIC = fails(function () { return nativeToString.call({ source: 'a', flags: 'b' }) != '/a/b'; });
|
||
|
// FF44- RegExp#toString has a wrong name
|
||
|
var INCORRECT_NAME = nativeToString.name != TO_STRING;
|
||
|
|
||
|
// `RegExp.prototype.toString` method
|
||
|
// https://tc39.es/ecma262/#sec-regexp.prototype.tostring
|
||
|
if (NOT_GENERIC || INCORRECT_NAME) {
|
||
|
redefine(RegExp.prototype, TO_STRING, function toString() {
|
||
|
var R = anObject(this);
|
||
|
var p = $toString(R.source);
|
||
|
var rf = R.flags;
|
||
|
var f = $toString(rf === undefined && R instanceof RegExp && !('flags' in RegExpPrototype) ? flags.call(R) : rf);
|
||
|
return '/' + p + '/' + f;
|
||
|
}, { unsafe: true });
|
||
|
}
|