diff --git a/src/ecmascript/libdom/spidermonkey/heartbeat.cpp b/src/ecmascript/libdom/spidermonkey/heartbeat.cpp index 0b71df79e..9f6f5c0b7 100644 --- a/src/ecmascript/libdom/spidermonkey/heartbeat.cpp +++ b/src/ecmascript/libdom/spidermonkey/heartbeat.cpp @@ -89,6 +89,11 @@ add_heartbeat(struct ecmascript_interpreter *interpreter) assert(interpreter); + if (interpreter->heartbeat) { + interpreter->heartbeat->ref_count++; + return interpreter->heartbeat; + } + if (!interpreter->vs || !interpreter->vs->doc_view) ses = NULL; else @@ -99,6 +104,7 @@ add_heartbeat(struct ecmascript_interpreter *interpreter) hb->ttl = get_opt_int("ecmascript.max_exec_time", ses); hb->interpreter = interpreter; + hb->ref_count = 1; add_to_list(heartbeats, hb); /* Update the heartbeat timer. */ @@ -122,6 +128,10 @@ done_heartbeat(struct heartbeat *hb) if (!hb) return; /* add_heartbeat returned NULL */ assert(hb->interpreter); + if (--hb->ref_count > 0) { + return; + } + /* Stop the heartbeat timer if this heartbeat is the only one. */ if (list_is_singleton(*hb)) { heartbeat_timer.it_value.tv_sec = 0; diff --git a/src/ecmascript/spidermonkey.cpp b/src/ecmascript/spidermonkey.cpp index 3309055e5..93dc2c191 100644 --- a/src/ecmascript/spidermonkey.cpp +++ b/src/ecmascript/spidermonkey.cpp @@ -306,6 +306,7 @@ spidermonkey_put_interpreter(struct ecmascript_interpreter *interpreter) interpreter->backend_data = NULL; interpreter->ac = nullptr; interpreter->ar = nullptr; + done_heartbeat(interpreter->heartbeat); } void diff --git a/src/ecmascript/spidermonkey/heartbeat.h b/src/ecmascript/spidermonkey/heartbeat.h index 3f2c90eba..ef03f7e78 100644 --- a/src/ecmascript/spidermonkey/heartbeat.h +++ b/src/ecmascript/spidermonkey/heartbeat.h @@ -13,6 +13,7 @@ struct heartbeat { * second. When it reaches 0, script execution is * terminated. */ + int ref_count; struct ecmascript_interpreter *interpreter; };