Skip to content

Commit

Permalink
chg: update fixes superseded in PM 32.2
Browse files Browse the repository at this point in the history
  • Loading branch information
martok committed May 18, 2023
1 parent cce6dc6 commit c282679
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/builtin-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ d35aaqx5ub95lt.cloudfront.net/js/app-*.js$script
! --
github.com
gist.github.com
std-PerformanceObserver,std-queueMicrotask,gh-compat,gh-main-csp,sm-gh-extra,sm-cookie
std-PerformanceObserver,std-queueMicrotask,gh-compat,gh-turbo,gh-main-csp,sm-gh-extra,sm-cookie
github.com/socket-worker.js$script
gist.github.com/socket-worker.js$script
github.com/assets-cdn/worker/socket-worker-*.js$script
Expand Down
47 changes: 47 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ function evaluateFix(fix, script, csp, contentReplace) {
contentReplace.push([`this.matchFields?.join("-")`, `((y)=>y?y.join("-"):y)(this.matchFields)`]);
contentReplace.push([`H.integrity=S.sriHashes[t],`, ``]);
break;
case "gh-turbo":
script.push(pf.Github_disableTurbo);
break;
case "gh-main-csp":
csp["connect-src"] = ["objects.githubusercontent.com", "codeload.github.com"];
break;
Expand Down Expand Up @@ -210,6 +213,14 @@ function supersededFixes(service) {
superseded.add("google-regexp");
superseded.add("notion-regexp");
}
if (service.isWebComponentsSupported) {
superseded.add("gh-compat");
superseded.add("pkg-WebComponents");
superseded.add("std-ShadowDOM");
}
if (service.isLogicalAssignSupported) {
superseded.add("wordpress-logicalassign");
}
return superseded;
}

Expand Down Expand Up @@ -615,6 +626,21 @@ class MergedFix {
}
}

const gWindowOpenListener = {
onOpenWindow: function(xulWindow)
{
const window = xulWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindow);
const onWindowLoad = () => {
window.removeEventListener("load", onWindowLoad);
if (window.document.documentElement.getAttribute("windowtype") == "navigator:browser") {
gService._checkWindowFeatures(window);
}
}
window.addEventListener("load", onWindowLoad);
}
}


class PolyfillService {
constructor() {
Expand All @@ -624,6 +650,17 @@ class PolyfillService {
this.isNullishCoalescingSupported = this._checkSyntax("foo??bar");
this.isNamedCapturingGroupSupported = this._checkSyntax("/(?<Name>x)/");
this.isPropertyEscapeSupported = this._checkSyntax("/\\p{L}/u");
this.isLogicalAssignSupported = this._checkSyntax("let a=3;a||=false;a??=true");
// Features that need a Window global to be checked
this.isWebComponentsSupported = false;
const win = Services.wm.getMostRecentWindow("navigator:browser");
if (win) {
this._checkWindowFeatures(win);
} else {
// Addons get loaded before the first Window is created. Instead, delay the check
// until the first navigator window is opened.
Services.wm.addListener(gWindowOpenListener);
}
this.fixCache = new Map();
this.rules = new RuleEngine();
this.exclusion = new RuleEngine();
Expand All @@ -633,6 +670,7 @@ class PolyfillService {

destroy() {
settings.onPrefChanged.remove(this._prefChanged, this);
Services.wm.removeListener(gWindowOpenListener);
}

_loadRules() {
Expand Down Expand Up @@ -682,6 +720,15 @@ class PolyfillService {
return true;
}

_checkWindowFeatures(window) {
this.isWebComponentsSupported = typeof window.ShadowRoot !== "undefined" &&
typeof window.Element.prototype.attachShadow !== "undefined" &&
typeof window.Node.prototype.getRootNode !== "undefined" &&
typeof window.customElements !== "undefined" &&
typeof window.customElements.define !== "undefined";
Services.wm.removeListener(gWindowOpenListener);
}

isSiteEnabled(URI) {
return this.rules.isSiteEnabled(URI.host);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/polyfills.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c282679

Please sign in to comment.