fix(createEmptyObject) fix some createEmptyObject values (#22512)

### What does this PR do?
We must use the right number of properties (not more or less) or we
should set it to 0
### How did you verify your code works?
Read the code, this will avoid potencial crashs and improve stability
This commit is contained in:
Ciro Spaciari
2025-11-13 15:19:18 -08:00
committed by GitHub
parent d7bf4fb443
commit 21d582a3cd
4 changed files with 8 additions and 8 deletions

View File

@@ -3028,7 +3028,7 @@ pub const H2FrameParser = struct {
var stream = this.streams.getPtr(stream_id) orelse {
return globalObject.throw("Invalid stream id", .{});
};
var state = jsc.JSValue.createEmptyObject(globalObject, 7);
var state = jsc.JSValue.createEmptyObject(globalObject, 6);
state.put(globalObject, jsc.ZigString.static("localWindowSize"), jsc.JSValue.jsNumber(stream.windowSize));
state.put(globalObject, jsc.ZigString.static("state"), jsc.JSValue.jsNumber(@intFromEnum(stream.state)));

View File

@@ -383,9 +383,9 @@ pub fn getEphemeralKeyInfo(this: *This, globalObject: *jsc.JSGlobalObject, _: *j
if (this.isServer()) {
return JSValue.jsNull();
}
var result = JSValue.createEmptyObject(globalObject, 3);
const ssl_ptr = this.socket.ssl() orelse return JSValue.jsNull();
var result = JSValue.createEmptyObject(globalObject, 0);
// TODO: investigate better option or compatible way to get the key
// this implementation follows nodejs but for BoringSSL SSL_get_server_tmp_key will always return 0

View File

@@ -92,7 +92,7 @@ fn cpusImplLinux(globalThis: *jsc.JSGlobalObject) !jsc.JSValue {
times.irq = scale * try std.fmt.parseInt(u64, toks.next() orelse return error.eol, 10);
// Actually create the JS object representing the CPU
const cpu = jsc.JSValue.createEmptyObject(globalThis, 3);
const cpu = jsc.JSValue.createEmptyObject(globalThis, 1);
cpu.put(globalThis, jsc.ZigString.static("times"), times.toValue(globalThis));
try values.putIndex(globalThis, num_cpus, cpu);
@@ -511,7 +511,7 @@ fn networkInterfacesPosix(globalThis: *jsc.JSGlobalObject) bun.JSError!jsc.JSVal
num_inet_interfaces += 1;
}
var ret = jsc.JSValue.createEmptyObject(globalThis, 8);
var ret = jsc.JSValue.createEmptyObject(globalThis, 0);
// Second pass through, populate each interface object
it = interface_start;
@@ -522,7 +522,7 @@ fn networkInterfacesPosix(globalThis: *jsc.JSGlobalObject) bun.JSError!jsc.JSVal
const addr = std.net.Address.initPosix(@alignCast(@as(*std.posix.sockaddr, @ptrCast(iface.ifa_addr))));
const netmask = std.net.Address.initPosix(@alignCast(@as(*std.posix.sockaddr, @ptrCast(iface.ifa_netmask))));
var interface = jsc.JSValue.createEmptyObject(globalThis, 7);
var interface = jsc.JSValue.createEmptyObject(globalThis, 0);
// address <string> The assigned IPv4 or IPv6 address
// cidr <string> The assigned IPv4 or IPv6 address with the routing prefix in CIDR notation. If the netmask is invalid, this property is set to null.

View File

@@ -118,7 +118,7 @@ pub const S3ListObjectsV2Result = struct {
const jsContents = try JSValue.createEmptyArray(globalObject, contents.items.len);
for (contents.items, 0..) |item, i| {
const objectInfo = JSValue.createEmptyObject(globalObject, 1);
const objectInfo = JSValue.createEmptyObject(globalObject, 0);
objectInfo.put(globalObject, jsc.ZigString.static("key"), try bun.String.createUTF8ForJS(globalObject, item.key));
if (item.etag) |etag| {
@@ -146,7 +146,7 @@ pub const S3ListObjectsV2Result = struct {
}
if (item.owner) |owner| {
const jsOwner = JSValue.createEmptyObject(globalObject, 2);
const jsOwner = JSValue.createEmptyObject(globalObject, 0);
if (owner.id) |id| {
jsOwner.put(globalObject, jsc.ZigString.static("id"), try bun.String.createUTF8ForJS(globalObject, id));
}
@@ -168,7 +168,7 @@ pub const S3ListObjectsV2Result = struct {
const jsCommonPrefixes = try JSValue.createEmptyArray(globalObject, common_prefixes.items.len);
for (common_prefixes.items, 0..) |prefix, i| {
const jsPrefix = JSValue.createEmptyObject(globalObject, 1);
const jsPrefix = JSValue.createEmptyObject(globalObject, 0);
jsPrefix.put(globalObject, jsc.ZigString.static("prefix"), try bun.String.createUTF8ForJS(globalObject, prefix));
try jsCommonPrefixes.putIndex(globalObject, @intCast(i), jsPrefix);
}