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
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
73f2c6e
Initial Files for MutationObserverAPI
srivassumit Mar 16, 2017
bee1340
add a vector of MutationObserver objects as a member of ScriptThread
srivassumit Mar 16, 2017
a5af9a2
Merge branch 'master' of https://github.com/servo/servo into Mutation…
srivassumit Mar 16, 2017
4ec5d92
Merge branch 'master' of https://github.com/servo/servo into Mutation…
srivassumit Mar 17, 2017
16c09d4
incomplete code for mutationobserver and mutationrecord
srivassumit Mar 20, 2017
e162f8a
fixed build errors, Constructor is pending
srivassumit Mar 21, 2017
b0af820
Resolving merge conflicts
krishnakarthick1993 Mar 23, 2017
8e6d4e9
added Mutation Observer Constructor
srivassumit Mar 29, 2017
4797cc3
Merge branch 'MutationObserver-dev' of https://github.com/srivassumit…
srivassumit Mar 29, 2017
dd9ea19
Merge branch 'master' of https://github.com/servo/servo into Mutation…
srivassumit Mar 29, 2017
4db8c26
changes for constructor
srivassumit Mar 30, 2017
1a7e2d4
Merge branch 'master' of https://github.com/servo/servo into Mutation…
srivassumit Mar 30, 2017
ef51869
Update mutationrecord.rs
srivassumit Mar 31, 2017
2d10eb7
Update script_thread.rs
srivassumit Mar 31, 2017
3dd78ed
more changes as per review comments
srivassumit Apr 1, 2017
0160982
fixed test test-tidy issues, accessed ScriptThread from mutationobserver
srivassumit Apr 1, 2017
eefb95b
Merge branch 'master' of https://github.com/servo/servo into Mutation…
srivassumit Apr 1, 2017
2cce8c5
modifications for review comments
srivassumit Apr 5, 2017
7115abd
Merge branch 'master' of https://github.com/servo/servo into Mutation…
srivassumit Apr 5, 2017
2821def
changes as per review comments
srivassumit Apr 5, 2017
a82e79d
Merge branch 'master' of https://github.com/servo/servo into Mutatio…
srivassumit Apr 5, 2017
3bd4438
removed unused imports and fixed review comments.
srivassumit Apr 5, 2017
c6739ef
removed unused import
srivassumit Apr 5, 2017
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

changes as per review comments

  • Loading branch information
srivassumit committed Apr 5, 2017
commit 2821def19177a7aadcb55fd52f97057f94eb24f8
@@ -4,11 +4,12 @@

use core::ptr::null;
use dom;
use dom::bindings::codegen::Bindings::MutationObserverBinding;
use dom::bindings::codegen::Bindings::MutationObserverBinding::MutationCallback;
use dom::bindings::codegen::Bindings::MutationObserverBinding::MutationObserverInit;
use dom::bindings::error::Fallible;
use dom::bindings::js::Root;
use dom::bindings::reflector::Reflector;
use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::trace::JSTraceable;
use dom::mutationrecord::MutationRecord;
use dom::node::Node;
@@ -21,11 +22,17 @@ use std::rc::Rc;
#[dom_struct]
pub struct MutationObserver {
reflector_: Reflector,
callback: MutationCallback,
#[ignore_heap_size_of = "can't measure Rc values"]
callback: Rc<MutationCallback>,
}

impl MutationObserver {
fn new(global: &Window, callback: Rc<MutationCallback>) -> MutationObserver {
pub fn new(global: &Window, callback: Rc<MutationCallback>) -> Root<MutationObserver> {
let boxed_observer = box MutationObserver::new_inherited(callback);
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.

MutationObserver {
reflector_: Reflector::new(),
callback: callback,
@@ -34,7 +41,7 @@ impl MutationObserver {

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(Root::from_ref(&*observer))
ScriptThread::add_mutation_observer(observer.deref());
return Ok(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.


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

}

// https://dom.spec.whatwg.org/#dom-mutationrecord-target
@@ -1,3 +1,6 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* The origin of this IDL file is:
* https://dom.spec.whatwg.org/#mutationobserver
@@ -1,3 +1,6 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* The origin of this IDL file is:
* https://dom.spec.whatwg.org/#mutationrecord
@@ -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.

use devtools;
use devtools_traits::{DevtoolScriptControlMsg, DevtoolsPageInfo};
use devtools_traits::{ScriptToDevtoolsControlMsg, WorkerId};
@@ -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.

let script_thread = unsafe { &*root.get().unwrap() };
script_thread.mutation_observers
.push(JS::from_ref(&*observer));
.borrow_mut()
.push(JS::from_ref(observer));
})
}

@@ -3,8 +3,8 @@
"dom.bluetooth.testing.enabled": false,
"dom.forcetouch.enabled": false,
"dom.mouseevent.which.enabled": false,
"dom.mutation_observer.enabled": false,
"dom.mozbrowser.enabled": false,
"dom.mutation_observer.enabled": false,
"dom.permissions.enabled": false,
"dom.permissions.testing.allowed_in_nonsecure_contexts": false,
"dom.serviceworker.timeout_seconds": 60,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.