You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
1.1 KiB
27 lines
1.1 KiB
2 weeks ago
|
'use strict';
|
||
|
var PROPER_FUNCTION_NAME = require('../internals/function-name').PROPER;
|
||
|
var defineBuiltIn = require('../internals/define-built-in');
|
||
|
var anObject = require('../internals/an-object');
|
||
|
var $toString = require('../internals/to-string');
|
||
|
var fails = require('../internals/fails');
|
||
|
var getRegExpFlags = require('../internals/regexp-get-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 = PROPER_FUNCTION_NAME && nativeToString.name !== TO_STRING;
|
||
|
|
||
|
// `RegExp.prototype.toString` method
|
||
|
// https://tc39.es/ecma262/#sec-regexp.prototype.tostring
|
||
|
if (NOT_GENERIC || INCORRECT_NAME) {
|
||
|
defineBuiltIn(RegExpPrototype, TO_STRING, function toString() {
|
||
|
var R = anObject(this);
|
||
|
var pattern = $toString(R.source);
|
||
|
var flags = $toString(getRegExpFlags(R));
|
||
|
return '/' + pattern + '/' + flags;
|
||
|
}, { unsafe: true });
|
||
|
}
|