Skip to content

Commit

Permalink
paclib: New JS context on new PAC
Browse files Browse the repository at this point in the history
  • Loading branch information
kiron1 committed Aug 18, 2024
1 parent 844f5d0 commit 0fe2427
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions paclib/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct Engine<'a> {
}

impl<'a> Engine<'a> {
pub fn new() -> Self {
fn mkjs() -> Context<'a> {
let mut js = Context::default();

js.register_global_class::<DnsCache>().unwrap();
Expand Down Expand Up @@ -49,8 +49,11 @@ impl<'a> Engine<'a> {
.expect("eval pac_utils.js");
js.eval(Source::from_bytes(crate::DEFAULT_PAC_SCRIPT))
.expect("eval default PAC script");
js
}

Self { js }
pub fn new() -> Self {
Self { js: Self::mkjs() }
}

pub fn with_pac_script(pac_script: &str) -> Result<Self, PacScriptError> {
Expand All @@ -60,6 +63,7 @@ impl<'a> Engine<'a> {
}

pub fn set_pac_script(&mut self, pac_script: Option<&str>) -> Result<(), PacScriptError> {
self.js = Self::mkjs();
let pac_script = pac_script.unwrap_or(crate::DEFAULT_PAC_SCRIPT);
self.js
.eval(Source::from_bytes(pac_script))
Expand Down

0 comments on commit 0fe2427

Please sign in to comment.