Bug 1274274 - Disassociate isDisconnected from element store; r=automatedtester

MozReview-Commit-ID: 4uxbLKlgfsL

--HG--
extra : rebase_source : 7e2c236c470b8637aba78461b2c058a005b20ad7
This commit is contained in:
Andreas Tolfsen 2016-05-20 15:11:37 +01:00
Родитель 0f872f6301
Коммит c002fdc182
1 изменённых файлов: 39 добавлений и 39 удалений

Просмотреть файл

@ -180,7 +180,7 @@ element.Store = class {
let wrappedEl = new XPCNativeWrapper(el);
if (!el ||
!(wrappedEl.ownerDocument == wrappedFrame.document) ||
this.isDisconnected(wrappedEl, wrappedFrame, wrappedShadowRoot)) {
element.isDisconnected(wrappedEl, wrappedFrame, wrappedShadowRoot)) {
throw new StaleElementReferenceError(
"The element reference is stale. Either the element " +
"is no longer attached to the DOM or the page has been refreshed.");
@ -189,44 +189,6 @@ element.Store = class {
return el;
}
/**
* Check if the element is detached from the current frame as well as
* the optional shadow root (when inside a Shadow DOM context).
*
* @param {nsIDOMElement} el
* Element to be checked.
* @param nsIDOMWindow frame
* Window object that contains the element or the current host
* of the shadow root.
* @param {ShadowRoot=} shadowRoot
* An optional shadow root containing an element.
*
* @return {boolean}
* Flag indicating that the element is disconnected.
*/
isDisconnected(el, frame, shadowRoot = undefined) {
// shadow dom
if (shadowRoot && frame.ShadowRoot) {
if (el.compareDocumentPosition(shadowRoot) &
DOCUMENT_POSITION_DISCONNECTED) {
return true;
}
// looking for next possible ShadowRoot ancestor
let parent = shadowRoot.host;
while (parent && !(parent instanceof frame.ShadowRoot)) {
parent = parent.parentNode;
}
return this.isDisconnected(shadowRoot.host, parent, frame);
// outside shadow dom
} else {
let docEl = frame.document.documentElement;
return el.compareDocumentPosition(docEl) &
DOCUMENT_POSITION_DISCONNECTED;
}
}
/**
* Convert values to primitives that can be transported over the
* Marionette protocol.
@ -743,6 +705,44 @@ element.generateUUID = function() {
return uuid.substring(1, uuid.length - 1);
};
/**
* Check if the element is detached from the current frame as well as
* the optional shadow root (when inside a Shadow DOM context).
*
* @param {nsIDOMElement} el
* Element to be checked.
* @param nsIDOMWindow frame
* Window object that contains the element or the current host
* of the shadow root.
* @param {ShadowRoot=} shadowRoot
* An optional shadow root containing an element.
*
* @return {boolean}
* Flag indicating that the element is disconnected.
*/
element.isDisconnected = function(el, frame, shadowRoot = undefined) {
// shadow dom
if (shadowRoot && frame.ShadowRoot) {
if (el.compareDocumentPosition(shadowRoot) &
DOCUMENT_POSITION_DISCONNECTED) {
return true;
}
// looking for next possible ShadowRoot ancestor
let parent = shadowRoot.host;
while (parent && !(parent instanceof frame.ShadowRoot)) {
parent = parent.parentNode;
}
return element.isDisconnected(shadowRoot.host, frame, parent);
// outside shadow dom
} else {
let docEl = frame.document.documentElement;
return el.compareDocumentPosition(docEl) &
DOCUMENT_POSITION_DISCONNECTED;
}
};
/**
* This function generates a pair of coordinates relative to the viewport
* given a target element and coordinates relative to that element's