Closed Bug 1765727 Opened 2 years ago Closed 2 years ago

Add comment explaining error.isWebDriverError() uses a name check and not `instanceof`

Categories

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

enhancement

Tracking

(firefox102 fixed)

RESOLVED FIXED
102 Branch
Tracking Status
firefox102 --- fixed

People

(Reporter: whimboo, Assigned: whimboo)

Details

Attachments

(1 file)

Currently isWebDriverError uses just the name of the error to determine if it's a WebDriver error:

https://searchfox.org/mozilla-central/rev/2fd70a667e6f89a9ec6622ecb302b1ab48e4a062/remote/shared/webdriver/Errors.jsm#109-111

 isWebDriverError(obj) {
    return error.isError(obj) && "name" in obj && ERRORS.has(obj.name);
  },

Instead we should use an instanceof check to determine if the prototype chain of a given object contains the WebDriverError prototype.

Note that instanceof could cause a problem if we are ever comparing objects that were created in different globals because they won't have the same prototype object.

As discussed, instanceof is usually dangerous (cross global / cross process etc...), let's just add a comment in the code.

Priority: -- → P3
Summary: error.isWebDriverError() should use `instanceof` to check for the prototype chain → Add comment explaining error.isWebDriverError() uses a name check and not `instanceof`
Assignee: nobody → hskupin
Status: NEW → ASSIGNED
Pushed by hskupin@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/fd9ec7652acf
[remote] Add explanation comment to error.isWebDriverError() to explain why not using instanceof. r=webdriver-reviewers,jgraham DONTBUILD
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 102 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: