mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-12 20:42:21 +00:00
LibWeb: Ensure TransformStream's transform/flush callbacks do not throw
Unlike what the comments here currently indicate, these callbacks do only return a Promise, and thus cannot throw.
This commit is contained in:
parent
60ea803b2a
commit
ffb48ccd81
Notes:
sideshowbarker
2024-07-16 18:26:46 +09:00
Author: https://github.com/trflynn89
Commit: ffb48ccd81
Pull-request: https://github.com/SerenityOS/serenity/pull/24165
Reviewed-by: https://github.com/kennethmyhra ✅
Reviewed-by: https://github.com/shannonbooth ✅
1 changed files with 6 additions and 12 deletions
|
@ -4657,24 +4657,18 @@ WebIDL::ExceptionOr<void> set_up_transform_stream_default_controller_from_transf
|
||||||
// callback this value transformer.
|
// callback this value transformer.
|
||||||
if (transformer_dict.transform) {
|
if (transformer_dict.transform) {
|
||||||
transform_algorithm = JS::create_heap_function(realm.heap(), [controller, &realm, transformer, callback = transformer_dict.transform](JS::Value chunk) -> WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> {
|
transform_algorithm = JS::create_heap_function(realm.heap(), [controller, &realm, transformer, callback = transformer_dict.transform](JS::Value chunk) -> WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> {
|
||||||
// Note: callback does not return a promise, so invoke_callback may return an abrupt completion
|
// Note: callback returns a promise, so invoke_callback will never return an abrupt completion
|
||||||
auto result = WebIDL::invoke_callback(*callback, transformer, chunk, controller);
|
auto result = MUST(WebIDL::invoke_callback(*callback, transformer, chunk, controller)).release_value();
|
||||||
if (result.is_error())
|
return WebIDL::create_resolved_promise(realm, result);
|
||||||
return WebIDL::create_rejected_promise(realm, *result.release_value());
|
|
||||||
|
|
||||||
return WebIDL::create_resolved_promise(realm, *result.release_value());
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// 5. If transformerDict["flush"] exists, set flushAlgorithm to an algorithm which returns the result of invoking
|
// 5. If transformerDict["flush"] exists, set flushAlgorithm to an algorithm which returns the result of invoking
|
||||||
// transformerDict["flush"] with argument list « controller » and callback this value transformer.
|
// transformerDict["flush"] with argument list « controller » and callback this value transformer.
|
||||||
if (transformer_dict.flush) {
|
if (transformer_dict.flush) {
|
||||||
flush_algorithm = JS::create_heap_function(realm.heap(), [&realm, transformer, callback = transformer_dict.flush, controller]() -> WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> {
|
flush_algorithm = JS::create_heap_function(realm.heap(), [&realm, transformer, callback = transformer_dict.flush, controller]() -> WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> {
|
||||||
// Note: callback does not return a promise, so invoke_callback may return an abrupt completion
|
// Note: callback returns a promise, so invoke_callback will never return an abrupt completion
|
||||||
auto result = WebIDL::invoke_callback(*callback, transformer, controller);
|
auto result = MUST(WebIDL::invoke_callback(*callback, transformer, controller)).release_value();
|
||||||
if (result.is_error()) {
|
return WebIDL::create_resolved_promise(realm, result);
|
||||||
return WebIDL::create_rejected_promise(realm, *result.release_value());
|
|
||||||
}
|
|
||||||
return WebIDL::create_resolved_promise(realm, *result.release_value());
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue