aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/script/dom/imagebitmap.rs44
-rw-r--r--components/script/dom/webidls/ImageBitmap.webidl2
-rw-r--r--tests/wpt/meta/html/dom/idlharness.https.html.ini3
-rw-r--r--tests/wpt/meta/html/dom/idlharness.worker.js.ini3
4 files changed, 36 insertions, 16 deletions
diff --git a/components/script/dom/imagebitmap.rs b/components/script/dom/imagebitmap.rs
index 36b845b64e4..66294cbf05c 100644
--- a/components/script/dom/imagebitmap.rs
+++ b/components/script/dom/imagebitmap.rs
@@ -19,7 +19,11 @@ pub struct ImageBitmap {
reflector_: Reflector,
width: u32,
height: u32,
- bitmap_data: DomRefCell<Vec<u8>>,
+ /// The actual pixel data of the bitmap
+ ///
+ /// If this is `None`, then the bitmap data has been released by calling
+ /// [`close`](https://html.spec.whatwg.org/multipage/#dom-imagebitmap-close)
+ bitmap_data: DomRefCell<Option<Vec<u8>>>,
origin_clean: Cell<bool>,
}
@@ -29,7 +33,7 @@ impl ImageBitmap {
reflector_: Reflector::new(),
width: width_arg,
height: height_arg,
- bitmap_data: DomRefCell::new(vec![]),
+ bitmap_data: DomRefCell::new(Some(vec![])),
origin_clean: Cell::new(true),
}
}
@@ -43,26 +47,48 @@ impl ImageBitmap {
}
pub fn set_bitmap_data(&self, data: Vec<u8>) {
- *self.bitmap_data.borrow_mut() = data;
+ *self.bitmap_data.borrow_mut() = Some(data);
}
pub fn set_origin_clean(&self, origin_is_clean: bool) {
self.origin_clean.set(origin_is_clean);
}
+
+ /// Return the value of the [`[[Detached]]`](https://html.spec.whatwg.org/multipage/#detached)
+ /// internal slot
+ fn is_detached(&self) -> bool {
+ self.bitmap_data.borrow().is_none()
+ }
}
impl ImageBitmapMethods for ImageBitmap {
- // https://html.spec.whatwg.org/multipage/#dom-imagebitmap-height
+ /// <https://html.spec.whatwg.org/multipage/#dom-imagebitmap-height>
fn Height(&self) -> u32 {
- //to do: add a condition for checking detached internal slot
- //and return 0 if set to true
+ // Step 1. If this's [[Detached]] internal slot's value is true, then return 0.
+ if self.is_detached() {
+ return 0;
+ }
+
+ // Step 2. Return this's height, in CSS pixels.
self.height
}
- // https://html.spec.whatwg.org/multipage/#dom-imagebitmap-width
+ /// <https://html.spec.whatwg.org/multipage/#dom-imagebitmap-width>
fn Width(&self) -> u32 {
- //to do: add a condition to check detached internal slot
- ////and return 0 if set to true
+ // Step 1. If this's [[Detached]] internal slot's value is true, then return 0.
+ if self.is_detached() {
+ return 0;
+ }
+
+ // Step 2. Return this's width, in CSS pixels.
self.width
}
+
+ /// <https://html.spec.whatwg.org/multipage/#dom-imagebitmap-close>
+ fn Close(&self) {
+ // Step 1. Set this's [[Detached]] internal slot value to true.
+ // Step 2. Unset this's bitmap data.
+ // NOTE: The existence of the bitmap data is the internal slot in our implementation
+ self.bitmap_data.borrow_mut().take();
+ }
}
diff --git a/components/script/dom/webidls/ImageBitmap.webidl b/components/script/dom/webidls/ImageBitmap.webidl
index 51c923bfaf4..d15d96772fd 100644
--- a/components/script/dom/webidls/ImageBitmap.webidl
+++ b/components/script/dom/webidls/ImageBitmap.webidl
@@ -14,7 +14,7 @@
interface ImageBitmap {
readonly attribute unsigned long width;
readonly attribute unsigned long height;
- //void close();
+ undefined close();
};
typedef (CanvasImageSource or
diff --git a/tests/wpt/meta/html/dom/idlharness.https.html.ini b/tests/wpt/meta/html/dom/idlharness.https.html.ini
index 51c90457c2e..bae2b9ac0f7 100644
--- a/tests/wpt/meta/html/dom/idlharness.https.html.ini
+++ b/tests/wpt/meta/html/dom/idlharness.https.html.ini
@@ -662,9 +662,6 @@
[CanvasRenderingContext2D interface: document.createElement("canvas").getContext("2d") must inherit property "filter" with the proper type]
expected: FAIL
- [ImageBitmap interface: operation close()]
- expected: FAIL
-
[DataTransfer interface: attribute files]
expected: FAIL
diff --git a/tests/wpt/meta/html/dom/idlharness.worker.js.ini b/tests/wpt/meta/html/dom/idlharness.worker.js.ini
index 86e95fe3d0b..4dc6d066130 100644
--- a/tests/wpt/meta/html/dom/idlharness.worker.js.ini
+++ b/tests/wpt/meta/html/dom/idlharness.worker.js.ini
@@ -170,9 +170,6 @@
[WorkerGlobalScope interface: attribute ononline]
expected: FAIL
- [ImageBitmap interface: operation close()]
- expected: FAIL
-
[OffscreenCanvasRenderingContext2D interface: operation setLineDash(sequence<unrestricted double>)]
expected: FAIL