webhook-action/node_modules/es-abstract/2018/SetFunctionLength.js

30 lines
980 B
JavaScript
Raw Normal View History

'use strict';
2024-03-28 02:00:41 +00:00
var $TypeError = require('es-errors/type');
var DefinePropertyOrThrow = require('./DefinePropertyOrThrow');
var HasOwnProperty = require('./HasOwnProperty');
var IsExtensible = require('./IsExtensible');
2024-03-28 02:00:41 +00:00
var isInteger = require('../helpers/isInteger');
2022-11-10 10:43:16 +00:00
// https://262.ecma-international.org/9.0/#sec-setfunctionlength
module.exports = function SetFunctionLength(F, length) {
if (typeof F !== 'function' || !IsExtensible(F) || HasOwnProperty(F, 'length')) {
throw new $TypeError('Assertion failed: `F` must be an extensible function and lack an own `length` property');
}
2024-03-28 02:00:41 +00:00
if (typeof length !== 'number') {
throw new $TypeError('Assertion failed: `length` must be a Number');
}
2024-03-28 02:00:41 +00:00
if (length < 0 || !isInteger(length)) {
throw new $TypeError('Assertion failed: `length` must be an integer >= 0');
}
return DefinePropertyOrThrow(F, 'length', {
'[[Configurable]]': true,
'[[Enumerable]]': false,
'[[Value]]': length,
'[[Writable]]': false
});
};