Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mutation observer API #16190

Closed
wants to merge 23 commits into from
Closed

Conversation

@srivassumit
Copy link
Contributor

srivassumit commented Mar 30, 2017

Changes for implementing the Initial Steps of the Mutation Observer API as described here


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #6633 (initial steps).
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive
Copy link

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
Copy link

highfive commented Mar 30, 2017

Heads up! This PR modifies the following files:

  • @fitzgen: components/script/dom/mod.rs, components/script/dom/webidls/MutationObserver.webidl, components/script/dom/bindings/codegen/Bindings.conf, components/script/dom/mutationobserver.rs, components/script/script_thread.rs, components/script/dom/mutationrecord.rs, components/script/dom/webidls/MutationRecord.webidl
  • @KiChjang: components/script/dom/mod.rs, components/script/dom/webidls/MutationObserver.webidl, components/script/dom/bindings/codegen/Bindings.conf, components/script/dom/mutationobserver.rs, components/script/script_thread.rs, components/script/dom/mutationrecord.rs, components/script/dom/webidls/MutationRecord.webidl
@highfive
Copy link

highfive commented Mar 30, 2017

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
@@ -18,6 +18,16 @@ DOMInterfaces = {
'weakReferenceable': True,
},

'MutationObserver': {

This comment has been minimized.

Copy link
@emilio

emilio Mar 30, 2017

Member

Is this really needed? I'd expect it to just work without this.


impl MutationObserver {

fn new(global: &dom::bindings::js::Root<dom::window::Window>, callback: MutationCallback) -> MutationObserver {

This comment has been minimized.

Copy link
@emilio

emilio Mar 30, 2017

Member

Please fix indentation in the whole file so it's indented to 4 spaces.

@@ -1,5 +1,5 @@
[contenttype_javascripturi.html]
type: testharness
[Javascript URI document.contentType === 'text/html']
expected: FAIL
expected: TIMEOUT

This comment has been minimized.

Copy link
@emilio

emilio Mar 30, 2017

Member

Are all these tests really timing out with your changes?

This comment has been minimized.

Copy link
@jdm

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.

Copy link
@krishnakarthick1993

krishnakarthick1993 Apr 1, 2017

Those tests timed out without our changes. We ran the tests on a unmodified servo code.

@emilio
Copy link
Member

emilio commented Mar 30, 2017

r? @jdm

@highfive highfive assigned jdm and unassigned emilio Mar 30, 2017
Copy link
Member

jdm left a comment

This is a good start! Please remove the servo submodule that was added in this PR, and if you're having trouble with compile errors then please ask specific questions. I was surprised to see code in mutationobserve.rs that can't compile.

}
}

pub fn Constructor(global: &dom::bindings::js::Root<dom::window::Window>, callback: Rc<MutationCallback>) -> Result<Root<MutationObserver>, Error> {

This comment has been minimized.

Copy link
@jdm

jdm Mar 30, 2017

Member

This should be &Window instead of &Root<Window>.

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.

Copy link
@jdm

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.

Copy link
@jdm

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.

Copy link
@jdm

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.

Copy link
@jdm

jdm Mar 30, 2017

Member

This should be Vec<JS<MutationObserver>> instead.

@@ -1,5 +1,5 @@
[contenttype_javascripturi.html]
type: testharness
[Javascript URI document.contentType === 'text/html']
expected: FAIL
expected: TIMEOUT

This comment has been minimized.

Copy link
@jdm

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.

Copy link
@jdm

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.

Copy link
@jdm

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.

Copy link
@jdm

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.

Copy link
@jdm

jdm Mar 30, 2017

Member

This should be JS<Node> instead.

This comment has been minimized.

Copy link
@srivassumit

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.

Copy link
@KiChjang

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>.

@jdm
Copy link
Member

jdm commented Mar 30, 2017

Also, I'm very confused that ./mach test-tidy does not show any errors for you, given that there are some clear style violations that I would expect it to report. Luckily, our CI picks it up just fine:

Checking files for tidiness...

./components/script/dom/mutationobserver.rs:1: incorrect license

./components/script/dom/mutationobserver.rs:31: Line is longer than 120 characters

./components/script/dom/mutationobserver.rs:32: tab on line

./components/script/dom/mutationobserver.rs:42: tab on line

./components/script/dom/mutationobserver.rs:48: tab on line

./components/script/dom/mutationobserver.rs:54: tab on line

./components/script/dom/mutationobserver.rs:4: use statement is not in alphabetical order

	expected: dom_struct::dom_struct

	found: dom::bindings::codegen::Bindings::MutationObserverBinding::MutationCallback

./components/script/dom/mutationobserver.rs:23: found an empty line following a {

./components/script/dom/mutationobserver.rs:39: found an empty line following a {

./components/script/dom/mutationobserver.rs:41: method declared in webidl is missing a comment with a specification link

./components/script/dom/mutationobserver.rs:47: method declared in webidl is missing a comment with a specification link

./components/script/dom/mutationobserver.rs:52: method declared in webidl is missing a comment with a specification link

./components/script/dom/mutationrecord.rs:1: incorrect license

./components/script/dom/mutationrecord.rs:3: use statement is not in alphabetical order

	expected: dom_struct::dom_struct

	found: dom::bindings::codegen::Bindings::MutationRecordBinding::MutationRecordBinding::MutationRecordMethods

./components/script/dom/mutationrecord.rs:6: use statement is not in alphabetical order

	expected: dom::bindings::str::DOMString

	found: dom::bindings::reflector::Reflector

./components/script/dom/mutationrecord.rs:66: found an empty line following a {

./components/script/dom/mutationrecord.rs:67: method declared in webidl is missing a comment with a specification link

./components/script/dom/mutationrecord.rs:73: method declared in webidl is missing a comment with a specification link

./components/script/dom/mutationrecord.rs:77: method declared in webidl is missing a comment with a specification link

./components/script/dom/mutationrecord.rs:81: method declared in webidl is missing a comment with a specification link

./components/script/dom/mutationrecord.rs:85: method declared in webidl is missing a comment with a specification link

./components/script/dom/mutationrecord.rs:95: method declared in webidl is missing a comment with a specification link

./components/script/dom/mutationrecord.rs:105: method declared in webidl is missing a comment with a specification link

./components/script/dom/mutationrecord.rs:115: method declared in webidl is missing a comment with a specification link

./components/script/dom/mutationrecord.rs:125: method declared in webidl is missing a comment with a specification link

./components/script/dom/webidls/MutationObserver.webidl:0: No specification link found.

./components/script/dom/webidls/MutationObserver.webidl:1: incorrect license

./components/script/dom/webidls/MutationRecord.webidl:0: No specification link found.

./components/script/dom/webidls/MutationRecord.webidl:1: incorrect license

./resources/prefs.json:None: Unordered key (found dom.mutation_observer.enabled before dom.mozbrowser.enabled)
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.

Copy link
@jdm

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.

Copy link
@jdm

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.

Copy link
@jdm

jdm Apr 5, 2017

Member

This method will need to return Ok(observer) once observer is a Root<MutationObserver> value.

@jdm
Copy link
Member

jdm commented Apr 5, 2017

./mach test-tidy reports:

./components/script/dom/webidls/MutationObserver.webidl:1: incorrect license
./components/script/dom/webidls/MutationRecord.webidl:1: incorrect license
./resources/prefs.json:None: Unordered key (found dom.mutation_observer.enabled before dom.mozbrowser.enabled)
#[dom_struct]
pub struct MutationObserver {
reflector_: Reflector,
callback: MutationCallback,

This comment has been minimized.

Copy link
@jdm

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.

Copy link
@srivassumit

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
Copy link
Member

jdm left a comment

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.

Copy link
@jdm

jdm Apr 5, 2017

Member

Doesn't this cause a warning about an unused import?

This comment has been minimized.

Copy link
@srivassumit

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.

Copy link
@jdm

jdm Apr 5, 2017

Member

nit: reindent by one extra space.

@@ -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.

Copy link
@jdm

jdm Apr 5, 2017

Member

This only needs self.record.clone(); the DOMString::from is unnecessary.

reflect_dom_object(boxed_observer, global, MutationObserverBinding::Wrap)
}

pub fn new_inherited(callback: Rc<MutationCallback>) -> MutationObserver {

This comment has been minimized.

Copy link
@jdm

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.

Copy link
@jdm

jdm Apr 5, 2017

Member

This needs to be DOMRefCell<Vec<JS<MutationObserver>>> (which provides the borrow_mut() method that you're calling).

@jdm
Copy link
Member

jdm commented Apr 5, 2017

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.

@jdm jdm closed this Apr 5, 2017
bors-servo added a commit that referenced this pull request Apr 5, 2017
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 -->
bors-servo added a commit that referenced this pull request Apr 5, 2017
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 -->
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Apr 5, 2017
…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
Manishearth pushed a commit to Manishearth/gecko-dev that referenced this pull request Apr 11, 2017
…m:tmp); r=jdm

Rebase and squash of servo/servo#16190.

Source-Repo: https://github.com/servo/servo
Source-Revision: 8e2a1477ae800b86eae45fc9c6daf85615100854
JerryShih pushed a commit to JerryShih/gecko-dev that referenced this pull request Apr 12, 2017
…m:tmp); r=jdm

Rebase and squash of servo/servo#16190.

Source-Repo: https://github.com/servo/servo
Source-Revision: 8e2a1477ae800b86eae45fc9c6daf85615100854
@srivassumit srivassumit deleted the srivassumit:MutationObserver-dev branch Apr 19, 2017
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Oct 1, 2019
…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
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Oct 1, 2019
…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
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Oct 1, 2019
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

6 participants
You can’t perform that action at this time.