Closed Bug 1764689 Opened 3 years ago Closed 3 years ago

Unnecessary use of global this in BOOKMARK_VALIDATORS.url

Categories

(Toolkit :: Places, task, P3)

task

Tracking

()

RESOLVED FIXED
101 Branch
Tracking Status
firefox101 --- fixed

People

(Reporter: arai, Assigned: arai)

References

Details

Attachments

(1 file)

https://searchfox.org/mozilla-central/rev/d34f9713ae128a3138c2b70d8041a535f1049d19/toolkit/components/places/PlacesUtils.jsm#237

function simpleValidateFunc(boolValidateFn) {
  return (v, input) => {
    if (!boolValidateFn(v, input)) {
      throw new Error("Invalid value");
    }
    return v;
  };
}
...
const BOOKMARK_VALIDATORS = Object.freeze({
...
  url: v => {
    simpleValidateFunc(
      val =>
        (typeof val == "string" && val.length <= DB_URL_LENGTH_MAX) ||
        (val instanceof Ci.nsIURI && val.spec.length <= DB_URL_LENGTH_MAX) ||
        (URL.isInstance(val) && val.href.length <= DB_URL_LENGTH_MAX)
    ).call(this, v);

The this there is global this, but simpleValidateFunc returns an arrow function that doesn't use the this value on the call, but inherits from the enclosing scope.

Blocks: 1607331
Pushed by arai_a@mac.com: https://hg.mozilla.org/integration/autoland/rev/848dee4a3553 Remove unnnecessary global this reference in BOOKMARK_VALIDATORS.url. r=mak
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 101 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: