Re-enable cached property support

The idea is that frequently accessed properties, e.g. window.document, can be
cached directly as data properties on the underlying v8::Object, removing the
need for the access call into Zig. This is only used on a handful of properties,
almost all of which are on the Window. It is important that the property be
read-only. For example, window.location cannot be cached this way because
window.location is writable (e.g. window.location.hash = '#blah').

This existed briefly before Zigdom, but was removed as part of the migration.
The implementation has changed. This previously relied on a "postAttach" feature
which no longer exists. It is not integrated in the bridge/callback directly and
lazily applied after the first access.
This commit is contained in:
Karl Seguin
2026-01-19 11:28:42 +08:00
parent 6f3cb4b48e
commit 43805ad698
4 changed files with 27 additions and 6 deletions

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2023-2025 Lightpanda (Selecy SAS)
// Copyright (C) 2023-2026 Lightpanda (Selecy SAS)
//
// Francis Bouvier <francis@lightpanda.io>
// Pierre Tachoire <pierre@lightpanda.io>
@@ -164,7 +164,7 @@ pub const Accessor = struct {
const Opts = struct {
static: bool = false,
cache: ?[]const u8 = null, // @ZIGDOM
cache: ?[]const u8 = null,
as_typed_array: bool = false,
null_as_undefined: bool = false,
};
@@ -184,11 +184,13 @@ pub const Accessor = struct {
if (comptime opts.static) {
caller.function(T, getter, handle.?, .{
.cache = opts.cache,
.as_typed_array = opts.as_typed_array,
.null_as_undefined = opts.null_as_undefined,
});
} else {
caller.method(T, getter, handle.?, .{
.cache = opts.cache,
.as_typed_array = opts.as_typed_array,
.null_as_undefined = opts.null_as_undefined,
});