2021-02-26 04:58:33 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var GetIntrinsic = require('get-intrinsic');
|
|
|
|
|
|
|
|
var $TypeError = GetIntrinsic('%TypeError%');
|
|
|
|
|
|
|
|
var DefinePropertyOrThrow = require('./DefinePropertyOrThrow');
|
|
|
|
var HasOwnProperty = require('./HasOwnProperty');
|
|
|
|
var IsExtensible = require('./IsExtensible');
|
|
|
|
var IsNonNegativeInteger = require('./IsNonNegativeInteger');
|
|
|
|
var Type = require('./Type');
|
|
|
|
|
2022-11-10 11:43:16 +01:00
|
|
|
// https://262.ecma-international.org/11.0/#sec-setfunctionlength
|
2021-02-26 04:58:33 +01:00
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
if (Type(length) !== 'Number') {
|
|
|
|
throw new $TypeError('Assertion failed: `length` must be a Number');
|
|
|
|
}
|
|
|
|
if (!IsNonNegativeInteger(length)) {
|
|
|
|
throw new $TypeError('Assertion failed: `length` must be an integer >= 0');
|
|
|
|
}
|
|
|
|
return DefinePropertyOrThrow(F, 'length', {
|
|
|
|
'[[Configurable]]': true,
|
|
|
|
'[[Enumerable]]': false,
|
|
|
|
'[[Value]]': length,
|
|
|
|
'[[Writable]]': false
|
|
|
|
});
|
|
|
|
};
|