source: imaps-frontend/node_modules/es-abstract/2017/SetFunctionName.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[d565449]1'use strict';
2
3var hasOwn = require('hasown');
4
5var $TypeError = require('es-errors/type');
6
7var getSymbolDescription = require('get-symbol-description');
8
9var DefinePropertyOrThrow = require('./DefinePropertyOrThrow');
10var IsExtensible = require('./IsExtensible');
11
12// https://262.ecma-international.org/6.0/#sec-setfunctionname
13
14module.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};
Note: See TracBrowser for help on using the repository browser.