Compare commits

...

3 Commits

Author SHA1 Message Date
Akulij
d174ee7bc7 fix: handle Runner in BotController
reason: earlier, Runner and js runtime in it were freed after init of
BotController, which potentially was able to lead into hanging function
in config without runtime, BUT, there is check in in JS_FreeRuntime to
have zero objects, so bug found without hesitation ;)
2025-05-21 14:07:02 +05:00
Akulij
ca2e661a0e fix: in Runner's init_config use deserialize_js instead of js_into 2025-05-21 14:06:09 +05:00
Akulij
c33c67044a delete test test_deserialization_main, since it isnot actual anymore 2025-05-21 13:04:08 +05:00
2 changed files with 10 additions and 13 deletions

View File

@ -479,7 +479,7 @@ impl Runner {
let val = self.run_script(content)?;
// let rc: RunnerConfig = from_js(unsafe { self.context.context_raw() }, &val)?;
let rc: RunnerConfig = val.js_into()?;
let rc: RunnerConfig = DeserializerJS::deserialize_js(&val)?;
Ok(rc)
}
@ -521,16 +521,6 @@ mod tests {
println!("Val: {:?}", val.to_string());
}
#[test]
fn test_deserialization_main() {
let runner = Runner::init().unwrap();
let val = runner.run_script(include_str!("../mainbot.js")).unwrap();
let s: RunnerConfig = from_js(unsafe { runner.context.context_raw() }, &val).unwrap();
println!("deser: {:#?}", s);
let o = val.try_into_object().unwrap();
println!("o: {:?}", recursive_format(o));
}
#[test]
fn test_func_deserialization_main() {
let runner = Runner::init().unwrap();

View File

@ -105,6 +105,7 @@ pub struct BotController {
pub bot: Bot,
pub db: DB,
pub rc: RunnerConfig,
pub runner: Runner,
}
impl BotController {
@ -112,9 +113,15 @@ impl BotController {
let bot = Bot::new(&config.bot_token);
let db = DB::init(&config.db_url).await?;
let rc = Runner::init()?.init_config(include_str!("../mainbot.js"))?;
let runner = Runner::init()?;
let rc = runner.init_config(include_str!("../mainbot.js"))?;
Ok(Self { bot, db, rc })
Ok(Self {
bot,
db,
rc,
runner,
})
}
}