"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const index$1 = require("../get-intrinsic/index.cjs");
const index$2 = require("../define-data-property/index.cjs");
const index = require("../has-property-descriptors/index.cjs");
const index$3 = require("../gopd/index.cjs");
const type = require("../es-errors/type.cjs");
var GetIntrinsic = index$1.getIntrinsic;
var define = index$2.defineDataProperty;
var hasDescriptors = index.hasPropertyDescriptors_1();
var gOPD = index$3.gopd;
var $TypeError = type.type;
var $floor = GetIntrinsic("%Math.floor%");
var setFunctionLength = function setFunctionLength2(fn, length) {
  if (typeof fn !== "function") {
    throw new $TypeError("`fn` is not a function");
  }
  if (typeof length !== "number" || length < 0 || length > 4294967295 || $floor(length) !== length) {
    throw new $TypeError("`length` must be a positive 32-bit integer");
  }
  var loose = arguments.length > 2 && !!arguments[2];
  var functionLengthIsConfigurable = true;
  var functionLengthIsWritable = true;
  if ("length" in fn && gOPD) {
    var desc = gOPD(fn, "length");
    if (desc && !desc.configurable) {
      functionLengthIsConfigurable = false;
    }
    if (desc && !desc.writable) {
      functionLengthIsWritable = false;
    }
  }
  if (functionLengthIsConfigurable || functionLengthIsWritable || !loose) {
    if (hasDescriptors) {
      define(
        /** @type {Parameters<define>[0]} */
        fn,
        "length",
        length,
        true,
        true
      );
    } else {
      define(
        /** @type {Parameters<define>[0]} */
        fn,
        "length",
        length
      );
    }
  }
  return fn;
};
exports.setFunctionLength = setFunctionLength;
//# sourceMappingURL=index.cjs.map
