From 7d05730ac755de804b40e6c6d33ff4ae5d229a7a Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Thu, 10 Oct 2024 15:32:51 +0200 Subject: [PATCH] [spidermonkey] option change hook to not read option too often --- src/js/spidermonkey-shared.cpp | 6 ++++-- src/js/spidermonkey-shared.h | 1 + src/js/spidermonkey.cpp | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/js/spidermonkey-shared.cpp b/src/js/spidermonkey-shared.cpp index 96aec94a4..8ca6cfecd 100644 --- a/src/js/spidermonkey-shared.cpp +++ b/src/js/spidermonkey-shared.cpp @@ -7,7 +7,6 @@ #include "elinks.h" -#include "config/options.h" #include "js/spidermonkey-shared.h" #include @@ -28,6 +27,9 @@ static int spidermonkey_runtime_refcount; * * @return 1 if successful or 0 on error. If this succeeds, the * caller must eventually call spidermonkey_runtime_release(). */ + +long spidermonkey_memory_limit; + int spidermonkey_runtime_addref(void) { @@ -37,7 +39,7 @@ spidermonkey_runtime_addref(void) return 0; } - main_ctx = JS_NewContext(get_opt_long("ecmascript.spidermonkey.memory_limit", NULL)); + main_ctx = JS_NewContext(spidermonkey_memory_limit); if (!main_ctx) { JS_ShutDown(); diff --git a/src/js/spidermonkey-shared.h b/src/js/spidermonkey-shared.h index ccb812d7e..23ad09691 100644 --- a/src/js/spidermonkey-shared.h +++ b/src/js/spidermonkey-shared.h @@ -9,6 +9,7 @@ extern JSRuntime *spidermonkey_runtime; extern JSContext *main_ctx; +extern long spidermonkey_memory_limit; int spidermonkey_runtime_addref(void); void spidermonkey_runtime_release(void); diff --git a/src/js/spidermonkey.cpp b/src/js/spidermonkey.cpp index bd67cae70..81e26c165 100644 --- a/src/js/spidermonkey.cpp +++ b/src/js/spidermonkey.cpp @@ -134,9 +134,24 @@ reported: JS_ClearPendingException(ctx); } +static int +change_hook_spidermonkey(struct session *ses, struct option *current, struct option *changed) +{ + spidermonkey_memory_limit = get_opt_long("ecmascript.spidermonkey.memory_limit", ses); + + return 0; +} + static void spidermonkey_init(struct module *module) { + static const struct change_hook_info spidermonkey_change_hooks[] = { + { "ecmascript.spidermonkey.memory_limit", change_hook_spidermonkey }, + { NULL, NULL }, + }; + register_change_hooks(spidermonkey_change_hooks); + spidermonkey_memory_limit = get_opt_long("ecmascript.spidermonkey.memory_limit", NULL); + js_module_init_ok = spidermonkey_runtime_addref(); }