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 all commits
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

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

'nativeType': 'MutationObserver',
'path': 'dom::mutationobserver::MutationObserver',
},

'MutationRecord': {
'nativeType': 'MutationRecord',
'path': 'dom::mutationrecord::MutationRecord',
},

'Promise': {
'spiderMonkeyInterface': True,
},
@@ -378,6 +378,8 @@ pub mod messageevent;
pub mod mimetype;
pub mod mimetypearray;
pub mod mouseevent;
pub mod mutationobserver;
pub mod mutationrecord;
pub mod namednodemap;
pub mod navigator;
pub mod navigatorinfo;
@@ -0,0 +1,41 @@
/* 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/. */

use dom::bindings::codegen::Bindings::MutationObserverBinding;
use dom::bindings::codegen::Bindings::MutationObserverBinding::MutationCallback;
use dom::bindings::error::Fallible;
use dom::bindings::js::Root;
use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::window::Window;
use dom_struct::dom_struct;
use script_thread::ScriptThread;
use std::ops::Deref;
use std::rc::Rc;

#[dom_struct]
pub struct MutationObserver {
reflector_: Reflector,
#[ignore_heap_size_of = "can't measure Rc values"]
callback: Rc<MutationCallback>,
}

impl MutationObserver {
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)
}

fn new_inherited(callback: Rc<MutationCallback>) -> MutationObserver {
MutationObserver {
reflector_: Reflector::new(),
callback: callback,
}
}

pub fn Constructor(global: &Window, callback: Rc<MutationCallback>) -> Fallible<Root<MutationObserver>> {
let observer = MutationObserver::new(global, callback);
ScriptThread::add_mutation_observer(observer.deref());
return Ok(observer);
}
}
@@ -0,0 +1,38 @@
/* 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/. */

use dom::bindings::codegen::Bindings::MutationRecordBinding::MutationRecordBinding::MutationRecordMethods;
use dom::bindings::js::{JS, Root};
use dom::bindings::reflector::Reflector;
use dom::bindings::str::DOMString;
use dom::node::Node;
use dom_struct::dom_struct;

#[dom_struct]
pub struct MutationRecord {
reflector_: Reflector,

//property for record type
record_type: DOMString,

//property for target node
target: JS<Node>,
}

impl MutationRecord {

}

impl MutationRecordMethods for MutationRecord {
// https://dom.spec.whatwg.org/#dom-mutationrecord-type
fn Type(&self) -> DOMString {
self.record_type.clone()
}

// https://dom.spec.whatwg.org/#dom-mutationrecord-target
fn Target(&self) -> Root<Node> {
return Root::from_ref(&*self.target);
}

}
@@ -0,0 +1,27 @@
/* 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
*/

// https://dom.spec.whatwg.org/#mutationobserver
[Pref="dom.mutation_observer.enabled", Constructor(MutationCallback callback)]
interface MutationObserver {
//void observe(Node target, optional MutationObserverInit options);
//void disconnect();
//sequence<MutationRecord> takeRecords();
};

callback MutationCallback = void (sequence<MutationRecord> mutations, MutationObserver observer);

dictionary MutationObserverInit {
boolean childList = false;
boolean attributes;
boolean characterData;
boolean subtree = false;
boolean attributeOldValue;
boolean characterDataOldValue;
sequence<DOMString> attributeFilter;
};
@@ -0,0 +1,24 @@
/* 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
*/

// https://dom.spec.whatwg.org/#mutationrecord
[Pref="dom.mutation_observer.enabled", Exposed=Window]
interface MutationRecord {
readonly attribute DOMString type;
[SameObject]
readonly attribute Node target;
//[SameObject]
//readonly attribute NodeList addedNodes;
//[SameObject]
//readonly attribute NodeList removedNodes;
//readonly attribute Node? previousSibling;
//readonly attribute Node? nextSibling;
//readonly attribute DOMString? attributeName;
//readonly attribute DOMString? attributeNamespace;
//readonly attribute DOMString? oldValue;
};
@@ -46,6 +46,7 @@ use dom::event::{Event, EventBubbles, EventCancelable};
use dom::globalscope::GlobalScope;
use dom::htmlanchorelement::HTMLAnchorElement;
use dom::htmliframeelement::HTMLIFrameElement;
use dom::mutationobserver::MutationObserver;
use dom::node::{Node, NodeDamage, window_from_node};
use dom::serviceworker::TrustedServiceWorkerAddress;
use dom::serviceworkerregistration::ServiceWorkerRegistration;
@@ -480,6 +481,9 @@ pub struct ScriptThread {

microtask_queue: MicrotaskQueue,

/// The unit of related similar-origin browsing contexts' list of MutationObserver objects
mutation_observers: DOMRefCell<Vec<JS<MutationObserver>>>,

/// A handle to the webvr thread, if available
webvr_thread: Option<IpcSender<WebVRMsg>>,

@@ -570,6 +574,15 @@ impl ScriptThreadFactory for ScriptThread {
}

impl ScriptThread {
pub fn add_mutation_observer(observer: &MutationObserver) {
SCRIPT_THREAD_ROOT.with(|root| {
let script_thread = unsafe { &*root.get().unwrap() };
script_thread.mutation_observers
.borrow_mut()
.push(JS::from_ref(observer));
})
}

pub fn mark_document_with_no_blocked_loads(doc: &Document) {
SCRIPT_THREAD_ROOT.with(|root| {
let script_thread = unsafe { &*root.get().unwrap() };
@@ -722,6 +735,8 @@ impl ScriptThread {

microtask_queue: MicrotaskQueue::default(),

mutation_observers: Default::default(),

layout_to_constellation_chan: state.layout_to_constellation_chan,

webvr_thread: state.webvr_thread,
@@ -4,6 +4,7 @@
"dom.forcetouch.enabled": false,
"dom.mouseevent.which.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,
@@ -1,5 +1,5 @@
[contenttype_datauri_01.html]
type: testharness
[Data URI document.contentType === 'text/plain' when data URI MIME type is not set]
expected: FAIL
expected: TIMEOUT

@@ -1,5 +1,5 @@
[contenttype_datauri_02.html]
type: testharness
[Data URI document.contentType === 'text/html' when data URI MIME type is set]
expected: FAIL
expected: TIMEOUT

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


ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.