Skip to content

Truly independent web browser

LibWeb: Serialize a Notification's data after checking its options

Shannon Booth2106a38782a9
diff --git a/Libraries/LibWeb/Bindings/Rust/src/notifications_api/notification.rs b/Libraries/LibWeb/Bindings/Rust/src/notifications_api/notification.rs
index 701b4c2013a..4220325fca7 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/notifications_api/notification.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/notifications_api/notification.rs
@@ -124,7 +124,7 @@ struct CreateNotificationOptions {
renotify: bool,
silent: Option<bool>,
require_interaction: bool,
- data: Vec<u8>,
+ data: Value,
actions: Vec<NotificationAction>,
}
@@ -272,11 +272,6 @@ impl Notification {
title: Utf16String,
options: NotificationOptions,
) -> WebIdlResult<Ref<Self>> {
- // The constructor rejects actions before attempting to serialize data.
- if !options.actions.is_empty() {
- return Err(Exception::type_error("Options `action` is not empty"));
- }
-
let options = CreateNotificationOptions {
direction: options.dir,
language: options.lang,
@@ -291,7 +286,7 @@ impl Notification {
renotify: options.renotify,
silent: options.silent,
require_interaction: options.require_interaction,
- data: structured_serialize_for_storage(cx, options.data)?,
+ data: options.data,
actions: options.actions,
};
Self::create_with_global_scope(cx, title, options)
@@ -322,7 +317,7 @@ impl Notification {
// 3. Let notification be the result of creating a notification with a settings object given title, options, and this’s relevant settings object.
let notification =
- Self::create_a_notification_with_a_settings_object(title, options, &relevant_settings_object)?;
+ Self::create_a_notification_with_a_settings_object(cx, title, options, &relevant_settings_object)?;
// 4. Associate this with notification.
let this_notification = allocate(vm, |_| Self {
@@ -354,6 +349,7 @@ impl Notification {
// https://notifications.spec.whatwg.org/#create-a-notification-with-a-settings-object
fn create_a_notification_with_a_settings_object(
+ cx: &mut CallContext,
title: Utf16String,
options: CreateNotificationOptions,
settings: &CppEnvironmentSettingsObject,
@@ -374,11 +370,12 @@ impl Notification {
let fallback_timestamp = settings.current_wall_time().round_ties_even() as u64;
// 4. Return the result of creating a notification given title, options, origin, baseURL, and fallbackTimestamp.
- Self::create_a_notification(title, options, origin, &base_url, fallback_timestamp)
+ Self::create_a_notification(cx, title, options, origin, &base_url, fallback_timestamp)
}
// https://notifications.spec.whatwg.org/#create-a-notification
fn create_a_notification(
+ cx: &mut CallContext,
title: Utf16String,
options: CreateNotificationOptions,
origin: Origin,
@@ -403,7 +400,7 @@ impl Notification {
let mut notification = ConceptNotification {
// 4. Set notification’s data to StructuredSerializeForStorage(options["data"]).
- data: options.data,
+ data: structured_serialize_for_storage(cx, options.data)?,
// 5. Set notification’s title to title.
title,
diff --git a/Tests/LibWeb/Text/expected/notifications/constructor-create-steps.txt b/Tests/LibWeb/Text/expected/notifications/constructor-create-steps.txt
index eb83f25f7e2..7d2663874b3 100644
--- a/Tests/LibWeb/Text/expected/notifications/constructor-create-steps.txt
+++ b/Tests/LibWeb/Text/expected/notifications/constructor-create-steps.txt
@@ -4,3 +4,7 @@ silent alone: created, actions frozen: true
vibrate alone: created, actions frozen: true
renotify without tag: TypeError
one action: TypeError
+renotify without tag, uncloneable data: TypeError
+silent with vibrate, uncloneable data: TypeError
+one action, uncloneable data: TypeError
+uncloneable data: DataCloneError
diff --git a/Tests/LibWeb/Text/input/notifications/constructor-create-steps.html b/Tests/LibWeb/Text/input/notifications/constructor-create-steps.html
index d51fc1fd8c9..3fad65beed2 100644
--- a/Tests/LibWeb/Text/input/notifications/constructor-create-steps.html
+++ b/Tests/LibWeb/Text/input/notifications/constructor-create-steps.html
@@ -17,5 +17,9 @@
attempt("vibrate alone", { vibrate: [100] });
attempt("renotify without tag", { renotify: true });
attempt("one action", { actions: [{ action: "a", title: "A" }] });
+ attempt("renotify without tag, uncloneable data", { renotify: true, data: () => {} });
+ attempt("silent with vibrate, uncloneable data", { silent: true, vibrate: [100], data: () => {} });
+ attempt("one action, uncloneable data", { actions: [{ action: "a", title: "A" }], data: () => {} });
+ attempt("uncloneable data", { data: () => {} });
});
</script>