mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
Handle v8:Object::GetOwnPropertyNames returning null
This seems to only happen in error cases, most notably someone changes the object to return an invalid ownKeys, as we see in WPT /fetch/api/headers/headers-record.any.html
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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 .{
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user