Last change
on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Line | |
---|
1 | 'use strict';
|
---|
2 | var redefine = require('../internals/redefine');
|
---|
3 | var anObject = require('../internals/an-object');
|
---|
4 | var $toString = require('../internals/to-string');
|
---|
5 | var fails = require('../internals/fails');
|
---|
6 | var flags = require('../internals/regexp-flags');
|
---|
7 |
|
---|
8 | var TO_STRING = 'toString';
|
---|
9 | var RegExpPrototype = RegExp.prototype;
|
---|
10 | var nativeToString = RegExpPrototype[TO_STRING];
|
---|
11 |
|
---|
12 | var NOT_GENERIC = fails(function () { return nativeToString.call({ source: 'a', flags: 'b' }) != '/a/b'; });
|
---|
13 | // FF44- RegExp#toString has a wrong name
|
---|
14 | var INCORRECT_NAME = nativeToString.name != TO_STRING;
|
---|
15 |
|
---|
16 | // `RegExp.prototype.toString` method
|
---|
17 | // https://tc39.es/ecma262/#sec-regexp.prototype.tostring
|
---|
18 | if (NOT_GENERIC || INCORRECT_NAME) {
|
---|
19 | redefine(RegExp.prototype, TO_STRING, function toString() {
|
---|
20 | var R = anObject(this);
|
---|
21 | var p = $toString(R.source);
|
---|
22 | var rf = R.flags;
|
---|
23 | var f = $toString(rf === undefined && R instanceof RegExp && !('flags' in RegExpPrototype) ? flags.call(R) : rf);
|
---|
24 | return '/' + p + '/' + f;
|
---|
25 | }, { unsafe: true });
|
---|
26 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.