frozen array in XRInputSourcesChangeEvent, update to_frozen_array doc (#34100)

* frozen array in XRInputSourcesChangeEvent, update 	o_frozen_array doc

Signed-off-by: L Ashwin B <lashwinib@gmail.com>

* simplified changes

Signed-off-by: L Ashwin B <lashwinib@gmail.com>

* added tests

Signed-off-by: L Ashwin B <lashwinib@gmail.com>

---------

Signed-off-by: L Ashwin B <lashwinib@gmail.com>
This commit is contained in:
chickenleaf 2024-11-02 19:57:59 +05:30 committed by GitHub
parent f47cc927a0
commit 900d13fc2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 18 additions and 13 deletions

View file

@ -116,7 +116,7 @@ impl Clone for DOMJSClass {
}
unsafe impl Sync for DOMJSClass {}
/// Returns a JSVal representing a frozen array of ports
/// Returns a JSVal representing the frozen JavaScript array
pub fn to_frozen_array<T: ToJSValConvertible>(convertibles: &[T], cx: SafeJSContext) -> JSVal {
rooted!(in(*cx) let mut ports = UndefinedValue());
unsafe { convertibles.to_jsval(*cx, ports.handle_mut()) };

View file

@ -3,9 +3,8 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use dom_struct::dom_struct;
use js::conversions::ToJSValConvertible;
use js::jsapi::Heap;
use js::jsval::{JSVal, UndefinedValue};
use js::jsval::JSVal;
use js::rust::HandleObject;
use servo_atoms::Atom;
@ -17,6 +16,7 @@ use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{reflect_dom_object_with_proto, DomObject};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString;
use crate::dom::bindings::utils::to_frozen_array;
use crate::dom::event::Event;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
@ -87,15 +87,8 @@ impl XRInputSourcesChangeEvent {
}
let _ac = enter_realm(global);
let cx = GlobalScope::get_cx();
unsafe {
rooted!(in(*cx) let mut added_val = UndefinedValue());
added.to_jsval(*cx, added_val.handle_mut());
changeevent.added.set(added_val.get());
rooted!(in(*cx) let mut removed_val = UndefinedValue());
removed.to_jsval(*cx, removed_val.handle_mut());
changeevent.removed.set(removed_val.get());
}
changeevent.added.set(to_frozen_array(added, cx));
changeevent.removed.set(to_frozen_array(removed, cx));
changeevent
}
}

View file

@ -844130,7 +844130,7 @@
]
],
"events_input_sources_change.https.html": [
"b2a17d4e17ae03bf7ed51e07095aa36dcce033a3",
"db8a8233fe55a920a077a644d711a455daf14b6b",
[
null,
{}

View file

@ -5,6 +5,7 @@
<script src="resources/webxr_test_constants.js"></script>
<script>
"use strict"
let testName = "Transient input sources fire events in the right order";
let watcherDone = new Event("watcherdone");
@ -25,6 +26,17 @@ let testFunction = function(session, fakeDeviceController, t) {
assert_equals(event.session, session);
validateSameObject(event);
assert_throws_js(
TypeError,
() => { event.added[0] = "test"; },
"added array must be frozen"
);
assert_throws_js(
TypeError,
() => { event.removed[0] = "test"; },
"removed array must be frozen"
);
// The first change event should be adding our controller.
if (inputChangeEvents === 1) {
validateAdded(event.added, 1);