1 |
3a515b92
|
cagy
|
'use strict';
|
2 |
|
|
|
3 |
|
|
var GetIntrinsic = require('../GetIntrinsic');
|
4 |
|
|
|
5 |
|
|
var has = require('has');
|
6 |
|
|
|
7 |
|
|
var $TypeError = GetIntrinsic('%TypeError%');
|
8 |
|
|
|
9 |
|
|
var getSymbolDescription = require('../helpers/getSymbolDescription');
|
10 |
|
|
|
11 |
|
|
var DefinePropertyOrThrow = require('./DefinePropertyOrThrow');
|
12 |
|
|
var IsExtensible = require('./IsExtensible');
|
13 |
|
|
var Type = require('./Type');
|
14 |
|
|
|
15 |
|
|
// https://ecma-international.org/ecma-262/6.0/#sec-setfunctionname
|
16 |
|
|
|
17 |
|
|
module.exports = function SetFunctionName(F, name) {
|
18 |
|
|
if (typeof F !== 'function') {
|
19 |
|
|
throw new $TypeError('Assertion failed: `F` must be a function');
|
20 |
|
|
}
|
21 |
|
|
if (!IsExtensible(F) || has(F, 'name')) {
|
22 |
|
|
throw new $TypeError('Assertion failed: `F` must be extensible, and must not have a `name` own property');
|
23 |
|
|
}
|
24 |
|
|
var nameType = Type(name);
|
25 |
|
|
if (nameType !== 'Symbol' && nameType !== 'String') {
|
26 |
|
|
throw new $TypeError('Assertion failed: `name` must be a Symbol or a String');
|
27 |
|
|
}
|
28 |
|
|
if (nameType === 'Symbol') {
|
29 |
|
|
var description = getSymbolDescription(name);
|
30 |
|
|
// eslint-disable-next-line no-param-reassign
|
31 |
|
|
name = typeof description === 'undefined' ? '' : '[' + description + ']';
|
32 |
|
|
}
|
33 |
|
|
if (arguments.length > 2) {
|
34 |
|
|
var prefix = arguments[2];
|
35 |
|
|
// eslint-disable-next-line no-param-reassign
|
36 |
|
|
name = prefix + ' ' + name;
|
37 |
|
|
}
|
38 |
|
|
return DefinePropertyOrThrow(F, 'name', {
|
39 |
|
|
'[[Value]]': name,
|
40 |
|
|
'[[Writable]]': false,
|
41 |
|
|
'[[Enumerable]]': false,
|
42 |
|
|
'[[Configurable]]': true
|
43 |
|
|
});
|
44 |
|
|
};
|