Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paclib: New JS context on new PAC #393

Merged
merged 1 commit into from
Aug 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading