Merge pull request #1636 from lightpanda-io/null_GetOwnPropertyNames

Handle v8:Object::GetOwnPropertyNames returning null
This commit is contained in:
Karl Seguin
2026-02-24 15:55:10 +08:00
committed by GitHub
3 changed files with 25 additions and 9 deletions

View File

@@ -1209,13 +1209,20 @@ fn _debugValue(self: *const Local, js_val: js.Value, seen: *std.AutoHashMapUnman
gop.value_ptr.* = {};
}
const names_arr = js_obj.getOwnPropertyNames();
const len = names_arr.len();
if (depth > 20) {
return writer.writeAll("...deeply nested object...");
}
const own_len = js_obj.getOwnPropertyNames().len();
const names_arr = js_obj.getOwnPropertyNames() catch {
return writer.writeAll("...invalid object...");
};
const len = names_arr.len();
const own_len = blk: {
const own_names = js_obj.getOwnPropertyNames() catch break :blk 0;
break :blk own_names.len();
};
if (own_len == 0) {
const js_val_str = try js_val.toStringSlice();
if (js_val_str.len > 2000) {

View File

@@ -129,8 +129,14 @@ pub fn isNullOrUndefined(self: Object) bool {
return v8.v8__Value__IsNullOrUndefined(@ptrCast(self.handle));
}
pub fn getOwnPropertyNames(self: Object) js.Array {
const handle = v8.v8__Object__GetOwnPropertyNames(self.handle, self.local.handle).?;
pub fn getOwnPropertyNames(self: Object) !js.Array {
const handle = v8.v8__Object__GetOwnPropertyNames(self.handle, self.local.handle) orelse {
// This is almost always a fatal error case. Either we're in some exception
// and things are messy, or we're shutting down, or someone has messed up
// the object (like some WPT tests do).
return error.TypeError;
};
return .{
.local = self.local,
.handle = handle,
@@ -145,8 +151,11 @@ pub fn getPropertyNames(self: Object) js.Array {
};
}
pub fn nameIterator(self: Object) NameIterator {
const handle = v8.v8__Object__GetPropertyNames(self.handle, self.local.handle).?;
pub fn nameIterator(self: Object) !NameIterator {
const handle = v8.v8__Object__GetPropertyNames(self.handle, self.local.handle) orelse {
// see getOwnPropertyNames above
return error.TypeError;
};
const count = v8.v8__Array__Length(handle);
return .{

View File

@@ -62,7 +62,7 @@ pub fn copy(arena: Allocator, original: KeyValueList) !KeyValueList {
}
pub fn fromJsObject(arena: Allocator, js_obj: js.Object, comptime normalizer: ?Normalizer, page: *Page) !KeyValueList {
var it = js_obj.nameIterator();
var it = try js_obj.nameIterator();
var list = KeyValueList.init();
try list.ensureTotalCapacity(arena, it.count);