2.53.18 beta 1 breaking changes in JavaScript

Discussion about Seamonkey builds
Post Reply
n0spam
Posts: 36
Joined: November 7th, 2020, 7:56 am

2.53.18 beta 1 breaking changes in JavaScript

Post by n0spam »

SeaMonkey 2.53.18 beta 1 removed syntax for functions without curly brackets around the body. You know you've got it when you see in console an error message "Missing { after function body". No "fix this" button for this - you'll have to manually fix it. The fix is trivial though:
1) Add curly brackets around the function body.
2) If the body doesn't start with "return" or "throw" followed by a space then insert "return("after the opening curly bracket and ")" before the closing curly bracket or before the semicolon (;) if there's any.

Examples for reference (lines that start with // are comments):

Code: Select all

// BROKEN
var $ = function(id) document.getElementById(id);
// FIXED
var $ = function(id) { return document.getElementById(id); }

// BROKEN
urls.some(function(url) okURL(url) && script.matchesURL(url));
// FIXED
urls.some(function(url){return okURL(url) && script.matchesURL(url);});

// BROKEN
onToggleStatus: function() Scriptish.enabled = !Scriptish.enabled,
// FIXED
onToggleStatus: function() {return (Scriptish.enabled = !Scriptish.enabled)},

// BROKEN. OK, looks like I lied, and it's only trivial if you're familiar with JavaScript syntax. Sorry for that.
get bis() Cc["@mozilla.org/binaryinputstream;1"]
  .createInstance(Ci.nsIBinaryInputStream),
// FIXED
get bis() {return Cc["@mozilla.org/binaryinputstream;1"]
  .createInstance(Ci.nsIBinaryInputStream)},
Broken functions can span across multiple lines:

Code: Select all

// BROKEN
function shouldNotRun() (
  winClosed || !Scriptish.enabled || !Scriptish_isGreasemonkeyable(href));
// FIXED. Also removed now unnecessary parentheses around the expression, but you can keep the entire body intact if in doubt.
function shouldNotRun() {
  return winClosed || !Scriptish.enabled || !Scriptish_isGreasemonkeyable(href);
}
User avatar
DanRaisch
Moderator
Posts: 126847
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Re: 2.53.18 beta 1 breaking changes in JavaScript

Post by DanRaisch »

Moving to SeaMonkey Builds where pre-release versions are discussed.
TPR75
Posts: 1317
Joined: July 25th, 2011, 8:11 am
Location: Poland

Re: 2.53.18 beta 1 breaking changes in JavaScript

Post by TPR75 »

n0spam wrote:
November 15th, 2023, 12:01 am
SeaMonkey 2.53.18 beta 1 removed syntax for functions without curly brackets around the body.
[...]
The fix is trivial though:
[...]
OK, looks like I lied, and it's only trivial if you're familiar with JavaScript syntax. Sorry for that.
Thank you for this information.
I'm using Adblock Plus 2.9.1 with some modifications to make it work under 2.53.17. I prefer ADP because I'm not using external lists of filters and I really on my own choices which is much easier to perform than using uBO.

Unfortunately, 2.53.18 requires more changes - I can't see lists of filters anymore (empty/blank window for "Filter Preferences"). I'm looking for such solution since 2.53.18 pre-beta version. I tried to put curly brackets but without "return" it didn't worked at all.

Before your hint I had two major breaking errors:

1) Error Console message for "filters-filteractions.js"

Code: Select all

Timestamp: 11/15/2023, 8:34:49 PM
Error: SyntaxError: missing { before function body
Source File: chrome://adblockplus/content/ui/filters-filteractions.js
Line: 64, Column: 20
Source Code:
  get treeElement() E("filtersTree"),
Original code:

Code: Select all

/**
   * <tree> element containing the filters.
   * @type XULElement
   */
  get treeElement() E("filtersTree"),
Changed code:

Code: Select all

  /**
   * <tree> element containing the filters.
   * @type XULElement
   */
  get treeElement()
  {
  return E("filtersTree")
  },
This one works and will not cause more errors.

2) Error Console message for "filters-filterview.js"

Code: Select all

