refact: move create_image_bitmap to ImageBitmap Impl (#37348) (#37602)

This PR moves the `create_image_bitmap` method from `GlobalScope` to a
helper function within the `ImageBitmap` implementation in
`imagebitmap.rs`.

Moving this method improves code organization and maintainability. Given
that `globalscope.rs` is already quite large, relocating
`create_image_bitmap` to `imagebitmap.rs` places it closer to the
`ImageBitmap` struct it primarily operates on.

As mentioned in the issue description (No dedicated tests are required
for this change, as long as the project builds), which it does using
`./mach build`. Also ran `./mach fmt` and `./mach test-tidy` which both
didn't report any issue.

Closes #37348

Signed-off-by: Bhuwan Pandit <bhuwanpandit109@gmail.com>
This commit is contained in:
Bhuwan Pandit 2025-06-21 05:12:11 +01:00 committed by GitHub
parent 0832ec5d96
commit d7269c0f3b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 409 additions and 390 deletions

View file

@ -58,6 +58,7 @@ use crate::dom::performance::Performance;
use crate::dom::promise::Promise;
use crate::dom::trustedscripturl::TrustedScriptURL;
use crate::dom::trustedtypepolicyfactory::TrustedTypePolicyFactory;
use crate::dom::types::ImageBitmap;
#[cfg(feature = "webgpu")]
use crate::dom::webgpu::identityhub::IdentityHub;
use crate::dom::window::{base64_atob, base64_btoa};
@ -465,9 +466,16 @@ impl WorkerGlobalScopeMethods<crate::DomTypeHolder> for WorkerGlobalScope {
options: &ImageBitmapOptions,
can_gc: CanGc,
) -> Rc<Promise> {
let p = self
.upcast::<GlobalScope>()
.create_image_bitmap(image, 0, 0, None, None, options, can_gc);
let p = ImageBitmap::create_image_bitmap(
self.upcast(),
image,
0,
0,
None,
None,
options,
can_gc,
);
p
}
@ -482,7 +490,8 @@ impl WorkerGlobalScopeMethods<crate::DomTypeHolder> for WorkerGlobalScope {
options: &ImageBitmapOptions,
can_gc: CanGc,
) -> Rc<Promise> {
let p = self.upcast::<GlobalScope>().create_image_bitmap(
let p = ImageBitmap::create_image_bitmap(
self.upcast(),
image,
sx,
sy,