mirror of
https://github.com/lexmount/moli.git
synced 2026-11-18 16:08:37 +00:00
fix(clipboard): align clipboard event interfaces
This commit is contained in:
@@ -192,6 +192,9 @@ pub(in crate::context_bootstrap) fn build_constructor_template_for_profile<'s>(
|
||||
ConstructorKind::ClipboardEvent => {
|
||||
build_event_subclass_template(scope, EventSubclassKind::ClipboardEvent)
|
||||
}
|
||||
ConstructorKind::ClipboardChangeEvent => {
|
||||
build_event_subclass_template(scope, EventSubclassKind::ClipboardChangeEvent)
|
||||
}
|
||||
ConstructorKind::ClipboardItem => {
|
||||
v8::FunctionTemplate::builder(moli_webapi_declare::web_api_constructor!(
|
||||
web_api_interfaces::ClipboardItem,
|
||||
|
||||
@@ -6,6 +6,8 @@ use super::{
|
||||
ui_event_init_callback,
|
||||
},
|
||||
events::{
|
||||
clipboard_change_event_change_id_getter_function, clipboard_change_event_types_getter_function,
|
||||
clipboard_event_clipboard_data_getter_function,
|
||||
toggle_event_source_getter_function,
|
||||
command_event_command_getter_function, command_event_source_getter_function,
|
||||
before_unload_event_return_value_getter_function,
|
||||
@@ -154,6 +156,29 @@ struct CloseEventTemplateAccessorsDeclaration {
|
||||
reason: (),
|
||||
}
|
||||
|
||||
#[derive(WebApiFunctionTemplate)]
|
||||
#[webapi(interface = web_api_interfaces::ClipboardEvent, enumerable, receiver)]
|
||||
struct ClipboardEventTemplateAccessorsDeclaration {
|
||||
#[webapi(
|
||||
accessor_property = "clipboardData",
|
||||
getter = clipboard_event_clipboard_data_getter_function
|
||||
)]
|
||||
clipboard_data: (),
|
||||
}
|
||||
|
||||
#[derive(WebApiFunctionTemplate)]
|
||||
#[webapi(interface = web_api_interfaces::ClipboardChangeEvent, enumerable, receiver)]
|
||||
struct ClipboardChangeEventTemplateAccessorsDeclaration {
|
||||
#[webapi(accessor_property, getter = clipboard_change_event_types_getter_function)]
|
||||
types: (),
|
||||
|
||||
#[webapi(
|
||||
accessor_property = "changeId",
|
||||
getter = clipboard_change_event_change_id_getter_function
|
||||
)]
|
||||
change_id: (),
|
||||
}
|
||||
|
||||
#[derive(WebApiFunctionTemplate)]
|
||||
#[webapi(interface = web_api_interfaces::TrackEvent, enumerable, receiver)]
|
||||
struct TrackEventTemplateAccessorsDeclaration {
|
||||
@@ -536,6 +561,8 @@ fn install_declaration<'s, D: WebApiFunctionTemplateDeclaration>(
|
||||
// prototype mutations cannot change which fields are exposed as own properties.
|
||||
fn event_template_declaration(interface: &str) -> Option<EventTemplateDeclaration> {
|
||||
Some(match interface {
|
||||
"ClipboardEvent" => EventTemplateDeclaration::new::<ClipboardEventTemplateAccessorsDeclaration>(),
|
||||
"ClipboardChangeEvent" => EventTemplateDeclaration::new::<ClipboardChangeEventTemplateAccessorsDeclaration>(),
|
||||
"ToggleEvent" => EventTemplateDeclaration::new::<ToggleEventTemplateAccessorsDeclaration>(),
|
||||
"CommandEvent" => EventTemplateDeclaration::new::<CommandEventTemplateAccessorsDeclaration>(),
|
||||
"BeforeUnloadEvent" => EventTemplateDeclaration::new::<BeforeUnloadEventTemplateAccessorsDeclaration>(),
|
||||
|
||||
@@ -47,6 +47,9 @@ const TRACK_EVENT_TRACK_SLOT: &str = "__moliTrackEventTrack";
|
||||
const COMMAND_EVENT_SOURCE_SLOT: &str = "__moliCommandEventSource";
|
||||
const COMMAND_EVENT_COMMAND_SLOT: &str = "__moliCommandEventCommand";
|
||||
const TOGGLE_EVENT_SOURCE_SLOT: &str = "__moliToggleEventSource";
|
||||
const CLIPBOARD_EVENT_CLIPBOARD_DATA_SLOT: &str = "__moliClipboardEventClipboardData";
|
||||
const CLIPBOARD_CHANGE_EVENT_TYPES_SLOT: &str = "__moliClipboardChangeEventTypes";
|
||||
const CLIPBOARD_CHANGE_EVENT_CHANGE_ID_SLOT: &str = "__moliClipboardChangeEventChangeId";
|
||||
const EVENT_SUBCLASS_KIND_SLOT: &str = "__moliEventSubclassKind";
|
||||
const BEFORE_UNLOAD_EVENT_RETURN_VALUE_SLOT: &str = "__moliBeforeUnloadEventReturnValue";
|
||||
#[derive(WebApiObject)]
|
||||
@@ -432,6 +435,54 @@ pub(super) fn mouse_event_related_target_getter_function<'s>(
|
||||
rv.set(event_related_target_value(scope, args.this()));
|
||||
}
|
||||
|
||||
pub(super) fn clipboard_event_clipboard_data_getter_function<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
args: v8::FunctionCallbackArguments<'s>,
|
||||
mut rv: v8::ReturnValue<'_, v8::Value>,
|
||||
) {
|
||||
if event_subclass_kind(scope, args.this()) != Some(EventSubclassKind::ClipboardEvent) {
|
||||
throw_type_error(scope, "Illegal invocation");
|
||||
return;
|
||||
}
|
||||
let value = get_private_value(scope, args.this(), CLIPBOARD_EVENT_CLIPBOARD_DATA_SLOT)
|
||||
.unwrap_or_else(|| v8::null(scope).into());
|
||||
rv.set(value);
|
||||
}
|
||||
|
||||
pub(super) fn clipboard_change_event_types_getter_function<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
args: v8::FunctionCallbackArguments<'s>,
|
||||
mut rv: v8::ReturnValue<'_, v8::Value>,
|
||||
) {
|
||||
if event_subclass_kind(scope, args.this()) != Some(EventSubclassKind::ClipboardChangeEvent) {
|
||||
throw_type_error(scope, "Illegal invocation");
|
||||
return;
|
||||
}
|
||||
let Some(value) = get_private_value(scope, args.this(), CLIPBOARD_CHANGE_EVENT_TYPES_SLOT)
|
||||
else {
|
||||
throw_type_error(scope, "Illegal invocation");
|
||||
return;
|
||||
};
|
||||
rv.set(value);
|
||||
}
|
||||
|
||||
pub(super) fn clipboard_change_event_change_id_getter_function<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
args: v8::FunctionCallbackArguments<'s>,
|
||||
mut rv: v8::ReturnValue<'_, v8::Value>,
|
||||
) {
|
||||
if event_subclass_kind(scope, args.this()) != Some(EventSubclassKind::ClipboardChangeEvent) {
|
||||
throw_type_error(scope, "Illegal invocation");
|
||||
return;
|
||||
}
|
||||
let Some(value) = get_private_value(scope, args.this(), CLIPBOARD_CHANGE_EVENT_CHANGE_ID_SLOT)
|
||||
else {
|
||||
throw_type_error(scope, "Illegal invocation");
|
||||
return;
|
||||
};
|
||||
rv.set(value);
|
||||
}
|
||||
|
||||
pub(super) use base::{
|
||||
clear_event_dispatch_fields, event_bubbles_getter_function, event_cancelable_getter_function,
|
||||
event_composed_getter_function, event_constructor_callback,
|
||||
|
||||
@@ -32,6 +32,7 @@ pub(in crate::context_bootstrap) enum EventSubclassKind {
|
||||
CapturedMouseEvent = 30,
|
||||
FontFaceSetLoadEvent = 31,
|
||||
HashChangeEvent = 32,
|
||||
ClipboardChangeEvent = 33,
|
||||
}
|
||||
|
||||
impl EventSubclassKind {
|
||||
@@ -69,6 +70,7 @@ impl EventSubclassKind {
|
||||
30 => Some(Self::CapturedMouseEvent),
|
||||
31 => Some(Self::FontFaceSetLoadEvent),
|
||||
32 => Some(Self::HashChangeEvent),
|
||||
33 => Some(Self::ClipboardChangeEvent),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -107,6 +109,7 @@ impl EventSubclassKind {
|
||||
Self::CapturedMouseEvent => "CapturedMouseEvent",
|
||||
Self::FontFaceSetLoadEvent => "FontFaceSetLoadEvent",
|
||||
Self::HashChangeEvent => "HashChangeEvent",
|
||||
Self::ClipboardChangeEvent => "ClipboardChangeEvent",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ enum SubclassInit<'s> {
|
||||
Basic(basic::BasicEventInit<'s>),
|
||||
Pointing(pointer::PointerEventInitPayload<'s>),
|
||||
Values(values::ValueEventInit<'s>),
|
||||
ClipboardChange(data::ClipboardChangeEventInitMembers<'s>),
|
||||
Interaction(input::InteractionEventInit<'s>),
|
||||
Payload(payload::PayloadEventInit<'s>),
|
||||
Font(FontFaceSetLoadEventInit<'s>),
|
||||
@@ -68,6 +69,9 @@ impl<'s> SubclassInit<'s> {
|
||||
| EventSubclassKind::PageTransitionEvent => {
|
||||
Self::Values(values::ValueEventInit::parse(scope, args, kind)?)
|
||||
}
|
||||
EventSubclassKind::ClipboardChangeEvent => Self::ClipboardChange(
|
||||
data::parse_clipboard_change_event_init(scope, args)?,
|
||||
),
|
||||
EventSubclassKind::InputEvent
|
||||
| EventSubclassKind::TouchEvent
|
||||
| EventSubclassKind::CapturedMouseEvent => {
|
||||
@@ -111,6 +115,7 @@ impl<'s> SubclassInit<'s> {
|
||||
Self::Basic(init) => init.event_flags(),
|
||||
Self::Pointing(init) => init.event_flags(),
|
||||
Self::Values(init) => init.event_flags(),
|
||||
Self::ClipboardChange(init) => init.event_flags(),
|
||||
Self::Interaction(init) => init.event_flags(),
|
||||
Self::Payload(init) => init.event_flags(),
|
||||
Self::Font(init) => init.event_flags(),
|
||||
@@ -133,6 +138,9 @@ impl<'s> SubclassInit<'s> {
|
||||
Self::Basic(init) => init.initialize(scope, event),
|
||||
Self::Pointing(init) => init.initialize(scope, event),
|
||||
Self::Values(init) => init.initialize(scope, event),
|
||||
Self::ClipboardChange(init) => {
|
||||
return data::initialize_clipboard_change_event(scope, event, init);
|
||||
}
|
||||
Self::Interaction(init) => return init.initialize(scope, event),
|
||||
Self::Payload(init) => init.initialize(scope, event),
|
||||
Self::Font(init) => init.initialize(scope, event),
|
||||
|
||||
@@ -783,3 +783,128 @@ pub(in crate::context_bootstrap::events) fn initialize_navigate_event_methods<'s
|
||||
.initialize(scope, event)
|
||||
.expect("NavigateEvent methods declaration should initialize");
|
||||
}
|
||||
|
||||
|
||||
#[derive(webidl::WebIdlDictionary)]
|
||||
#[webidl(prefix = "ClipboardChangeEventInit")]
|
||||
pub(super) struct ClipboardChangeEventInitMembers<'scope> {
|
||||
#[webidl(inherit)]
|
||||
base: EventInit,
|
||||
#[webidl(name = "changeId", with = clipboard_change_event_change_id_member)]
|
||||
change_id: v8::Local<'scope, v8::BigInt>,
|
||||
#[webidl(with = clipboard_change_event_types_member)]
|
||||
types: Vec<v8::Local<'scope, v8::String>>,
|
||||
}
|
||||
|
||||
struct ClipboardChangeEventType<'scope>(v8::Local<'scope, v8::String>);
|
||||
|
||||
impl<'scope> webidl::WebIdlConverter<'scope> for ClipboardChangeEventType<'scope> {
|
||||
type Options = ();
|
||||
|
||||
fn convert(
|
||||
scope: &mut v8::PinScope<'scope, '_>,
|
||||
value: v8::Local<'scope, v8::Value>,
|
||||
context: webidl::Context,
|
||||
_options: &Self::Options,
|
||||
) -> Result<Self, webidl::WebIdlError> {
|
||||
value
|
||||
.to_string(scope)
|
||||
.map(Self)
|
||||
.ok_or_else(|| webidl::WebIdlError::pending_exception(context))
|
||||
}
|
||||
}
|
||||
|
||||
impl ClipboardChangeEventInitMembers<'_> {
|
||||
pub(super) fn event_flags(&self) -> (bool, bool, bool) {
|
||||
(self.base.bubbles, self.base.cancelable, self.base.composed)
|
||||
}
|
||||
}
|
||||
|
||||
fn clipboard_change_event_change_id_member<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
object: v8::Local<'s, v8::Object>,
|
||||
name: &'static str,
|
||||
) -> Result<v8::Local<'s, v8::BigInt>, webidl::WebIdlError> {
|
||||
let context = webidl::Context::member("ClipboardChangeEventInit", name);
|
||||
let Some(value) = webidl::property_result(scope, object, name, context)? else {
|
||||
return Ok(v8::BigInt::new_from_u64(scope, 0));
|
||||
};
|
||||
if value.is_undefined() {
|
||||
return Ok(v8::BigInt::new_from_u64(scope, 0));
|
||||
}
|
||||
value
|
||||
.to_big_int(scope)
|
||||
.ok_or_else(|| webidl::WebIdlError::pending_exception(context))
|
||||
}
|
||||
|
||||
fn clipboard_change_event_types_member<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
object: v8::Local<'s, v8::Object>,
|
||||
name: &'static str,
|
||||
) -> Result<Vec<v8::Local<'s, v8::String>>, webidl::WebIdlError> {
|
||||
let context = webidl::Context::member("ClipboardChangeEventInit", name);
|
||||
let Some(value) = webidl::property_result(scope, object, name, context)? else {
|
||||
return Ok(Vec::new());
|
||||
};
|
||||
if value.is_undefined() {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
webidl::convert::<webidl::Sequence<ClipboardChangeEventType<'s>>>(scope, value, context)
|
||||
.map(|sequence| sequence.0.into_iter().map(|value| value.0).collect())
|
||||
}
|
||||
|
||||
pub(super) fn parse_clipboard_change_event_init<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
args: &v8::FunctionCallbackArguments<'s>,
|
||||
) -> Option<ClipboardChangeEventInitMembers<'s>> {
|
||||
let context = webidl::Context::argument("ClipboardChangeEvent", 2);
|
||||
let object = match webidl::dictionary_arg(args, 1, context) {
|
||||
Ok(object) => object,
|
||||
Err(error) => {
|
||||
webidl::throw_error(scope, &error);
|
||||
return None;
|
||||
}
|
||||
};
|
||||
let Some(object) = object else {
|
||||
return Some(ClipboardChangeEventInitMembers {
|
||||
base: EventInit::default(),
|
||||
change_id: v8::BigInt::new_from_u64(scope, 0),
|
||||
types: Vec::new(),
|
||||
});
|
||||
};
|
||||
match webidl::parse_dictionary_object(scope, object) {
|
||||
Ok(init) => Some(init),
|
||||
Err(error) => {
|
||||
webidl::throw_error(scope, &error);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(in crate::context_bootstrap::events::subclasses) fn initialize_clipboard_change_event<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
event: v8::Local<'s, v8::Object>,
|
||||
init: ClipboardChangeEventInitMembers<'s>,
|
||||
) -> bool {
|
||||
let mut elements = Vec::with_capacity(init.types.len());
|
||||
for event_type in init.types {
|
||||
elements.push(event_type.into());
|
||||
}
|
||||
let types = v8::Array::new_with_elements(scope, &elements);
|
||||
if types.set_integrity_level(scope, v8::IntegrityLevel::Frozen) != Some(true) {
|
||||
return false;
|
||||
}
|
||||
set_private_value(
|
||||
scope,
|
||||
event,
|
||||
CLIPBOARD_CHANGE_EVENT_TYPES_SLOT,
|
||||
types.into(),
|
||||
);
|
||||
set_private_value(
|
||||
scope,
|
||||
event,
|
||||
CLIPBOARD_CHANGE_EVENT_CHANGE_ID_SLOT,
|
||||
init.change_id.into(),
|
||||
);
|
||||
true
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use webidl::WebIdlDictionarySerialize;
|
||||
pub(super) struct ClipboardInit<'s> {
|
||||
#[webidl(inherit)]
|
||||
base: EventInit,
|
||||
#[webidl(nullable, interface = web_api_interfaces::DataTransfer)]
|
||||
#[webidl(nullable, interface = web_api_interfaces::DataTransfer, snapshot_slot = CLIPBOARD_EVENT_CLIPBOARD_DATA_SLOT)]
|
||||
clipboard_data: Option<v8::Local<'s, v8::Object>>,
|
||||
}
|
||||
|
||||
|
||||
@@ -392,6 +392,10 @@ const CONSTRUCTOR_SPECS_BEFORE_STREAMS: &[ConstructorSpec] = &[
|
||||
interface: web_api_interfaces::ClipboardEvent::DESCRIPTOR,
|
||||
kind: ConstructorKind::ClipboardEvent,
|
||||
},
|
||||
ConstructorSpec {
|
||||
interface: web_api_interfaces::ClipboardChangeEvent::DESCRIPTOR,
|
||||
kind: ConstructorKind::ClipboardChangeEvent,
|
||||
},
|
||||
ConstructorSpec {
|
||||
interface: web_api_interfaces::KeyboardEvent::DESCRIPTOR,
|
||||
kind: ConstructorKind::KeyboardEvent,
|
||||
|
||||
@@ -27,6 +27,7 @@ pub(in crate::context_bootstrap) enum ConstructorKind {
|
||||
CapturedMouseEvent,
|
||||
DragEvent,
|
||||
ClipboardEvent,
|
||||
ClipboardChangeEvent,
|
||||
ClipboardItem,
|
||||
KeyboardEvent,
|
||||
InputEvent,
|
||||
|
||||
@@ -1110,3 +1110,262 @@ fn popover_show_rejects_owner_document_changes_during_toggle_steps() {
|
||||
r#"{"showRejected":true,"showStayedClosed":true,"hideThrew":false,"hideClosed":true,"dismissRejected":true,"dismissStayedClosed":true}"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clipboard_event_uses_a_branded_prototype_accessor_and_webidl_dictionary() {
|
||||
let mut vm = new_storage_test_vm("https://clipboard-event-webidl.test/");
|
||||
|
||||
let result = vm
|
||||
.eval(
|
||||
r#"
|
||||
(() => {
|
||||
const transfer = new DataTransfer();
|
||||
const defaults = new ClipboardEvent("copy");
|
||||
const descriptor = Object.getOwnPropertyDescriptor(
|
||||
ClipboardEvent.prototype,
|
||||
"clipboardData"
|
||||
);
|
||||
const errorName = callback => {
|
||||
try {
|
||||
callback();
|
||||
return "none";
|
||||
} catch (error) {
|
||||
return error && error.name;
|
||||
}
|
||||
};
|
||||
|
||||
const order = [];
|
||||
const init = {};
|
||||
for (const [name, value] of [
|
||||
["bubbles", true],
|
||||
["cancelable", true],
|
||||
["clipboardData", transfer],
|
||||
["composed", true]
|
||||
]) {
|
||||
Object.defineProperty(init, name, {
|
||||
get() {
|
||||
order.push(name);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
const initialized = new ClipboardEvent("paste", init);
|
||||
|
||||
const sentinel = {};
|
||||
let preservesGetterException = false;
|
||||
try {
|
||||
new ClipboardEvent("copy", {
|
||||
get clipboardData() {
|
||||
throw sentinel;
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
preservesGetterException = error === sentinel;
|
||||
}
|
||||
|
||||
return JSON.stringify({
|
||||
defaults: [
|
||||
defaults.clipboardData === null,
|
||||
Object.hasOwn(defaults, "clipboardData")
|
||||
],
|
||||
initialized: [
|
||||
initialized.clipboardData === transfer,
|
||||
initialized.bubbles,
|
||||
initialized.cancelable,
|
||||
initialized.composed,
|
||||
Object.hasOwn(initialized, "clipboardData")
|
||||
],
|
||||
descriptor: [
|
||||
typeof descriptor.get,
|
||||
descriptor.get.name,
|
||||
descriptor.get.length,
|
||||
typeof descriptor.set,
|
||||
descriptor.enumerable,
|
||||
descriptor.configurable
|
||||
],
|
||||
order,
|
||||
errors: [
|
||||
errorName(() => descriptor.get.call({})),
|
||||
errorName(() => new ClipboardEvent("copy", {clipboardData: {}})),
|
||||
errorName(() => new ClipboardEvent("copy", 1))
|
||||
],
|
||||
preservesGetterException
|
||||
});
|
||||
})()
|
||||
"#,
|
||||
)
|
||||
.expect("ClipboardEvent WebIDL probe should evaluate");
|
||||
|
||||
assert_eq!(
|
||||
result,
|
||||
r#"{"defaults":[true,false],"initialized":[true,true,true,true,false],"descriptor":["function","get clipboardData",0,"undefined",true,true],"order":["bubbles","cancelable","composed","clipboardData"],"errors":["TypeError","TypeError","TypeError"],"preservesGetterException":true}"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clipboard_change_event_exposes_frozen_types_and_bigint_change_id() {
|
||||
let mut vm = new_storage_test_vm("http://clipboard-change-event.test/");
|
||||
|
||||
let result = vm
|
||||
.eval(
|
||||
r#"
|
||||
(() => {
|
||||
const defaults = new ClipboardChangeEvent("clipboardchange");
|
||||
const order = [];
|
||||
const sourceTypes = [
|
||||
{
|
||||
toString() {
|
||||
order.push("type item");
|
||||
return "text/plain";
|
||||
}
|
||||
},
|
||||
"text/html",
|
||||
"\uD800"
|
||||
];
|
||||
const expectedChangeId = -(1n << 100n) + 123n;
|
||||
const init = {};
|
||||
for (const [name, value] of [
|
||||
["bubbles", true],
|
||||
["cancelable", true],
|
||||
["changeId", expectedChangeId],
|
||||
["composed", true],
|
||||
["types", sourceTypes]
|
||||
]) {
|
||||
Object.defineProperty(init, name, {
|
||||
get() {
|
||||
order.push(name);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
const initialized = new ClipboardChangeEvent("clipboardchange", init);
|
||||
sourceTypes[0] = "changed";
|
||||
sourceTypes.push("image/png");
|
||||
|
||||
const typesDescriptor = Object.getOwnPropertyDescriptor(
|
||||
ClipboardChangeEvent.prototype,
|
||||
"types"
|
||||
);
|
||||
const changeIdDescriptor = Object.getOwnPropertyDescriptor(
|
||||
ClipboardChangeEvent.prototype,
|
||||
"changeId"
|
||||
);
|
||||
const accessor = descriptor => [
|
||||
typeof descriptor.get,
|
||||
descriptor.get.name,
|
||||
descriptor.get.length,
|
||||
typeof descriptor.set,
|
||||
descriptor.enumerable,
|
||||
descriptor.configurable
|
||||
];
|
||||
const errorName = callback => {
|
||||
try {
|
||||
callback();
|
||||
return "none";
|
||||
} catch (error) {
|
||||
return error && error.name;
|
||||
}
|
||||
};
|
||||
|
||||
return JSON.stringify({
|
||||
constructor: [
|
||||
typeof ClipboardChangeEvent,
|
||||
ClipboardChangeEvent.name,
|
||||
ClipboardChangeEvent.length,
|
||||
ClipboardChangeEvent.prototype instanceof Event,
|
||||
isSecureContext
|
||||
],
|
||||
defaults: [
|
||||
defaults instanceof ClipboardChangeEvent,
|
||||
defaults instanceof Event,
|
||||
defaults.types.length,
|
||||
Object.isFrozen(defaults.types),
|
||||
defaults.types === defaults.types,
|
||||
defaults.changeId === 0n,
|
||||
Object.hasOwn(defaults, "types"),
|
||||
Object.hasOwn(defaults, "changeId"),
|
||||
Object.prototype.toString.call(defaults)
|
||||
],
|
||||
initialized: [
|
||||
initialized.bubbles,
|
||||
initialized.cancelable,
|
||||
initialized.composed,
|
||||
initialized.types.slice(0, 2).join(","),
|
||||
initialized.types.length,
|
||||
initialized.types[2].charCodeAt(0) === 0xD800,
|
||||
initialized.types === initialized.types,
|
||||
Object.isFrozen(initialized.types),
|
||||
String(initialized.changeId),
|
||||
initialized.changeId === expectedChangeId
|
||||
],
|
||||
accessors: [accessor(typesDescriptor), accessor(changeIdDescriptor)],
|
||||
keys: Object.keys(ClipboardChangeEvent.prototype),
|
||||
order,
|
||||
booleanBigInt: new ClipboardChangeEvent("x", {changeId: true}).changeId === 1n,
|
||||
errors: [
|
||||
errorName(() => ClipboardChangeEvent("x")),
|
||||
errorName(() => new ClipboardChangeEvent()),
|
||||
errorName(() => new ClipboardChangeEvent("x", 1)),
|
||||
errorName(() => new ClipboardChangeEvent("x", {changeId: 1})),
|
||||
errorName(() => new ClipboardChangeEvent("x", {types: null})),
|
||||
errorName(() => typesDescriptor.get.call({})),
|
||||
errorName(() => changeIdDescriptor.get.call({}))
|
||||
]
|
||||
});
|
||||
})()
|
||||
"#,
|
||||
)
|
||||
.expect("ClipboardChangeEvent WebIDL probe should evaluate");
|
||||
|
||||
assert_eq!(
|
||||
result,
|
||||
r#"{"constructor":["function","ClipboardChangeEvent",1,true,false],"defaults":[true,true,0,true,true,true,false,false,"[object ClipboardChangeEvent]"],"initialized":[true,true,true,"text/plain,text/html",3,true,true,true,"-1267650600228229401496703205253",true],"accessors":[["function","get types",0,"undefined",true,true],["function","get changeId",0,"undefined",true,true]],"keys":["types","changeId"],"order":["bubbles","cancelable","composed","changeId","types","type item"],"booleanBigInt":true,"errors":["TypeError","TypeError","TypeError","TypeError","TypeError","TypeError","TypeError"]}"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clipboard_event_dictionaries_convert_event_init_before_derived_members() {
|
||||
let mut vm = new_storage_test_vm("https://clipboard-event-dictionary-order.test/");
|
||||
let result = vm.eval(r#"
|
||||
(() => {
|
||||
const checks = [];
|
||||
for (const [Ctor, derivedMember] of [
|
||||
[ClipboardEvent, 'clipboardData'], [ClipboardChangeEvent, 'changeId']
|
||||
]) {
|
||||
for (const baseMember of ['bubbles', 'cancelable', 'composed']) {
|
||||
const baseError = new RangeError('base getter');
|
||||
const derivedError = new TypeError('derived getter');
|
||||
const reads = [];
|
||||
const init = {};
|
||||
Object.defineProperty(init, baseMember, {get() {
|
||||
reads.push(baseMember);
|
||||
throw baseError;
|
||||
}});
|
||||
Object.defineProperty(init, derivedMember, {get() {
|
||||
reads.push(derivedMember);
|
||||
throw derivedError;
|
||||
}});
|
||||
try { new Ctor('change', init); checks.push(false); }
|
||||
catch (error) { checks.push(error === baseError); }
|
||||
checks.push(reads.length === 1, reads[0] === baseMember);
|
||||
}
|
||||
}
|
||||
const transfer = new DataTransfer();
|
||||
const clipboardInit = {
|
||||
clipboardData: {},
|
||||
get composed() { this.clipboardData = transfer; return true; }
|
||||
};
|
||||
const clipboard = new ClipboardEvent('copy', clipboardInit);
|
||||
checks.push(clipboard.composed, clipboard.clipboardData === transfer);
|
||||
const changeInit = {
|
||||
changeId: 1,
|
||||
get composed() { this.changeId = 42n; return true; },
|
||||
types: ['text/plain']
|
||||
};
|
||||
const change = new ClipboardChangeEvent('clipboardchange', changeInit);
|
||||
checks.push(change.composed, change.changeId === 42n, change.types[0] === 'text/plain');
|
||||
return checks.every(Boolean) || JSON.stringify(checks);
|
||||
})()
|
||||
"#).expect("Clipboard dictionary conversion should stop on base errors and observe base getter mutations first");
|
||||
assert_eq!(result, "true");
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@ fn web_platform_surface_stubs_are_present_and_brand_correctly() {
|
||||
"CompressionStream","DecompressionStream",
|
||||
"ReadableStreamBYOBReader","ReadableStreamBYOBRequest","ReadableByteStreamController",
|
||||
"Geolocation","GeolocationPosition","GeolocationCoordinates","GeolocationPositionError",
|
||||
"MediaCapabilities","Clipboard","ClipboardItem",
|
||||
"MediaCapabilities","Clipboard","ClipboardItem","ClipboardChangeEvent",
|
||||
];
|
||||
const out = [];
|
||||
for (const name of names) {
|
||||
@@ -267,6 +267,7 @@ fn web_platform_surface_stubs_are_present_and_brand_correctly() {
|
||||
out.push(`DOMRect<DOMRectReadOnly:${DOMRect.prototype instanceof DOMRectReadOnly}`);
|
||||
out.push(`DOMPoint<DOMPointReadOnly:${DOMPoint.prototype instanceof DOMPointReadOnly}`);
|
||||
out.push(`Clipboard<EventTarget:${Clipboard.prototype instanceof EventTarget}`);
|
||||
out.push(`ClipboardChangeEvent<Event:${ClipboardChangeEvent.prototype instanceof Event}`);
|
||||
return out.join("|");
|
||||
})()
|
||||
"#,
|
||||
@@ -304,11 +305,13 @@ fn web_platform_surface_stubs_are_present_and_brand_correctly() {
|
||||
"MediaCapabilities:function:true",
|
||||
"Clipboard:function:true",
|
||||
"ClipboardItem:function:true",
|
||||
"ClipboardChangeEvent:function:true",
|
||||
"ToggleEvent<Event:true",
|
||||
"HashChangeEvent<Event:true",
|
||||
"DOMRect<DOMRectReadOnly:true",
|
||||
"DOMPoint<DOMPointReadOnly:true",
|
||||
"Clipboard<EventTarget:true",
|
||||
"ClipboardChangeEvent<Event:true",
|
||||
];
|
||||
assert_eq!(result, expected_parts.join("|"));
|
||||
}
|
||||
|
||||
@@ -623,6 +623,7 @@ fn navigator_scalar_access_does_not_materialize_unused_same_object_children() {
|
||||
"MediaCapabilities",
|
||||
"Clipboard",
|
||||
"ClipboardItem",
|
||||
"ClipboardChangeEvent",
|
||||
] {
|
||||
assert_eq!(
|
||||
constructor_materialization_count(&mut vm, name),
|
||||
|
||||
@@ -108,6 +108,7 @@ interfaces! {
|
||||
Clients;
|
||||
Clipboard: EventTarget;
|
||||
ClipboardEvent: Event;
|
||||
ClipboardChangeEvent: Event;
|
||||
ClipboardItem;
|
||||
CloseEvent: Event;
|
||||
CommandEvent: Event;
|
||||
|
||||
Reference in New Issue
Block a user