mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-11 17:00:37 +00:00
LibWeb/HTML: Resolve image decoding promises inside tasks
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run
This corresponds to https://github.com/whatwg/html/pull/10753 WHile I was at it, I've also moved the checks inside the spin callback, and reformatted the spec comments to match our style.
This commit is contained in:
parent
8d8aa964da
commit
21e6db6ba4
Notes:
github-actions[bot]
2024-12-05 21:46:21 +00:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/LadybirdBrowser/ladybird/commit/21e6db6ba45 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2229 Reviewed-by: https://github.com/ADKaster
1 changed files with 56 additions and 40 deletions
|
@ -319,6 +319,9 @@ WebIDL::ExceptionOr<GC::Ref<WebIDL::Promise>> HTMLImageElement::decode() const
|
|||
|
||||
// 2. Queue a microtask to perform the following steps:
|
||||
queue_a_microtask(&document(), GC::create_function(realm.heap(), [this, promise, &realm]() mutable {
|
||||
// 1. Let global be this's relevant global object.
|
||||
auto& global = relevant_global_object(*this);
|
||||
|
||||
auto reject_if_document_not_fully_active = [this, promise, &realm]() -> bool {
|
||||
if (this->document().is_fully_active())
|
||||
return false;
|
||||
|
@ -339,55 +342,68 @@ WebIDL::ExceptionOr<GC::Ref<WebIDL::Promise>> HTMLImageElement::decode() const
|
|||
return true;
|
||||
};
|
||||
|
||||
// 2.1 If any of the following are true:
|
||||
// 2.1.1 this's node document is not fully active;
|
||||
// 2.1.1 then reject promise with an "EncodingError" DOMException.
|
||||
if (reject_if_document_not_fully_active())
|
||||
// 2. If any of the following are true:
|
||||
// - this's node document is not fully active;
|
||||
// - or this's current request's state is broken,
|
||||
// then reject promise with an "EncodingError" DOMException.
|
||||
if (reject_if_document_not_fully_active() || reject_if_current_request_state_broken()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 2.1.2 or this's current request's state is broken,
|
||||
// 2.1.2 then reject promise with an "EncodingError" DOMException.
|
||||
if (reject_if_current_request_state_broken())
|
||||
return;
|
||||
|
||||
// 2.2 Otherwise, in parallel wait for one of the following cases to occur, and perform the corresponding actions:
|
||||
Platform::EventLoopPlugin::the().deferred_invoke(GC::create_function(heap(), [this, promise, &realm, reject_if_document_not_fully_active, reject_if_current_request_state_broken] {
|
||||
// 3. Otherwise, in parallel wait for one of the following cases to occur, and perform the corresponding actions:
|
||||
Platform::EventLoopPlugin::the().deferred_invoke(GC::create_function(heap(), [this, promise, &realm, &global] {
|
||||
Platform::EventLoopPlugin::the().spin_until(GC::create_function(heap(), [&] {
|
||||
auto queue_reject_task = [&](String const& message) {
|
||||
queue_global_task(Task::Source::DOMManipulation, global, GC::create_function(realm.heap(), [&realm, &promise, &message] {
|
||||
auto exception = WebIDL::EncodingError::create(realm, message);
|
||||
HTML::TemporaryExecutionContext context(realm);
|
||||
WebIDL::reject_promise(realm, promise, exception);
|
||||
}));
|
||||
};
|
||||
|
||||
// -> This img element's node document stops being fully active
|
||||
if (!document().is_fully_active()) {
|
||||
// Queue a global task on the DOM manipulation task source with global to reject promise with an "EncodingError" DOMException.
|
||||
queue_reject_task("Node document not fully active"_string);
|
||||
return true;
|
||||
}
|
||||
|
||||
auto state = this->current_request().state();
|
||||
|
||||
return !this->document().is_fully_active() || state == ImageRequest::State::Broken || state == ImageRequest::State::CompletelyAvailable;
|
||||
// -> FIXME: This img element's current request changes or is mutated
|
||||
if (false) {
|
||||
// Queue a global task on the DOM manipulation task source with global to reject promise with an "EncodingError" DOMException.
|
||||
queue_reject_task("Current request changed or was mutated"_string);
|
||||
return true;
|
||||
}
|
||||
|
||||
// -> This img element's current request's state becomes broken
|
||||
if (state == ImageRequest::State::Broken) {
|
||||
// Queue a global task on the DOM manipulation task source with global to reject promise with an "EncodingError" DOMException.
|
||||
queue_reject_task("Current request state is broken"_string);
|
||||
return true;
|
||||
}
|
||||
|
||||
// -> This img element's current request's state becomes completely available
|
||||
if (state == ImageRequest::State::CompletelyAvailable) {
|
||||
// FIXME: Decode the image.
|
||||
// FIXME: If decoding does not need to be performed for this image (for example because it is a vector graphic) or the decoding process completes successfully, then queue a global task on the DOM manipulation task source with global to resolve promise with undefined.
|
||||
// FIXME: If decoding fails (for example due to invalid image data), then queue a global task on the DOM manipulation task source with global to reject promise with an "EncodingError" DOMException.
|
||||
|
||||
// NOTE: For now we just resolve it.
|
||||
queue_global_task(Task::Source::DOMManipulation, global, GC::create_function(realm.heap(), [&realm, &promise] {
|
||||
HTML::TemporaryExecutionContext context(realm);
|
||||
WebIDL::resolve_promise(realm, promise, JS::js_undefined());
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}));
|
||||
|
||||
// 2.2.1 This img element's node document stops being fully active
|
||||
// 2.2.1 Reject promise with an "EncodingError" DOMException.
|
||||
if (reject_if_document_not_fully_active())
|
||||
return;
|
||||
|
||||
// FIXME: 2.2.2 This img element's current request changes or is mutated
|
||||
// FIXME: 2.2.2 Reject promise with an "EncodingError" DOMException.
|
||||
|
||||
// 2.2.3 This img element's current request's state becomes broken
|
||||
// 2.2.3 Reject promise with an "EncodingError" DOMException.
|
||||
if (reject_if_current_request_state_broken())
|
||||
return;
|
||||
|
||||
// 2.2.4 This img element's current request's state becomes completely available
|
||||
if (this->current_request().state() == ImageRequest::State::CompletelyAvailable) {
|
||||
// 2.2.4.1 FIXME: Decode the image.
|
||||
// 2.2.4.2 FIXME: If decoding does not need to be performed for this image (for example because it is a vector graphic), resolve promise with undefined.
|
||||
// 2.2.4.3 FIXME: If decoding fails (for example due to invalid image data), reject promise with an "EncodingError" DOMException.
|
||||
// 2.2.4.4 FIXME: If the decoding process completes successfully, resolve promise with undefined.
|
||||
// 2.2.4.5 FIXME: User agents should ensure that the decoded media data stays readily available until at least the end of the next successful update
|
||||
// the rendering step in the event loop. This is an important part of the API contract, and should not be broken if at all possible.
|
||||
// (Typically, this would only be violated in low-memory situations that require evicting decoded image data, or when the image is too large
|
||||
// to keep in decoded form for this period of time.)
|
||||
|
||||
HTML::TemporaryExecutionContext context(realm);
|
||||
WebIDL::resolve_promise(realm, promise, JS::js_undefined());
|
||||
}
|
||||
}));
|
||||
}));
|
||||
|
||||
// 3. Return promise.
|
||||
return promise;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue