aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Liz <accs@liz3.net> 2023-10-09 20:47:38 +0200
committerGravatar GitHub <noreply@github.com> 2023-10-09 11:47:38 -0700
commita9e1792607fea89944526ed5478a3a82db2932eb (patch)
tree8a0248b8d1f68ff3f2bd60eaebd825ea4107a080
parent0965e6ddfd48b2e0e44c2efce7d9fc24115ef63e (diff)
downloadbun-a9e1792607fea89944526ed5478a3a82db2932eb.tar.gz
bun-a9e1792607fea89944526ed5478a3a82db2932eb.tar.zst
bun-a9e1792607fea89944526ed5478a3a82db2932eb.zip
fix: support uint8 exit code range (#6303)
The exit code support is between 0-255 and not only in the signed positive range (0-127). Node.js does not seam to throw on a bigger integer and just wraps around, but throwing a error is a good approach and makes the behaviour more defined. This allows the range to be 0-255 Fixes: https://github.com/oven-sh/bun/issues/6284
-rw-r--r--src/bun.js/bindings/Process.cpp4
-rw-r--r--test/js/node/process/process.test.js9
2 files changed, 11 insertions, 2 deletions
diff --git a/src/bun.js/bindings/Process.cpp b/src/bun.js/bindings/Process.cpp
index 1caff9be9..fd194f547 100644
--- a/src/bun.js/bindings/Process.cpp
+++ b/src/bun.js/bindings/Process.cpp
@@ -749,8 +749,8 @@ JSC_DEFINE_CUSTOM_SETTER(setProcessExitCode, (JSC::JSGlobalObject * lexicalGloba
int exitCodeInt = exitCode.toInt32(lexicalGlobalObject);
RETURN_IF_EXCEPTION(throwScope, false);
- if (exitCodeInt < 0 || exitCodeInt > 127) {
- throwRangeError(lexicalGlobalObject, throwScope, "exitCode must be between 0 and 127"_s);
+ if (exitCodeInt < 0 || exitCodeInt > 255) {
+ throwRangeError(lexicalGlobalObject, throwScope, "exitCode must be between 0 and 255"_s);
return false;
}
diff --git a/test/js/node/process/process.test.js b/test/js/node/process/process.test.js
index 4fb678dce..fd91fdef5 100644
--- a/test/js/node/process/process.test.js
+++ b/test/js/node/process/process.test.js
@@ -263,6 +263,15 @@ describe("process.exitCode", () => {
});
});
+it("process exitCode range (#6284)", () => {
+ const { exitCode, stdout } = spawnSync({
+ cmd: [bunExe(), join(import.meta.dir, "process-exitCode-fixture.js"), "255"],
+ env: bunEnv,
+ });
+ expect(exitCode).toBe(255);
+ expect(stdout.toString().trim()).toBe("PASS");
+});
+
it("process.exit", () => {
const { exitCode, stdout } = spawnSync({
cmd: [bunExe(), join(import.meta.dir, "process-exit-fixture.js")],