Auto merge of #29354 - ben-freist:dom-drop-impl-worklet, r=delan

#26488 Move worklet drop implementation into single droppable member

Signed-off-by: Benjamin Freist <bfreist@soundhound.com>

<!-- Please describe your changes on the following line: -->
Hey @jdm ,
is this issue still free? I would like to start contributing to servo.
This patch is straight from PR 28302, I thought it would be good to start with a small part, I hope that's ok.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #___ (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because they will be checked by the compiler.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2023-02-14 23:43:47 +01:00 committed by GitHub
commit 02de93dc38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -70,13 +70,25 @@ use uuid::Uuid;
const WORKLET_THREAD_POOL_SIZE: u32 = 3; const WORKLET_THREAD_POOL_SIZE: u32 = 3;
const MIN_GC_THRESHOLD: u32 = 1_000_000; const MIN_GC_THRESHOLD: u32 = 1_000_000;
#[derive(JSTraceable, MallocSizeOf)]
struct DroppableField {
worklet_id: WorkletId,
}
impl Drop for DroppableField {
fn drop(&mut self) {
let script_thread = ScriptThread::worklet_thread_pool();
script_thread.exit_worklet(self.worklet_id);
}
}
#[dom_struct] #[dom_struct]
/// <https://drafts.css-houdini.org/worklets/#worklet> /// <https://drafts.css-houdini.org/worklets/#worklet>
pub struct Worklet { pub struct Worklet {
reflector: Reflector, reflector: Reflector,
window: Dom<Window>, window: Dom<Window>,
worklet_id: WorkletId,
global_type: WorkletGlobalScopeType, global_type: WorkletGlobalScopeType,
droppable_field: DroppableField,
} }
impl Worklet { impl Worklet {
@ -84,8 +96,10 @@ impl Worklet {
Worklet { Worklet {
reflector: Reflector::new(), reflector: Reflector::new(),
window: Dom::from_ref(window), window: Dom::from_ref(window),
worklet_id: WorkletId::new(),
global_type: global_type, global_type: global_type,
droppable_field: DroppableField {
worklet_id: WorkletId::new(),
},
} }
} }
@ -98,7 +112,7 @@ impl Worklet {
} }
pub fn worklet_id(&self) -> WorkletId { pub fn worklet_id(&self) -> WorkletId {
self.worklet_id self.droppable_field.worklet_id
} }
#[allow(dead_code)] #[allow(dead_code)]
@ -138,7 +152,7 @@ impl WorkletMethods for Worklet {
pool.fetch_and_invoke_a_worklet_script( pool.fetch_and_invoke_a_worklet_script(
global.pipeline_id(), global.pipeline_id(),
self.worklet_id, self.droppable_field.worklet_id,
self.global_type, self.global_type,
self.window.origin().immutable().clone(), self.window.origin().immutable().clone(),
global.api_base_url(), global.api_base_url(),
@ -154,13 +168,6 @@ impl WorkletMethods for Worklet {
} }
} }
impl Drop for Worklet {
fn drop(&mut self) {
let script_thread = ScriptThread::worklet_thread_pool();
script_thread.exit_worklet(self.worklet_id);
}
}
/// A guid for worklets. /// A guid for worklets.
#[derive(Clone, Copy, Debug, Eq, Hash, JSTraceable, PartialEq)] #[derive(Clone, Copy, Debug, Eq, Hash, JSTraceable, PartialEq)]
pub struct WorkletId(Uuid); pub struct WorkletId(Uuid);