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

fix: provide a way to disable document patching #1221

Merged
merged 2 commits into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,22 @@ import {
ArrayFind,
ArraySlice,
defineProperty,
isTrue,
isUndefined,
} from '../../shared/language';
import { getNodeOwnerKey } from '../../faux-shadow/node';
import { createStaticNodeList } from '../../shared/static-node-list';
import { createStaticHTMLCollection } from '../../shared/static-html-collection';

let skipGlobalPatching: boolean;
function isGlobalPatchingSkipped() {
if (isUndefined(skipGlobalPatching)) {
skipGlobalPatching =
document.body.getAttribute('data-global-patching-bypass') === 'temporary-bypass';
}
return isTrue(skipGlobalPatching);
}

export default function apply() {
const HTMLBodyElementPrototype = HTMLBodyElement.prototype;
// The following patched methods hide shadowed elements from global
Expand All @@ -40,7 +50,10 @@ export default function apply() {
]);
const ownerKey = getNodeOwnerKey(this);
// Return the first non shadow element
const filtered = ArrayFind.call(elements, elm => getNodeOwnerKey(elm) === ownerKey);
const filtered = ArrayFind.call(
elements,
elm => getNodeOwnerKey(elm) === ownerKey || isGlobalPatchingSkipped()
);
return !isUndefined(filtered) ? filtered : null;
},
writable: true,
Expand All @@ -54,7 +67,10 @@ export default function apply() {
string
]);
const ownerKey = getNodeOwnerKey(this);
const filtered = ArrayFilter.call(elements, elm => getNodeOwnerKey(elm) === ownerKey);
const filtered = ArrayFilter.call(
elements,
elm => getNodeOwnerKey(elm) === ownerKey || isGlobalPatchingSkipped()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check could go outside the ArrayFilter, but I wanted to leave it in here so that it gives us the performance cost of document patching. In effect, we execute the filtering rule and skip it. The core perf scripts will measure the cost of document patching.

);
return createStaticNodeList(filtered);
},
writable: true,
Expand All @@ -68,7 +84,10 @@ export default function apply() {
arguments
) as [string]);
const ownerKey = getNodeOwnerKey(this);
const filtered = ArrayFilter.call(elements, elm => getNodeOwnerKey(elm) === ownerKey);
const filtered = ArrayFilter.call(
elements,
elm => getNodeOwnerKey(elm) === ownerKey || isGlobalPatchingSkipped()
);
return createStaticHTMLCollection(filtered);
},
writable: true,
Expand All @@ -82,7 +101,10 @@ export default function apply() {
string
]);
const ownerKey = getNodeOwnerKey(this);
const filtered = ArrayFilter.call(elements, elm => getNodeOwnerKey(elm) === ownerKey);
const filtered = ArrayFilter.call(
elements,
elm => getNodeOwnerKey(elm) === ownerKey || isGlobalPatchingSkipped()
);
// NodeList because of https://bugzilla.mozilla.org/show_bug.cgi?id=14869
return createStaticNodeList(filtered);
},
Expand All @@ -97,7 +119,10 @@ export default function apply() {
arguments
) as [string, string]);
const ownerKey = getNodeOwnerKey(this);
const filtered = ArrayFilter.call(elements, elm => getNodeOwnerKey(elm) === ownerKey);
const filtered = ArrayFilter.call(
elements,
elm => getNodeOwnerKey(elm) === ownerKey || isGlobalPatchingSkipped()
);
// NodeList because of https://bugzilla.mozilla.org/show_bug.cgi?id=14869
return createStaticNodeList(filtered);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
ArraySlice,
defineProperty,
isNull,
isTrue,
isUndefined,
getOwnPropertyDescriptor,
} from '../../shared/language';
Expand All @@ -30,6 +31,15 @@ import { pathComposer } from '../../3rdparty/polymer/path-composer';
import { createStaticNodeList } from '../../shared/static-node-list';
import { createStaticHTMLCollection } from '../../shared/static-html-collection';

let skipGlobalPatching: boolean;
function isGlobalPatchingSkipped() {
if (isUndefined(skipGlobalPatching)) {
skipGlobalPatching =
document.body.getAttribute('data-global-patching-bypass') === 'temporary-bypass';
}
return isTrue(skipGlobalPatching);
}

export default function apply() {
function elemFromPoint(this: Document, left: number, top: number) {
const element = elementFromPoint.call(this, left, top);
Expand Down Expand Up @@ -87,7 +97,7 @@ export default function apply() {
return null;
}
const ownerKey = getNodeOwnerKey(this);
return getNodeOwnerKey(elm) === ownerKey ? elm : null;
return getNodeOwnerKey(elm) === ownerKey || isGlobalPatchingSkipped() ? elm : null;
},
writable: true,
enumerable: true,
Expand All @@ -100,7 +110,10 @@ export default function apply() {
string
]);
const ownerKey = getNodeOwnerKey(this);
const filtered = ArrayFind.call(elements, elm => getNodeOwnerKey(elm) === ownerKey);
const filtered = ArrayFind.call(
elements,
elm => getNodeOwnerKey(elm) === ownerKey || isGlobalPatchingSkipped()
);
return !isUndefined(filtered) ? filtered : null;
},
writable: true,
Expand All @@ -114,7 +127,10 @@ export default function apply() {
string
]);
const ownerKey = getNodeOwnerKey(this);
const filtered = ArrayFilter.call(elements, elm => getNodeOwnerKey(elm) === ownerKey);
const filtered = ArrayFilter.call(
elements,
elm => getNodeOwnerKey(elm) === ownerKey || isGlobalPatchingSkipped()
);
return createStaticNodeList(filtered);
},
writable: true,
Expand All @@ -128,7 +144,10 @@ export default function apply() {
arguments
) as [string]);
const ownerKey = getNodeOwnerKey(this);
const filtered = ArrayFilter.call(elements, elm => getNodeOwnerKey(elm) === ownerKey);
const filtered = ArrayFilter.call(
elements,
elm => getNodeOwnerKey(elm) === ownerKey || isGlobalPatchingSkipped()
);
return createStaticHTMLCollection(filtered);
},
writable: true,
Expand All @@ -142,7 +161,9 @@ export default function apply() {
arguments
) as [string]);
const ownerKey = getNodeOwnerKey(this);
const filtered = ArrayFilter.call(elements, elm => getNodeOwnerKey(elm) === ownerKey);
const filtered =
ArrayFilter.call(elements, elm => getNodeOwnerKey(elm) === ownerKey) ||
isGlobalPatchingSkipped();
// NodeList because of https://bugzilla.mozilla.org/show_bug.cgi?id=14869
return createStaticNodeList(filtered);
},
Expand All @@ -157,7 +178,9 @@ export default function apply() {
arguments
) as [string, string]);
const ownerKey = getNodeOwnerKey(this);
const filtered = ArrayFilter.call(elements, elm => getNodeOwnerKey(elm) === ownerKey);
const filtered =
ArrayFilter.call(elements, elm => getNodeOwnerKey(elm) === ownerKey) ||
isGlobalPatchingSkipped();
// NodeList because of https://bugzilla.mozilla.org/show_bug.cgi?id=14869
return createStaticNodeList(filtered);
},
Expand All @@ -180,7 +203,7 @@ export default function apply() {
const ownerKey = getNodeOwnerKey(this);
const filtered = ArrayFilter.call(
elements,
elm => getNodeOwnerKey(elm) === ownerKey
elm => getNodeOwnerKey(elm) === ownerKey || isGlobalPatchingSkipped()
);
return createStaticNodeList(filtered);
},
Expand Down