Timestamp: 11/15/2023, 8:52:00 PM
Error: SyntaxError: missing { before function body
Source File: chrome://adblockplus/content/ui/filters-filterview.js
Line: 239, Column: 20
Source Code:
  get treeElement() this.boxObject ? this.boxObject.treeBody.parentNode : null, 
Original code:

Code: Select all

  /**
   * <tree> element that the view is attached to.
   * @type XULElement
   */
  get treeElement() this.boxObject ? this.boxObject.treeBody.parentNode : null,
Changed code:

Code: Select all

  /**
   * <tree> element that the view is attached to.
   * @type XULElement
   */
  get treeElement()
  {
    return this.boxObject ? this.boxObject.treeBody.parentNode : null
  },
It helped because there is no more error for this part of script in Error Console.

Unfortunately, it's not over for "filters-filterview.js". New entry:

Code: Select all

Timestamp: 11/15/2023, 8:59:58 PM
Error: SyntaxError: missing { before function body
Source File: chrome://adblockplus/content/ui/filters-filterview.js
Line: 308, Column: 21
Source Code:
  get subscription() this._subscription, 
Original code:

Code: Select all

  /**
   * Filter subscription being displayed.
   * @type Subscription
   */
  get subscription() this._subscription,
  set subscription(value)
  {
    if (value == this._subscription)
      return;

    // Make sure the editor is done before we update the list.
    if (this.treeElement)
      this.treeElement.stopEditing(true);

    this._subscription = value;
    this.refresh(true);
  },
As you can see it's a little more complicated and I suspect we need more {} and "return"s...

Can you help with this one?
n0spam
Posts: 36
Joined: November 7th, 2020, 7:56 am

Re: 2.53.18 beta 1 breaking changes in JavaScript

Post by n0spam »

TPR75 wrote:
November 15th, 2023, 1:43 pm
Unfortunately, it's not over for "filters-filterview.js". New entry:

Code: Select all

Timestamp: 11/15/2023, 8:59:58 PM
Error: SyntaxError: missing { before function body
Source File: chrome://adblockplus/content/ui/filters-filterview.js
Line: 308, Column: 21
Source Code:
  get subscription() this._subscription, 
Original code:

Code: Select all

  /**
   * Filter subscription being displayed.
   * @type Subscription
   */
  get subscription() this._subscription,
  set subscription(value)
  {
...
  },
As you can see it's a little more complicated and I suspect we need more {} and "return"s...

Can you help with this one?
The broken line is:

Code: Select all

get subscription() this._subscription,
It should be like this:

Code: Select all

get subscription() { return this._subscription; },
Before I forget again, I don't recommend fixing 1 or 2 errors based on the error console messages, then reinstalling the extention and restarting the browser because that might takes ages to finish, depending on how badly the code is infested with this (in my case, Scriptish was pretty bad). If you have a JavaScript syntax analyzer, use it on all the JavaScript files (usually it's *.js and *.jsm) so you can fix them all at once. If you don't, a plain text editor works too - just search for "function", "get", and "set" matching the case and the entire word.
TPR75
Posts: 1317
Joined: July 25th, 2011, 8:11 am
Location: Poland

Re: 2.53.18 beta 1 breaking changes in JavaScript

Post by TPR75 »

n0spam wrote:
November 16th, 2023, 10:41 am

The broken line is:

Code: Select all

get subscription() this._subscription,
It should be like this:

Code: Select all

get subscription() { return this._subscription; },
Who are you that your help is so good?! =D>

I tried it before but I've made bad move and placed "}" after "," so it was not working, obviously my mistake. Now fixed.

There was only one more thing from Error Console and after fix in line 686:

Code: Select all

  get rowCount() { return this.data.length },
... ADB now works like before.

Thank you very much! :D


Error Console shows more entries related to ABP but looks like they don't break anything (at least, anything I can see) and are present under 2.53.17 too.
There are 4 entries but all the same:

Code: Select all

Timestamp: 11/16/2023, 8:48:16 PM
Error: Utils.dateFormatter is undefined
Source File: resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///C:/Users/[USER_NAME]/AppData/Roaming/Mozilla/SeaMonkey/Profiles/jyrjmje4.SM253b1/extensions/%7Bd10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d%7D.xpi!/bootstrap.js -> jar:file:///C:/Users/[USER_NAME]/AppData/Roaming/Mozilla/SeaMonkey/Profiles/jyrjmje4.SM253b1/extensions/%7Bd10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d%7D.xpi!/lib/utils.js
Line: 256
Original code:

Code: Select all

  /**
   * Formats a unix time according to user's locale.
   * @param {Integer} time  unix time in milliseconds
   * @return {String} formatted date and time
   */
  formatTime: function(time)
  {
    try
    {
      let date = new Date(time);
  /** below is line no. 256 [TPR75's comment]
      return Utils.dateFormatter.FormatDateTime("", Ci.nsIScriptableDateFormat.dateFormatShort,
                                                Ci.nsIScriptableDateFormat.timeFormatNoSeconds,
                                                date.getFullYear(), date.getMonth() + 1, date.getDate(),
                                                date.getHours(), date.getMinutes(), date.getSeconds());
    }
    catch(e)
    {
      // Make sure to return even on errors
      Cu.reportError(e);
      return "";
    }
  },
It's not something breaking extension's functionality but I'm just curious what it can be.
User avatar
therube
Posts: 21601
Joined: March 10th, 2004, 9:59 pm
Location: Maryland USA

Re: 2.53.18 beta 1 breaking changes in JavaScript

Post by therube »

(Even nicer is that a user can make such a change & actually fix things - without being mired down in the ideological concepts of a "secure" webextension (cough).)
Fire 750, bring back 250.
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.19) Gecko/20110420 SeaMonkey/2.0.14 Pinball CopyURL+ FetchTextURL FlashGot NoScript
n0spam
Posts: 36
Joined: November 7th, 2020, 7:56 am

Re: 2.53.18 beta 1 breaking changes in JavaScript

Post by n0spam »

FlashGot is broken as well, and ironically it uses dump() for error reporting in that particular spot, which means 99.999% of users won't see the error message because dump() is disabled by default (and last time I checked, it wasn't doing shit even when enabled).
All files are inside /chrome/flashgot.jar/content/flashgot/.

File Autocomplete.jsm:

Code: Select all

// Line 179
// BROKEN
  createInstance: function() this, 
// FIXED
  createInstance: function() { return this; }, 

// Line 159
// BROKEN
            function(s) s.toLowerCase().indexOf(searchString) !== -1
// FIXED
            function(s) { return s.toLowerCase().indexOf(searchString) !== -1; }
File LinkChooser.jsm

Code: Select all

// Line 209-210
// BROKEN
  getLevel: function(row) 0,
  getImageSrc: function(row, col) col.id === "links-type" && this.rows[row]._icon || "",
// FIXED
  getLevel: function(row) { return 0; },
  getImageSrc: function(row, col) { return col.id === "links-type" && this.rows[row]._icon || ""; },

// Line 206-207
// BROKEN
  isContainer: function(row) false,
  isSeparator: function(row) false,
// FIXED
  isContainer: function(row) { return false; },
  isSeparator: function(row) { return false; },

// Line 204
// BROKEN
  isEditable: function(row, column) column.id === "links-choosen",
// FIXED
  isEditable: function(row, column) { return column.id === "links-choosen"; },

// Line 192
// BROKEN
  getCellValue: function(row, column) column.id === "links-choosen" && this.rows[row]._choosen,
// FIXED
  getCellValue: function(row, column) { return column.id === "links-choosen" && this.rows[row]._choosen; },

// Line 178
// BROKEN
  get rowCount() this.rows.length,
// FIXED
  get rowCount() { return this.rows.length; },

// Line 127
// BROKEN
    rows.sort(function(a, b) a._sortKey > b._sortKey ? 1 * order : a._sortKey < b._sortKey ? -1 * order : 0);
// FIXED
    rows.sort(function(a, b) { return a._sortKey > b._sortKey ? 1 * order : a._sortKey < b._sortKey ? -1 * order : 0; });
User avatar
therube
Posts: 21601
Joined: March 10th, 2004, 9:59 pm
Location: Maryland USA

Re: 2.53.18 beta 1 breaking changes in JavaScript

Post by therube »

(I'd not run into any issues with FlashGot [using an earlier "fixed" version, at least that I've been aware of].

Link to other, relatively recent "fixed" FlashGot threads:
looks like FlashGot is broken on SM2.53.17
FlashGot is broken in SeaMonkey 2.53.17 beta 1 pre)
Fire 750, bring back 250.
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.19) Gecko/20110420 SeaMonkey/2.0.14 Pinball CopyURL+ FetchTextURL FlashGot NoScript
Post Reply