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.
26 lines
1.0 KiB
26 lines
1.0 KiB
'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 n$ToString = RegExpPrototype[TO_STRING]; |
|
|
|
var NOT_GENERIC = fails(function () { return n$ToString.call({ source: 'a', flags: 'b' }) != '/a/b'; }); |
|
// FF44- RegExp#toString has a wrong name |
|
var INCORRECT_NAME = PROPER_FUNCTION_NAME && n$ToString.name != TO_STRING; |
|
|
|
// `RegExp.prototype.toString` method |
|
// https://tc39.es/ecma262/#sec-regexp.prototype.tostring |
|
if (NOT_GENERIC || INCORRECT_NAME) { |
|
defineBuiltIn(RegExp.prototype, TO_STRING, function toString() { |
|
var R = anObject(this); |
|
var pattern = $toString(R.source); |
|
var flags = $toString(getRegExpFlags(R)); |
|
return '/' + pattern + '/' + flags; |
|
}, { unsafe: true }); |
|
}
|
|
|