Compare commits

...

3 Commits

Author SHA1 Message Date
Jarred Sumner
cbdbc95492 Speculative fix for napi_set_property crash 2024-05-04 22:37:35 -07:00
Jarred Sumner
60a8ad0b27 Support passing Subprocess stdout/stderr to Bun.serve() 2024-05-04 19:20:32 -07:00
Jarred Sumner
69f5c93b45 Update installation.md 2024-05-03 20:22:00 -07:00
6 changed files with 64 additions and 15 deletions

View File

@@ -190,7 +190,7 @@ $ iex "& {$(irm https://bun.sh/install.ps1)} -Version 1.1.6"
To download Bun binaries directly, you can visit the [releases page](https://github.com/oven-sh/bun/releases) page on GitHub.
For convenience, here are the direct download links for the latest version:
For convenience, here are download links for the latest version:
- [`bun-linux-x64.zip`](https://github.com/oven-sh/bun/releases/latest/download/bun-linux-x64.zip)
- [`bun-linux-x64-baseline.zip`](https://github.com/oven-sh/bun/releases/latest/download/bun-linux-x64-baseline.zip)

View File

@@ -2823,10 +2823,13 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
.Invalid => {
this.readable_stream_ref.deinit();
},
// toBlobIfPossible should've caught this
.Blob, .File => unreachable,
.JavaScript, .Direct => {
// toBlobIfPossible will typically convert .Blob streams, or .File streams into a Blob object, but cannot always.
.Blob,
.File,
// These are the common scenario:
.JavaScript,
.Direct,
=> {
if (this.resp) |resp| {
var pair = StreamPair{ .stream = stream, .this = this };
resp.runCorkedWithType(*StreamPair, doRenderStream, &pair);

View File

@@ -494,24 +494,35 @@ extern "C" napi_status napi_set_property(napi_env env, napi_value target,
return napi_invalid_arg;
}
auto globalObject = toJS(env);
auto& vm = globalObject->vm();
auto* object = toJS(target).getObject();
if (!object) {
JSValue targetValue = toJS(target);
if (!targetValue.isObject()) {
return napi_object_expected;
}
auto globalObject = toJS(env);
auto& vm = globalObject->vm();
auto* object = targetValue.getObject();
auto keyProp = toJS(key);
auto scope = DECLARE_CATCH_SCOPE(vm);
PutPropertySlot slot(object, true);
Identifier identifier = keyProp.toPropertyKey(globalObject);
JSValue jsValue = toJS(value);
PutPropertySlot slot(object, false);
object->put(object, globalObject, identifier, jsValue, slot);
Identifier identifier = keyProp.toPropertyKey(globalObject);
RETURN_IF_EXCEPTION(scope, napi_generic_failure);
scope.clearException();
JSValue jsValue = toJS(value);
if (!object->put(object, globalObject, identifier, jsValue, slot)) {
scope.clearExceptionExceptTermination();
return napi_generic_failure;
}
if (UNLIKELY(scope.exception())) {
scope.clearException();
return napi_generic_failure;
}
return napi_ok;
}
extern "C" napi_status napi_has_property(napi_env env, napi_value object,

View File

@@ -269,7 +269,7 @@ export function randomPort(): number {
}
expect.extend({
toRun(cmds: string[]) {
toRun(cmds: string[], optionalStdout?: string) {
const result = Bun.spawnSync({
cmd: [bunExe(), ...cmds],
env: bunEnv,
@@ -283,6 +283,14 @@ expect.extend({
};
}
if (optionalStdout) {
return {
pass: result.stdout.toString("utf-8") === optionalStdout,
message: () =>
`Expected ${cmds.join(" ")} to output ${optionalStdout} but got ${result.stdout.toString("utf-8")}`,
};
}
return {
pass: true,
message: () => `Expected ${cmds.join(" ")} to fail`,

View File

@@ -0,0 +1,20 @@
import { spawn, serve } from "bun";
const server = serve({
port: 0,
async fetch(req) {
const { stdout } = spawn({
cmd: [process.execPath, "--eval", 'console.write("hello world")'],
env: process.env,
stdout: "pipe",
stderr: "inherit",
stdin: "ignore",
});
return new Response(stdout);
},
});
const response = await fetch(server.url);
console.write(await response.text());
server.stop(true);

View File

@@ -0,0 +1,7 @@
import { test, expect } from "bun:test";
import "harness";
import { fileURLToPath } from "url";
test("Subprocess stdout can be used in Bun.serve()", async () => {
expect([fileURLToPath(import.meta.resolve("./spawn-stream-http-fixture.js"))]).toRun("hello world");
});