Skip to content

Commit

Permalink
chore: notify when we need to add replacement to private method
Browse files Browse the repository at this point in the history
  • Loading branch information
onemen committed Oct 27, 2024
1 parent 5bc65a8 commit 508e06e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 13 deletions.
29 changes: 25 additions & 4 deletions addon/chrome/content/changecode.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Tabmix.changeCode = function(aParent, afnName, aOptions) {
} else {
this.errMsg = "\n" + this.fullName + " is undefined.";
}

this.verifyPrivateMethodReplaced();

this.notFound.length = 0;
}

Expand All @@ -35,6 +38,9 @@ Tabmix.changeCode = function(aParent, afnName, aOptions) {
notFound: [],
value: "",
errMsg: "",
errMsgContent:
"\n\nTry Tabmix latest development version from https://bitbucket.org/onemen/tabmixplus-for-firefox/downloads/," +
"\nReport about this to Tabmix developer at https://github.com/onemen/TabMixPlus/issues",
_replace: function TMP_utils__replace(substr, newString, aParams) {
// Don't insert new code before "use strict";
if (substr == "{") {
Expand Down Expand Up @@ -164,9 +170,7 @@ Tabmix.changeCode = function(aParent, afnName, aOptions) {
if (notFoundCount && !this.silent) {
let str = (notFoundCount > 1 ? "s" : "") + "\n ";
ex.message = ex.fnName + " was unable to change " + aName + "." +
(this.errMsg || "\ncan't find string" + str + this.notFound.join("\n ")) +
"\n\nTry Tabmix latest development version from https://bitbucket.org/onemen/tabmixplus-for-firefox/downloads/," +
"\nReport about this to Tabmix developer at https://github.com/onemen/TabMixPlus/issues";
(this.errMsg || "\ncan't find string" + str + this.notFound.join("\n ")) + this.errMsgContent;
console.reportError(ex);
if (debugMode) {
console.clog(ex.fnName + "\nfunction " + aName + " = " + this.value, ex);
Expand All @@ -181,7 +185,24 @@ Tabmix.changeCode = function(aParent, afnName, aOptions) {
let caller = (stack.caller || {}).caller || {};
let {filename, lineNumber, columnNumber, name} = caller;
return {filename, lineNumber, columnNumber, fnName: name, message: ""};
}
},

verifyPrivateMethodReplaced() {
const matches = this.value.match(/this\.#(\w+)/g);
if (!matches) {
return;
}
const privateMethods = new Set(matches.map(match => match.replace("this.#", "")));
const parentName = afnName.split(".").slice(0, -1).join(".");
const ex = this.getCallerData(Components.stack.caller);
for (const methods of privateMethods) {
if (typeof aParent[`_${methods}`] === "undefined") {
ex.message = `Implement replacement for private method #${methods} in ${parentName} it is used by ${this.fullName}${this.errMsgContent}`;
console.reportError(ex);
}
}
this.value = this.value.replace(/this\.#(\w+)/g, "this._$1");
},
};

try {
Expand Down
9 changes: 3 additions & 6 deletions addon/chrome/content/minit/minit.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ var TMP_tabDNDObserver = {
configurable: true,
enumerable: true,
});

// this function is just a place holder we don't use it in vertical mode
gBrowser.tabContainer._animateExpandedPinnedTabMove = function() {};
}

if (Tabmix.isVersion(1330)) {
Expand Down Expand Up @@ -180,8 +183,6 @@ var TMP_tabDNDObserver = {
)._replace(
/let lastTabCenter = (.*)tabSize \/ 2;/,
'let lastTabCenter = $1(this.verticalMode ? tabSize / 2 : rightTabWidth / 2);'
)._replace(
/this\.#(\w*)/g, "this._$1", {check: Tabmix.isVersion(1310)}
).toCode();
} else {
// helper function to get floorp strings for width in vertical mode
Expand Down Expand Up @@ -243,8 +244,6 @@ var TMP_tabDNDObserver = {
? "translateY(" + Math.round(newMargin) + "px)"
: "translate(" + Math.round(newMargin) + "px," + Math.round(newMarginY) + "px)";`,
{check: Tabmix.isVersion(1300)}
)._replace(
/this\.#(\w*)/g, "this._$1", {check: Tabmix.isVersion(1310)}
);

const dropCode = Tabmix.changeCode(tabBar, "gBrowser.tabContainer.on_drop")._replace(
Expand Down Expand Up @@ -302,8 +301,6 @@ var TMP_tabDNDObserver = {
} else {
targetTab = null;
}`
)._replace(
/this\.#(\w*)/g, "this._$1", {check: Tabmix.isVersion(1320)}
);

/**
Expand Down
4 changes: 2 additions & 2 deletions addon/chrome/content/tab/scrollbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ Tabmix.multiRow = {

const codeToReplace = Tabmix.isVersion(1310) ? 'this.#verticalMode' : 'this.getAttribute("orient") == "vertical"';
Tabmix.changeCode(this, "scrollbox.on_touchstart")._replace(
codeToReplace, 'this._verticalMode'
codeToReplace, 'this._verticalMode', {silent: true}
).toCode();

Tabmix.changeCode(this, "scrollbox.on_touchmove")._replace(
codeToReplace, 'this._verticalMode'
codeToReplace, 'this._verticalMode', {silent: true}
).toCode();

this._scrollButtonUpLeft.addEventListener("contextmenu", this._createScrollButtonContextMenu, true);
Expand Down
2 changes: 1 addition & 1 deletion addon/modules/log.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ const console = {
if (typeof ex.filename == "undefined" && ex.fileName) {
ex.filename = ex.fileName;
}
if (!ex.filename || !ex.linenumber) {
if (!ex.filename || !ex.lineNumber) {
caller = this.caller;
ex.stack = caller.stack;
}
Expand Down
2 changes: 2 additions & 0 deletions types/extraTabmixUtils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ declare namespace ChangeCodeNS {
type: "__lookupSetter__" | "__lookupGetter__";
value: string;
errMsg: string;
errMsgContent: string;
notFound: (string | RegExp)[];

prototype: ChangeCodeClass;
Expand All @@ -48,6 +49,7 @@ declare namespace ChangeCodeNS {
show(aObj?: Record<string, unknown>, aName?: string): void;
isValidToChange(this: ChangeCodeClass, aName: string): boolean;
getCallerData(stack: nsIStackFrame, aOptions?: unknown): {filename: string; lineNumber: number; columnNumber: number; fnName: string; message: string};
verifyPrivateMethodReplaced(): void;
}
}

Expand Down
1 change: 1 addition & 0 deletions types/general.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ declare namespace MockedGeckoTypes {

interface TabContainer extends Element {
_animateElement: ArrowScrollbox;
_animateExpandedPinnedTabMove: (event: MouseEvent) => void;
_animateTabMove: (event: MouseEvent) => void;
_backgroundTabScrollPromise?: Promise<void>;
_blockDblClick?: boolean;
Expand Down

0 comments on commit 508e06e

Please sign in to comment.