use crate::js_bootstrap::{create_vu_js_context, ShimBundle};
use crate::vu_loop::DriverHttpClientImpl;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
use tropel_core::config::HttpConfig;
use tropel_http::client::{HttpClient, VuCookieClient};
use tropel_sandbox::config::SandboxConfig;
use tropel_sandbox::state::new_pm_state;
use tropel_sdk::traits::DriverHttpClient;
pub async fn vu_context_heap_bytes() -> Option<u64> {
heap_bytes_for(&ShimBundle::default()).await
}
pub async fn vu_context_heap_bytes_for_script(script: &[u8]) -> Option<u64> {
heap_bytes_for(&ShimBundle::from_script(script)).await
}
async fn heap_bytes_for(shim: &ShimBundle) -> Option<u64> {
let pm_state = new_pm_state();
let client: Arc<dyn DriverHttpClient> = Arc::new(DriverHttpClientImpl {
client: VuCookieClient::new(HttpClient::new(&HttpConfig::default()).ok()?),
});
let ctx = create_vu_js_context(
1,
&pm_state,
&client,
shim,
&SandboxConfig::default(),
Arc::new(AtomicBool::new(false)),
)
.await?;
Some(ctx.quickjs_heap_bytes())
}