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