ScriptManager: fix memory leak and resource handover

Release the arena when an inline script is empty and ensure the
handover flag is set correctly for all script execution modes.
This commit is contained in:
Adrià Arrufat
2026-03-17 13:32:29 +09:00
parent d9cdd78138
commit e048b0372f

View File

@@ -214,6 +214,7 @@ pub fn addFromElement(self: *ScriptManager, comptime from_parser: bool, script_e
if (inline_source.len == 0) { if (inline_source.len == 0) {
// we haven't set script_element._executed = true yet, which is good. // we haven't set script_element._executed = true yet, which is good.
// If content is appended to the script, we will execute it then. // If content is appended to the script, we will execute it then.
page.releaseArena(arena);
return; return;
} }
source = .{ .@"inline" = inline_source }; source = .{ .@"inline" = inline_source };
@@ -260,6 +261,7 @@ pub fn addFromElement(self: *ScriptManager, comptime from_parser: bool, script_e
break :blk .normal; break :blk .normal;
}, },
}; };
handover = true;
const is_blocking = script.mode == .normal; const is_blocking = script.mode == .normal;
if (is_blocking == false) { if (is_blocking == false) {
@@ -290,7 +292,6 @@ pub fn addFromElement(self: *ScriptManager, comptime from_parser: bool, script_e
.done_callback = Script.doneCallback, .done_callback = Script.doneCallback,
.error_callback = Script.errorCallback, .error_callback = Script.errorCallback,
}); });
handover = true;
if (comptime IS_DEBUG) { if (comptime IS_DEBUG) {
var ls: js.Local.Scope = undefined; var ls: js.Local.Scope = undefined;