Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
fix(workers): reject extended lifetime mismatch
ldm0c4f472469eb0
diff --git a/moli-benchmark/wpt-cross-current/failed-cases.txt b/moli-benchmark/wpt-cross-current/failed-cases.txtindex 42b3fa988..425049390 100644--- a/moli-benchmark/wpt-cross-current/failed-cases.txt+++ b/moli-benchmark/wpt-cross-current/failed-cases.txt@@ -3830,7 +3830,6 @@ workers/semantics/encodings/003.htmlworkers/semantics/encodings/004.htmlworkers/semantics/structured-clone/dedicated.htmlworkers/semantics/structured-clone/shared.html-workers/shared-worker-options-mismatch.htmlworklets/animation-worklet-service-worker-interception.https.htmlworklets/audio-worklet-service-worker-interception.https.htmlworklets/layout-worklet-service-worker-interception.https.htmldiff --git a/moli-benchmark/wpt-cross-current/passed-cases.txt b/moli-benchmark/wpt-cross-current/passed-cases.txtindex d246d25fd..20b288fab 100644--- a/moli-benchmark/wpt-cross-current/passed-cases.txt+++ b/moli-benchmark/wpt-cross-current/passed-cases.txt@@ -8372,6 +8372,7 @@ workers/semantics/xhr/004.htmlworkers/semantics/xhr/005.htmlworkers/semantics/xhr/006.htmlworkers/shared-worker-name-via-options.html+workers/shared-worker-options-mismatch.htmlworkers/shared-worker-parse-error-failure.htmlworkers/shared-worker-runtime-error-is-not-parse-error.htmlworkers/worker-request-animation-frame.htmldiff --git a/moli-renderer-v8/src/context_bootstrap/shared_worker_host.rs b/moli-renderer-v8/src/context_bootstrap/shared_worker_host.rsindex bcad28699..6bf2fb41f 100644--- a/moli-renderer-v8/src/context_bootstrap/shared_worker_host.rs+++ b/moli-renderer-v8/src/context_bootstrap/shared_worker_host.rs@@ -150,6 +150,7 @@ struct SharedWorkerOptions {name: String,script_kind: WorkerScriptKind,credentials_mode: SharedWorkerCredentialsMode,+ extended_lifetime: bool,same_site_cookies: Option<SharedWorkerSameSiteCookies>,}@@ -179,6 +180,7 @@ impl Default for SharedWorkerOptions {name: String::new(),script_kind: WorkerScriptKind::Classic,credentials_mode: SharedWorkerCredentialsMode::SameOrigin,+ extended_lifetime: false,same_site_cookies: None,}}@@ -288,8 +290,12 @@ fn shared_worker_constructor_callback_inner<'s>(WorkerScriptKind::Classic => SharedWorkerScriptType::Classic,WorkerScriptKind::Module => SharedWorkerScriptType::Module,};- let descriptor =- SharedWorkerDescriptor::new(script_type, options.credentials_mode, creation_context_type);+ let descriptor = SharedWorkerDescriptor::new(+ script_type,+ options.credentials_mode,+ options.extended_lifetime,+ creation_context_type,+ );let same_site_cookies = options.same_site_cookies.unwrap_or_else(|| {SharedWorkerSameSiteCookies::default_for_storage_key(&context.storage_key)});@@ -652,6 +658,7 @@ fn parse_shared_worker_options(}None => SharedWorkerCredentialsMode::SameOrigin,};+ let extended_lifetime = boolean_property(scope, object, "extendedLifetime")?;let same_site_cookies = match optional_string_property(scope, object, "sameSiteCookies")? {Some(value) if value == "all" => Some(SharedWorkerSameSiteCookies::All),Some(value) if value == "none" => Some(SharedWorkerSameSiteCookies::None),@@ -668,10 +675,22 @@ fn parse_shared_worker_options(name,script_kind,credentials_mode,+ extended_lifetime,same_site_cookies,})}+fn boolean_property(+ scope: &mut v8::PinScope<'_, '_>,+ object: v8::Local<'_, v8::Object>,+ key: &str,+) -> Option<bool> {+ let key = v8_string(scope, key)?;+ object+ .get(scope, key.into())+ .map(|value| value.boolean_value(scope))+}+fn optional_string_property(scope: &mut v8::PinScope<'_, '_>,object: v8::Local<'_, v8::Object>,diff --git a/moli-renderer-v8/src/shared_worker_runtime/loading.rs b/moli-renderer-v8/src/shared_worker_runtime/loading.rsindex 6cb922c78..b2c9951c1 100644--- a/moli-renderer-v8/src/shared_worker_runtime/loading.rs+++ b/moli-renderer-v8/src/shared_worker_runtime/loading.rs@@ -632,6 +632,7 @@ mod tests {SharedWorkerDescriptor::new(script_type,credentials_mode,+ false,moli_shared_worker::SharedWorkerCreationContextType::Secure,)}diff --git a/moli-shared-worker/src/options.rs b/moli-shared-worker/src/options.rsindex 9a3b83d78..655334f56 100644--- a/moli-shared-worker/src/options.rs+++ b/moli-shared-worker/src/options.rs@@ -60,6 +60,7 @@ impl SharedWorkerSameSiteCookies {pub struct SharedWorkerDescriptor {script_type: SharedWorkerScriptType,credentials_mode: SharedWorkerCredentialsMode,+ extended_lifetime: bool,creation_context_type: SharedWorkerCreationContextType,}@@ -69,11 +70,13 @@ impl SharedWorkerDescriptor {pub fn new(script_type: SharedWorkerScriptType,credentials_mode: SharedWorkerCredentialsMode,+ extended_lifetime: bool,creation_context_type: SharedWorkerCreationContextType,) -> Self {Self {script_type,credentials_mode,+ extended_lifetime,creation_context_type,}}@@ -88,6 +91,11 @@ impl SharedWorkerDescriptor {self.credentials_mode}+ /// Return whether the constructor requested an extended worker lifetime.+ pub fn extended_lifetime(&self) -> bool {+ self.extended_lifetime+ }+/// Return the secure-context class of the constructor environment.pub fn creation_context_type(&self) -> SharedWorkerCreationContextType {self.creation_context_type@@ -110,6 +118,12 @@ impl SharedWorkerDescriptor {requested: requested.credentials_mode,});}+ if self.extended_lifetime != requested.extended_lifetime {+ return Err(SharedWorkerCompatibilityError::ExtendedLifetime {+ existing: self.extended_lifetime,+ requested: requested.extended_lifetime,+ });+ }if self.creation_context_type != requested.creation_context_type {return Err(SharedWorkerCompatibilityError::CreationContextType {existing: self.creation_context_type,@@ -125,6 +139,7 @@ impl Default for SharedWorkerDescriptor {Self::new(SharedWorkerScriptType::Classic,SharedWorkerCredentialsMode::SameOrigin,+ false,SharedWorkerCreationContextType::Secure,)}@@ -141,6 +156,10 @@ pub enum SharedWorkerCompatibilityError {existing: SharedWorkerCredentialsMode,requested: SharedWorkerCredentialsMode,},+ ExtendedLifetime {+ existing: bool,+ requested: bool,+ },CreationContextType {existing: SharedWorkerCreationContextType,requested: SharedWorkerCreationContextType,@@ -164,6 +183,13 @@ impl fmt::Display for SharedWorkerCompatibilityError {f,"existing SharedWorker credentials mode {existing:?} is incompatible with requested {requested:?}"),+ Self::ExtendedLifetime {+ existing,+ requested,+ } => write!(+ f,+ "existing SharedWorker extended lifetime {existing} is incompatible with requested {requested}"+ ),Self::CreationContextType {existing,requested,diff --git a/moli-shared-worker/src/registry.rs b/moli-shared-worker/src/registry.rsindex 33a6517f9..50fe54c37 100644--- a/moli-shared-worker/src/registry.rs+++ b/moli-shared-worker/src/registry.rs@@ -800,6 +800,7 @@ mod tests {SharedWorkerDescriptor::new(SharedWorkerScriptType::Module,SharedWorkerCredentialsMode::SameOrigin,+ false,SharedWorkerCreationContextType::Secure,),);@@ -813,6 +814,40 @@ mod tests {));}+ #[test]+ fn extended_lifetime_mismatch_rejects_client_not_another_instance() {+ let registry = SharedWorkerRegistry::<u64>::default();+ let key = key("a");+ let first = registry.connect(key.clone(), SharedWorkerDescriptor::default());+ let instance_id = match first {+ SharedWorkerConnectAction::StartLoading { instance_id, .. } => instance_id,+ other => panic!("expected StartLoading, got {other:?}"),+ };+ registry.finish_loading(&key, instance_id, 1);++ let rejected = registry.connect(+ key,+ SharedWorkerDescriptor::new(+ SharedWorkerScriptType::Classic,+ SharedWorkerCredentialsMode::SameOrigin,+ true,+ SharedWorkerCreationContextType::Secure,+ ),+ );++ assert!(matches!(+ rejected,+ SharedWorkerConnectAction::RejectClient {+ error: SharedWorkerCompatibilityError::ExtendedLifetime {+ existing: false,+ requested: true,+ },+ ..+ }+ ));+ assert_eq!(registry.diagnostics().entry_count, 1);+ }+#[test]fn creation_context_mismatch_rejects_client_not_another_instance() {let registry = SharedWorkerRegistry::<u64>::default();@@ -829,6 +864,7 @@ mod tests {SharedWorkerDescriptor::new(SharedWorkerScriptType::Classic,SharedWorkerCredentialsMode::SameOrigin,+ false,SharedWorkerCreationContextType::Nonsecure,),);