From 075adabd05f5603c7d1d56162e076da90e9642c0 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sat, 23 Nov 2024 04:45:34 -0800 Subject: [PATCH] Update bindings.zig --- src/bun.js/bindings/bindings.zig | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index 1b7e8acbcbffa3..5faf461106f888 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -5456,7 +5456,18 @@ pub const JSValue = enum(i64) { pub fn getTruthyComptime(this: JSValue, global: *JSGlobalObject, comptime property: []const u8) bun.JSError!?JSValue { if (comptime bun.ComptimeEnumMap(BuiltinName).has(property)) { if (fastGet(this, global, @field(BuiltinName, property))) |prop| { - if (!prop.toBoolean()) return null; + switch (prop) { + .null, .undefined => return null, + else => { + // Ignore null, undefined, and empty string. + if (prop.isString()) { + if (!prop.toBoolean()) { + return null; + } + } + }, + } + return prop; } @@ -5469,8 +5480,19 @@ pub const JSValue = enum(i64) { // TODO: replace calls to this function with `getOptional` pub fn getTruthy(this: JSValue, global: *JSGlobalObject, property: []const u8) bun.JSError!?JSValue { if (try get(this, global, property)) |prop| { - if (!prop.toBoolean()) return null; - return prop; + switch (prop) { + .null, .undefined => {}, + else => { + // Ignore null, undefined, and empty string. + if (prop.isString()) { + if (!prop.toBoolean()) { + return null; + } + } + + return prop; + }, + } } return null;