Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upMutation observer API #16190
Mutation observer API #16190
Conversation
…Observer-dev merging changes from upstream Merge branch 'master' of https://github.com/servo/servo into MutationObserver-dev merging changes from upstream
…Observer-dev merge from upstream
…Observer-dev merged from upstream
…Observer-dev merge upstream
highfive
commented
Mar 30, 2017
|
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @emilio (or someone else) soon. |
highfive
commented
Mar 30, 2017
|
Heads up! This PR modifies the following files:
|
highfive
commented
Mar 30, 2017
| @@ -18,6 +18,16 @@ DOMInterfaces = { | |||
| 'weakReferenceable': True, | |||
| }, | |||
|
|
|||
| 'MutationObserver': { | |||
This comment has been minimized.
This comment has been minimized.
|
|
||
| impl MutationObserver { | ||
|
|
||
| fn new(global: &dom::bindings::js::Root<dom::window::Window>, callback: MutationCallback) -> MutationObserver { |
This comment has been minimized.
This comment has been minimized.
| @@ -1,5 +1,5 @@ | |||
| [contenttype_javascripturi.html] | |||
| type: testharness | |||
| [Javascript URI document.contentType === 'text/html'] | |||
| expected: FAIL | |||
| expected: TIMEOUT | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
jdm
Mar 30, 2017
Member
An easy way to check is to make a build on a branch that does not include any of the changes in this PR and run the tests again.
This comment has been minimized.
This comment has been minimized.
krishnakarthick1993
Apr 1, 2017
•
Those tests timed out without our changes. We ran the tests on a unmodified servo code.
|
r? @jdm |
|
This is a good start! Please remove the |
| } | ||
| } | ||
|
|
||
| pub fn Constructor(global: &dom::bindings::js::Root<dom::window::Window>, callback: Rc<MutationCallback>) -> Result<Root<MutationObserver>, Error> { |
This comment has been minimized.
This comment has been minimized.
| pub fn Constructor(global: &dom::bindings::js::Root<dom::window::Window>, callback: Rc<MutationCallback>) -> Result<Root<MutationObserver>, Error> { | ||
| let observer = MutationObserver::new(global, &callback); | ||
| ScriptThread.set_mutation_observer(observer) | ||
| } |
This comment has been minimized.
This comment has been minimized.
jdm
Mar 30, 2017
Member
This can't compile right now since the return type doesn't match what the code is doing. Please use the new/new_inherited methods from other files in dom/ as a guide.
|
|
||
| impl MutationObserverMethods for MutationObserver { | ||
|
|
||
| //void observe(Node target, optional MutationObserverInit options); |
This comment has been minimized.
This comment has been minimized.
jdm
Mar 30, 2017
Member
The comments should contain links to the DOM specification like https://dom.spec.whatwg.org/#dom-mutationobserver-observe instead.
| pub struct MutationRecord { | ||
| reflector_: Reflector, | ||
|
|
||
| // readonly attribute DOMString record_type; |
This comment has been minimized.
This comment has been minimized.
jdm
Mar 30, 2017
Member
Rather than duplicating IDL constructs in the comments, we should be describing what these fields used are for in English prose instead.
| @@ -480,6 +481,9 @@ pub struct ScriptThread { | |||
|
|
|||
| microtask_queue: MicrotaskQueue, | |||
|
|
|||
| /// a vector of MutationObserver objects | |||
| mutation_observers: Vec<MutationObserver>, | |||
This comment has been minimized.
This comment has been minimized.
| @@ -1,5 +1,5 @@ | |||
| [contenttype_javascripturi.html] | |||
| type: testharness | |||
| [Javascript URI document.contentType === 'text/html'] | |||
| expected: FAIL | |||
| expected: TIMEOUT | |||
This comment has been minimized.
This comment has been minimized.
jdm
Mar 30, 2017
Member
An easy way to check is to make a build on a branch that does not include any of the changes in this PR and run the tests again.
| readonly attribute Node? nextSibling; | ||
| readonly attribute DOMString? attributeName; | ||
| readonly attribute DOMString? attributeNamespace; | ||
| readonly attribute DOMString? oldValue; |
This comment has been minimized.
This comment has been minimized.
jdm
Mar 30, 2017
Member
Rather than implementing stubs for all of these attributes, let's comment out all of them in this file except for type and target. We can uncomment them when we give them real implementations.
| interface MutationObserver { | ||
| void observe(Node target, optional MutationObserverInit options); | ||
| void disconnect(); | ||
| sequence<MutationRecord> takeRecords(); |
This comment has been minimized.
This comment has been minimized.
jdm
Mar 30, 2017
Member
Let's comment out all of these methods in this file until we actually implement them.
| attributeNamespace: DOMString, | ||
|
|
||
| // readonly attribute DOMString? oldValue; | ||
| oldValue: DOMString, |
This comment has been minimized.
This comment has been minimized.
jdm
Mar 30, 2017
Member
Given my request to remove the methods we don't implement yet, let's remove all of these members except for record_type and target.
|
|
||
| // [SameObject] | ||
| // readonly attribute Node target; | ||
| target: Root<Node>, |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
srivassumit
Mar 31, 2017
•
Author
Contributor
Hi Josh, when I make this change, it gives me the following error:
error[E0053]: method Targethas an incompatible type for trait --> /home/sumit/Dropbox/NCSU/OODD/Servo/MyWork/servo/components/script/dom/mutationrecord.rs:38:25 | 38 | fn Target(&self) -> JS<Node> { | ^^^^^^^^ expected structdom::bindings::js::Root, found struct dom::bindings::js::JS| ::: /home/sumit/Dropbox/NCSU/OODD/Servo/MyWork/servo/target/debug/build/script-bb44ff0630eb7b72/out/Bindings/MutationRecordBinding.rs | 617 | fn Target(&self) -> Root<Node>; | ---------- type in trait | = note: expected typefn(&dom::mutationrecord::MutationRecord) -> dom::bindings::js::Rootdom::node::Nodefound typefn(&dom::mutationrecord::MutationRecord) -> dom::bindings::js::JSdom::node::Node`
It seems that it is expecting a Root element in the '/servo/target/debug/build/script-bb44ff0630eb7b72/out/Bindings/MutationRecordBinding.rs' file
This comment has been minimized.
This comment has been minimized.
KiChjang
Mar 31, 2017
Member
The field in the struct should be JS<Node>, but the return value of fn Target(&self) should be Root<Node>. Use Root::from_ref(&*self.target) to get a Root<T> from a JS<T>.
|
Also, I'm very confused that
|
made the changes as per the review comments in PR
| let observer = MutationObserver::new(global, Rc::deref(&callback)); | ||
| ScriptThread::add_mutation_observer(&observer) | ||
| pub fn Constructor(global: &Window, callback: Rc<MutationCallback>) -> Fallible<Root<MutationObserver>> { | ||
| let observer = MutationObserver::new(global, callback); |
This comment has been minimized.
This comment has been minimized.
jdm
Apr 5, 2017
Member
You should be calling reflect_dom_object here (per the documentation); follow the pattern of other code that has a constructor method like Blob.
| ScriptThread::add_mutation_observer(&observer) | ||
| pub fn Constructor(global: &Window, callback: Rc<MutationCallback>) -> Fallible<Root<MutationObserver>> { | ||
| let observer = MutationObserver::new(global, callback); | ||
| ScriptThread::add_mutation_observer(Root::from_ref(&*observer)) |
This comment has been minimized.
This comment has been minimized.
jdm
Apr 5, 2017
Member
add_mutation_observer should accept a &MutationObserver argument instead of Root<MutationObserver>.
| ScriptThread::add_mutation_observer(&observer) | ||
| pub fn Constructor(global: &Window, callback: Rc<MutationCallback>) -> Fallible<Root<MutationObserver>> { | ||
| let observer = MutationObserver::new(global, callback); | ||
| ScriptThread::add_mutation_observer(Root::from_ref(&*observer)) | ||
| } |
This comment has been minimized.
This comment has been minimized.
jdm
Apr 5, 2017
Member
This method will need to return Ok(observer) once observer is a Root<MutationObserver> value.
|
|
| #[dom_struct] | ||
| pub struct MutationObserver { | ||
| reflector_: Reflector, | ||
| callback: MutationCallback, |
This comment has been minimized.
This comment has been minimized.
jdm
Apr 5, 2017
Member
This should be Rc<MutationCallback>. To avoid the errors about heapsize::HeapSizeOf, you can add this annotation above this field: #[ignore_heap_size_of = "can't measure Rc values"]
This comment has been minimized.
This comment has been minimized.
srivassumit
Apr 5, 2017
Author
Contributor
Thanks Josh,
I have fixed the test-tidy issues, for some reason those were not visible when I ran the command locally.
I have also made the other changes as per the comments. Now the mutation observer part is not giving any errors, but there is an error in the script thread file at line 583:
"error: the type of this value must be known in this context" I cannot figure out why is it an error, the method is exactly the same as the mark_document_with_no_blocked_loads method.
…nObserver-dev merged upstream
|
Only a couple small changes left! Thanks for doing this! |
| @@ -18,6 +18,7 @@ | |||
| //! loop. | |||
|
|
|||
| use bluetooth_traits::BluetoothRequest; | |||
| use core::borrow::BorrowMut; | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
srivassumit
Apr 5, 2017
Author
Contributor
It was giving me an error when I used the borrow_mut() in the add_mutation_observer, now that I have change it to DOMRefCell, I guess this won't be needed anymore. I'll remove it.
| @@ -575,10 +576,11 @@ impl ScriptThreadFactory for ScriptThread { | |||
|
|
|||
| impl ScriptThread { | |||
| pub fn add_mutation_observer(observer: &MutationObserver) { | |||
| SCRIPT_THREAD_ROOT.with(|root| { | |||
| SCRIPT_THREAD_ROOT.with(|root| { | |||
This comment has been minimized.
This comment has been minimized.
| @@ -37,7 +37,7 @@ impl MutationRecord { | |||
| impl MutationRecordMethods for MutationRecord { | |||
| // https://dom.spec.whatwg.org/#dom-mutationrecord-type | |||
| fn Type(&self) -> DOMString { | |||
| return self.record_type; | |||
| DOMString::from(self.record_type.clone()) | |||
This comment has been minimized.
This comment has been minimized.
| reflect_dom_object(boxed_observer, global, MutationObserverBinding::Wrap) | ||
| } | ||
|
|
||
| pub fn new_inherited(callback: Rc<MutationCallback>) -> MutationObserver { |
This comment has been minimized.
This comment has been minimized.
jdm
Apr 5, 2017
Member
Let's not make these methods public. Only the constructor should be used here.
| @@ -480,6 +482,9 @@ pub struct ScriptThread { | |||
|
|
|||
| microtask_queue: MicrotaskQueue, | |||
|
|
|||
| /// The unit of related similar-origin browsing contexts' list of MutationObserver objects | |||
| mutation_observers: Vec<JS<MutationObserver>>, | |||
This comment has been minimized.
This comment has been minimized.
jdm
Apr 5, 2017
Member
This needs to be DOMRefCell<Vec<JS<MutationObserver>>> (which provides the borrow_mut() method that you're calling).
|
I took the liberty of squashing your commits into one and removing the many merge commits that this PR included. I've pushed the squashed branch to #16268. |
Basic MutationObserver interface stubs Rebase and squash of #16190. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16268) <!-- Reviewable:end -->
Basic MutationObserver interface stubs Rebase and squash of #16190. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16268) <!-- Reviewable:end -->
…m:tmp); r=jdm Rebase and squash of servo/servo#16190. Source-Repo: https://github.com/servo/servo Source-Revision: 8e2a1477ae800b86eae45fc9c6daf85615100854 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : febfe9bf5d1c77941bdc9a4e820a0e08741b2d57
…m:tmp); r=jdm Rebase and squash of servo/servo#16190. Source-Repo: https://github.com/servo/servo Source-Revision: 8e2a1477ae800b86eae45fc9c6daf85615100854
…m:tmp); r=jdm Rebase and squash of servo/servo#16190. Source-Repo: https://github.com/servo/servo Source-Revision: 8e2a1477ae800b86eae45fc9c6daf85615100854
…m:tmp); r=jdm Rebase and squash of servo/servo#16190. Source-Repo: https://github.com/servo/servo Source-Revision: 8e2a1477ae800b86eae45fc9c6daf85615100854 UltraBlame original commit: 2dbda4bb18ff68e7932dbe50949102cb16d9d36e
…m:tmp); r=jdm Rebase and squash of servo/servo#16190. Source-Repo: https://github.com/servo/servo Source-Revision: 8e2a1477ae800b86eae45fc9c6daf85615100854 UltraBlame original commit: 2dbda4bb18ff68e7932dbe50949102cb16d9d36e
…m:tmp); r=jdm Rebase and squash of servo/servo#16190. Source-Repo: https://github.com/servo/servo Source-Revision: 8e2a1477ae800b86eae45fc9c6daf85615100854 UltraBlame original commit: 2dbda4bb18ff68e7932dbe50949102cb16d9d36e
srivassumit commentedMar 30, 2017
•
edited
Changes for implementing the Initial Steps of the Mutation Observer API as described here
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is