mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-17 17:38:10 +00:00
Introduces an Env.String for persistent strings
If a webapi has a []const u8 parameter, then the page.call_arena is used. This is our favorite arena to use, but if the string value has a lifetime beyond the call, it then needs to be duped again (using page.arena). When a webapi has a Env.String parameter, the page.arena will be used directly to get the value from V8, removing the need for an intermediary dupe in the call_arena. This allows HTMLCollections to be streamlined. They no longer need to dupe the filter (tag name, class name, ...), which means they can no longer fail. It also means that we no longer need to needlessly dupe the string literals.
This commit is contained in:
@@ -1196,6 +1196,10 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
|
||||
return try self.createFunction(js_value);
|
||||
}
|
||||
|
||||
if (T == String) {
|
||||
return .{ .string = try valueToString(self.context_arena, js_value, self.isolate, self.v8_context) };
|
||||
}
|
||||
|
||||
const js_obj = js_value.castTo(v8.Object);
|
||||
|
||||
if (comptime isJsObject(T)) {
|
||||
@@ -2184,6 +2188,15 @@ pub fn Env(comptime State: type, comptime WebApis: type) type {
|
||||
promise: v8.Promise,
|
||||
};
|
||||
|
||||
// When doing jsValueToZig, string ([]const u8) are managed by the
|
||||
// call_arena. That means that if the API wants to persist the string
|
||||
// (which is relatively common), it needs to dupe it again.
|
||||
// If the parameter is an Env.String rather than a []const u8, then
|
||||
// the page's arena will be used (rather than the call arena).
|
||||
pub const String = struct {
|
||||
string: []const u8,
|
||||
};
|
||||
|
||||
pub const Inspector = struct {
|
||||
isolate: v8.Isolate,
|
||||
inner: *v8.Inspector,
|
||||
|
||||
Reference in New Issue
Block a user