Closed Bug 1608281 Opened 4 years ago Closed 3 years ago

Stop reading properties on the global `this` in JSMs

Categories

(Firefox :: General, task, P5)

task

Tracking

()

RESOLVED FIXED

People

(Reporter: bgrins, Assigned: bgrins)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

For example: Object.freeze(this.CustomizableUI); in https://searchfox.org/mozilla-central/rev/ba4fab1cc2f1c9c4e07cdb71542b8d441707c577/browser/components/customizableui/CustomizableUI.jsm#4447.

This is related to Bug 1308512 - I expect at least some of the consumers that do this are earlier setting something on this and can hopefully change to use const instead.

Priority: -- → P5

const won't work as you expect:

const foo = { a: 1 };
"use strict";foo.a = 2;
foo.a; // 2
var bar = { a: 1 };  // let also works
Object.freeze(bar);
"use strict";bar.a = 2; // Error

Why can't it just use Object.freeze(CustomizableUI);?

(In reply to Masatoshi Kimura [:emk] from comment #1)

Why can't it just use Object.freeze(CustomizableUI);?

My script for Bug 1608278 does ultimately do that rewrite. But it would be relatively easy to split things out to make just that change here, so I'll block that bug on this change.

Blocks: 1608278
Assignee: nobody → bgrinstead
Status: NEW → ASSIGNED

This code currently returns undefined:

var {FirstStartup} = ChromeUtils.import("resource://gre/modules/FirstStartup.jsm");
FirstStartup.state

But it's meant to return 0 (NOT_STARTED), and this patch fixes that.

Keywords: leave-open
Pushed by bgrinstead@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/ae7ccf443295
Stop unintenionally reading a property off of the global `this` in FirstStartup r=rhelmer

This patch was generated with a script. It doesn't include all files:

  • Files that use the preprocessor or fail to parse are skipped
  • Files that are loaded as JSMs but don't use the .jsm extension are skipped (those will be renamed in Bug 1609269)

It was generated with the following command:

hg revert --all &&
cp .gitignore .rgignore &&
rg --files-without-match -g '*.jsm' '^#endif|^#include|^#filter' | jscodeshift --stdin --transform ~/Code/jsm-rewrites/no-this-property-read.js --ignore-pattern ./mobile/android/modules/Sanitizer.jsm --ignore-pattern ./js/xpconnect/tests/unit/syntax_error.jsm &&
./mach eslint hg st | rg '^M ' | sed 's/^M //'

Attachment #9121412 - Attachment description: Bug 1608281 - Automated rewrite away from reading properties to `this` in JSM files - Round 1 → Bug 1608281 - Automated rewrite away from reading properties on the global `this` in JSM files - round 1
Blocks: 1610653
No longer blocks: 1608278
Pushed by bgrinstead@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/b17b4a20b809
Automated rewrite away from reading properties on the global `this` in JSM files - round 1 r=mossop

Bugbug thinks this bug should belong to this component, but please revert this change in case of error.

Component: General → Toolbars and Customization
Component: Toolbars and Customization → General

The leave-open keyword is there and there is no activity for 6 months.
:bgrins, maybe it's time to close this bug?

Flags: needinfo?(bgrinstead)

Closing this one. There were still some more consumers but they can be fixed separately.

Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Flags: needinfo?(bgrinstead)
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: