diff options
author | 2023-02-24 17:22:14 -0300 | |
---|---|---|
committer | 2023-02-24 12:22:14 -0800 | |
commit | 1c531472c93f9d3a7b491b100803b8c0ad42d0e7 (patch) | |
tree | 729e877d8188630a4f2a431e02b88a472675a0f7 /src | |
parent | dc8e8450491f2485cc7c3b42fd82aaaf0f978260 (diff) | |
download | bun-1c531472c93f9d3a7b491b100803b8c0ad42d0e7.tar.gz bun-1c531472c93f9d3a7b491b100803b8c0ad42d0e7.tar.zst bun-1c531472c93f9d3a7b491b100803b8c0ad42d0e7.zip |
fix(body) Make Request/Reponse empty body to be null (#2156)
* make empty nullable
* revert mistake change
Diffstat (limited to 'src')
-rw-r--r-- | src/bun.js/webcore/body.zig | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/bun.js/webcore/body.zig b/src/bun.js/webcore/body.zig index ad40c56ff..19e92d95a 100644 --- a/src/bun.js/webcore/body.zig +++ b/src/bun.js/webcore/body.zig @@ -363,7 +363,10 @@ pub const Body = struct { JSC.markBinding(@src()); switch (this.*) { - .Used, .Empty => { + .Empty => { + return JSValue.jsNull(); + }, + .Used => { return JSC.WebCore.ReadableStream.empty(globalThis); }, .InternalBlob, @@ -435,7 +438,7 @@ pub const Body = struct { pub fn fromJS( globalThis: *JSGlobalObject, - value: JSValue, + value: JSValue ) ?Value { value.ensureStillAlive(); @@ -976,6 +979,10 @@ pub fn BodyMixin(comptime Type: type) type { ) callconv(.C) JSValue { var body: *Body.Value = this.getBodyValue(); + if (body.* == .Empty) { + return JSValue.jsNull(); + } + if (body.* == .Used) { // TODO: make this closed return JSC.WebCore.ReadableStream.empty(globalThis); @@ -997,6 +1004,7 @@ pub fn BodyMixin(comptime Type: type) type { _: *JSC.CallFrame, ) callconv(.C) JSC.JSValue { var value: *Body.Value = this.getBodyValue(); + if (value.* == .Used) { return handleBodyAlreadyUsed(globalObject); } |