From dcb437b1ad1512c3a486d2bdf787b50f593a9cc8 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Fri, 18 Mar 2022 20:04:57 -0700 Subject: [PATCH] [bun.js] Response.prototype.type --- src/javascript/jsc/webcore/response.zig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/javascript/jsc/webcore/response.zig b/src/javascript/jsc/webcore/response.zig index 0fa5507c76..2cb4b50dad 100644 --- a/src/javascript/jsc/webcore/response.zig +++ b/src/javascript/jsc/webcore/response.zig @@ -102,6 +102,10 @@ pub const Response = struct { .@"get" = getBodyUsed, .ro = true, }, + .@"type" = .{ + .@"get" = getResponseType, + .ro = true, + }, }, ); @@ -169,6 +173,20 @@ pub const Response = struct { return ZigString.init(this.url).withEncoding().toValueGC(ctx.ptr()).asObjectRef(); } + pub fn getResponseType( + this: *Response, + ctx: js.JSContextRef, + _: js.JSValueRef, + _: js.JSStringRef, + _: js.ExceptionRef, + ) js.JSValueRef { + if (this.body.init.status_code < 200) { + return ZigString.init("error").toValue(ctx.ptr()).asObjectRef(); + } + + return ZigString.init("basic").toValue(ctx.ptr()).asObjectRef(); + } + pub fn getBodyUsed( this: *Response, _: js.JSContextRef,