1 | 'use strict';
|
2 | var DESCRIPTORS = require('../internals/descriptors');
|
3 | var fails = require('../internals/fails');
|
4 | var anObject = require('../internals/an-object');
|
5 | var normalizeStringArgument = require('../internals/normalize-string-argument');
|
6 |
|
7 | var nativeErrorToString = Error.prototype.toString;
|
8 |
|
9 | var INCORRECT_TO_STRING = fails(function () {
|
10 | if (DESCRIPTORS) {
|
11 |
|
12 |
|
13 | var object = Object.create(Object.defineProperty({}, 'name', { get: function () {
|
14 | return this === object;
|
15 | } }));
|
16 | if (nativeErrorToString.call(object) !== 'true') return true;
|
17 | }
|
18 |
|
19 | return nativeErrorToString.call({ message: 1, name: 2 }) !== '2: 1'
|
20 |
|
21 | || nativeErrorToString.call({}) !== 'Error';
|
22 | });
|
23 |
|
24 | module.exports = INCORRECT_TO_STRING ? function toString() {
|
25 | var O = anObject(this);
|
26 | var name = normalizeStringArgument(O.name, 'Error');
|
27 | var message = normalizeStringArgument(O.message);
|
28 | return !name ? message : !message ? name : name + ': ' + message;
|
29 | } : nativeErrorToString;
|