Closed Bug 1764688 Opened 3 years ago Closed 3 years ago

Misuse of arrow function + this in MessageHandlerFrameActor.jsm

Categories

(Remote Protocol :: WebDriver BiDi, defect, P3)

defect

Tracking

(firefox101 fixed)

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/remote/shared/messagehandler/transports/js-window-actors/MessageHandlerFrameActor.jsm#44

const MessageHandlerFrameActor = {
  registered: false,

  register: () => {
    if (this.registered) {
      return;
    }

...
    this.registered = true;

arrow function inherits this from the enclosing scope, and the this there is not the this value for the function call (so, MessageHandlerFrameActor for MessageHandlerFrameActor.register()), but the global this value.

The code work as expected because there's only one MessageHandlerFrameActor, and the global registered variable is falsy (undefined) at the beginning, and no other code touches it.

the code should use method definition instead.

Assignee: nobody → arai.unmht
Status: NEW → ASSIGNED
Blocks: 1607331

Good point, thanks for filing :arai (and for taking the bug :) )

Pushed by arai_a@mac.com: https://hg.mozilla.org/integration/autoland/rev/52c74d875e24 Fix this variable in MessageHandlerFrameActor.register. r=jdescottes,webdriver-reviewers
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: