mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #26434 - jdm:playground, r=Manishearth
Allow BabylonJS playground to load These changes fix the JS errors that currently appear when loading the page. You can't use the editor, but the webgl canvas works just fine. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #26428 and fix #25478 - [x] There are tests for these changes
This commit is contained in:
commit
52d9fb57fb
9 changed files with 69 additions and 46 deletions
|
@ -3669,6 +3669,11 @@ impl ProfilerMetadataFactory for Document {
|
|||
}
|
||||
|
||||
impl DocumentMethods for Document {
|
||||
// https://w3c.github.io/editing/ActiveDocuments/execCommand.html#querycommandsupported()
|
||||
fn QueryCommandSupported(&self, _command: DOMString) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom/#dom-document-stylesheets
|
||||
fn StyleSheets(&self) -> DomRoot<StyleSheetList> {
|
||||
self.stylesheet_list.or_init(|| {
|
||||
|
|
|
@ -690,12 +690,15 @@ fn inner_invoke(
|
|||
object.remove_listener_if_once(&event.type_(), &event_listener);
|
||||
}
|
||||
|
||||
// Step 2.6-2.8
|
||||
// FIXME(#25478): we need to get the global that the event
|
||||
// listener is going to be called on, then if it's a Window
|
||||
// set its .event to the event, remembering the previous
|
||||
// value of its .event. This allows events to just use
|
||||
// the word "event" instead of taking the event as an argument.
|
||||
// Step 2.6
|
||||
let global = listener.associated_global();
|
||||
|
||||
// Step 2.7-2.8
|
||||
let current_event = if let Some(window) = global.downcast::<Window>() {
|
||||
window.set_current_event(Some(event))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// Step 2.9 TODO: EventListener passive option not implemented
|
||||
|
||||
|
@ -712,8 +715,9 @@ fn inner_invoke(
|
|||
// Step 2.11 TODO: passive not implemented
|
||||
|
||||
// Step 2.12
|
||||
// TODO This is where we put back the .event we
|
||||
// had before step 2.6.
|
||||
if let Some(window) = global.downcast::<Window>() {
|
||||
window.set_current_event(current_event.as_ref().map(|e| &**e));
|
||||
}
|
||||
|
||||
// Step 2.13: short-circuit instead of going to next listener
|
||||
if event.stop_immediate.get() {
|
||||
|
|
|
@ -150,6 +150,23 @@ pub enum CompiledEventListener {
|
|||
}
|
||||
|
||||
impl CompiledEventListener {
|
||||
#[allow(unsafe_code)]
|
||||
pub fn associated_global(&self) -> DomRoot<GlobalScope> {
|
||||
let obj = match self {
|
||||
CompiledEventListener::Listener(listener) => listener.callback(),
|
||||
CompiledEventListener::Handler(CommonEventHandler::EventHandler(handler)) => {
|
||||
handler.callback()
|
||||
},
|
||||
CompiledEventListener::Handler(CommonEventHandler::ErrorEventHandler(handler)) => {
|
||||
handler.callback()
|
||||
},
|
||||
CompiledEventListener::Handler(CommonEventHandler::BeforeUnloadEventHandler(
|
||||
handler,
|
||||
)) => handler.callback(),
|
||||
};
|
||||
unsafe { GlobalScope::from_object(obj) }
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#the-event-handler-processing-algorithm
|
||||
pub fn call_or_handle_event(
|
||||
&self,
|
||||
|
|
|
@ -142,7 +142,7 @@ partial /*sealed*/ interface Document {
|
|||
// boolean queryCommandEnabled(DOMString commandId);
|
||||
// boolean queryCommandIndeterm(DOMString commandId);
|
||||
// boolean queryCommandState(DOMString commandId);
|
||||
// boolean queryCommandSupported(DOMString commandId);
|
||||
boolean queryCommandSupported(DOMString commandId);
|
||||
// DOMString queryCommandValue(DOMString commandId);
|
||||
|
||||
// special event handler IDL attributes that only apply to Document objects
|
||||
|
|
|
@ -180,6 +180,10 @@ partial interface Window {
|
|||
Selection? getSelection();
|
||||
};
|
||||
|
||||
// https://dom.spec.whatwg.org/#interface-window-extensions
|
||||
partial interface Window {
|
||||
[Replaceable] readonly attribute any event; // historical
|
||||
};
|
||||
|
||||
dictionary WindowPostMessageOptions : PostMessageOptions {
|
||||
USVString targetOrigin = "/";
|
||||
|
|
|
@ -83,6 +83,7 @@ use euclid::default::{Point2D as UntypedPoint2D, Rect as UntypedRect};
|
|||
use euclid::{Point2D, Rect, Scale, Size2D, Vector2D};
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use ipc_channel::router::ROUTER;
|
||||
use js::conversions::ToJSValConvertible;
|
||||
use js::jsapi::Heap;
|
||||
use js::jsapi::JSAutoRealm;
|
||||
use js::jsapi::JSObject;
|
||||
|
@ -340,6 +341,9 @@ pub struct Window {
|
|||
/// those values will cause the marker to be set to false.
|
||||
#[ignore_malloc_size_of = "Rc is hard"]
|
||||
layout_marker: DomRefCell<Rc<Cell<bool>>>,
|
||||
|
||||
/// https://dom.spec.whatwg.org/#window-current-event
|
||||
current_event: DomRefCell<Option<Dom<Event>>>,
|
||||
}
|
||||
|
||||
impl Window {
|
||||
|
@ -1334,9 +1338,34 @@ impl WindowMethods for Window {
|
|||
fn GetSelection(&self) -> Option<DomRoot<Selection>> {
|
||||
self.document.get().and_then(|d| d.GetSelection())
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-window-event
|
||||
#[allow(unsafe_code)]
|
||||
fn Event(&self, cx: JSContext) -> JSVal {
|
||||
rooted!(in(*cx) let mut rval = UndefinedValue());
|
||||
if let Some(ref event) = *self.current_event.borrow() {
|
||||
unsafe {
|
||||
event
|
||||
.reflector()
|
||||
.get_jsobject()
|
||||
.to_jsval(*cx, rval.handle_mut());
|
||||
}
|
||||
}
|
||||
rval.get()
|
||||
}
|
||||
}
|
||||
|
||||
impl Window {
|
||||
pub(crate) fn set_current_event(&self, event: Option<&Event>) -> Option<DomRoot<Event>> {
|
||||
let current = self
|
||||
.current_event
|
||||
.borrow()
|
||||
.as_ref()
|
||||
.map(|e| DomRoot::from_ref(&**e));
|
||||
*self.current_event.borrow_mut() = event.map(|e| Dom::from_ref(e));
|
||||
current
|
||||
}
|
||||
|
||||
/// https://html.spec.whatwg.org/multipage/#window-post-message-steps
|
||||
fn post_message_impl(
|
||||
&self,
|
||||
|
@ -2375,6 +2404,7 @@ impl Window {
|
|||
event_loop_waker,
|
||||
visible: Cell::new(true),
|
||||
layout_marker: DomRefCell::new(Rc::new(Cell::new(true))),
|
||||
current_event: DomRefCell::new(None),
|
||||
});
|
||||
|
||||
unsafe { WindowBinding::Wrap(JSContext::from_ptr(runtime.cx()), win) }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue