"use strict";
/* Socket Lib - Built with esbuild */
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var intercept_exports = {};
__export(intercept_exports, {
  processEmit: () => processEmit,
  processReallyExit: () => processReallyExit
});
module.exports = __toCommonJS(intercept_exports);
var import_error = require("../primordials/error");
var import_reflect = require("../primordials/reflect");
var import_internal = require("./_internal");
// @__NO_SIDE_EFFECTS__
function processEmit(eventName, exitCode, ...args) {
  if (eventName === "exit") {
    let actualExitCode = exitCode;
    if (actualExitCode === void 0) {
      const processExitCode = import_internal.globalProcess?.exitCode;
      actualExitCode = typeof processExitCode === "number" ? processExitCode : void 0;
    } else if (import_internal.globalProcess) {
      import_internal.globalProcess.exitCode = actualExitCode;
    }
    const result = (0, import_reflect.ReflectApply)(
      import_internal.originalProcessEmit,
      this,
      [eventName, actualExitCode, ...args]
    );
    const numExitCode = typeof actualExitCode === "number" ? actualExitCode : void 0;
    (0, import_internal.emit)("exit", numExitCode, void 0);
    (0, import_internal.emit)("afterexit", numExitCode, void 0);
    return result;
  }
  return (0, import_reflect.ReflectApply)(
    import_internal.originalProcessEmit,
    this,
    [eventName, exitCode, ...args]
  );
}
// @__NO_SIDE_EFFECTS__
function processReallyExit(code) {
  const exitCode = code || 0;
  if (import_internal.globalProcess) {
    import_internal.globalProcess.exitCode = exitCode;
  }
  (0, import_internal.emit)("exit", exitCode, void 0);
  (0, import_internal.emit)("afterexit", exitCode, void 0);
  (0, import_reflect.ReflectApply)(
    import_internal.originalProcessReallyExit,
    import_internal.globalProcess,
    [exitCode]
  );
  throw new import_error.ErrorCtor("processReallyExit should never return");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  processEmit,
  processReallyExit
});
