import { __require as requireGetIntrinsic } from "../../get-intrinsic/index.js";
import { __require as requireRange } from "../../es-errors/range.js";
import { __require as requireSyntax } from "../../es-errors/syntax.js";
import { __require as requireType } from "../../es-errors/type.js";
import { __require as requireIsInteger } from "../../math-intrinsics/isInteger.js";
import { __require as requireMaxArrayLength } from "../../math-intrinsics/constants/maxArrayLength.js";
import { __require as requireSetProto } from "../../set-proto/index.js";
var ArrayCreate;
var hasRequiredArrayCreate;
function requireArrayCreate() {
  if (hasRequiredArrayCreate) return ArrayCreate;
  hasRequiredArrayCreate = 1;
  var GetIntrinsic = requireGetIntrinsic();
  var $ArrayPrototype = GetIntrinsic("%Array.prototype%");
  var $RangeError = requireRange();
  var $SyntaxError = requireSyntax();
  var $TypeError = requireType();
  var isInteger = requireIsInteger();
  var MAX_ARRAY_LENGTH = requireMaxArrayLength();
  var $setProto = requireSetProto();
  ArrayCreate = function ArrayCreate2(length) {
    if (!isInteger(length) || length < 0) {
      throw new $TypeError("Assertion failed: `length` must be an integer Number >= 0");
    }
    if (length > MAX_ARRAY_LENGTH) {
      throw new $RangeError("length is greater than (2**32 - 1)");
    }
    var proto = arguments.length > 1 ? arguments[1] : $ArrayPrototype;
    var A = [];
    if (proto !== $ArrayPrototype) {
      if (!$setProto) {
        throw new $SyntaxError("ArrayCreate: a `proto` argument that is not `Array.prototype` is not supported in an environment that does not support setting the [[Prototype]]");
      }
      $setProto(A, proto);
    }
    if (length !== 0) {
      A.length = length;
    }
    return A;
  };
  return ArrayCreate;
}
export {
  requireArrayCreate as __require
};
