Closed Bug 1907234 Opened 2 years ago Closed 2 years ago

Improve error message for class members called "prototype" or "constructor"

Categories

(Core :: JavaScript Engine, enhancement, P3)

Firefox 128
enhancement

Tracking

()

RESOLVED FIXED
130 Branch
Tracking Status
firefox130 --- fixed

People

(Reporter: sidachen2003, Assigned: sidachen2003)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

Steps to reproduce:

class X {
  constructor = 1;
}

class Y {
  static prototype = 1;
}

Actual results:

Bad error message: "SyntaxError: bad method definition"

There's no method definition here and I probably don't intend to write one. It's the field itself that's invalid.

Expected results:

Something similar to V8's message:

  • SyntaxError: Classes may not have a field named 'constructor'
  • SyntaxError: Classes may not have a static property named 'prototype'

For more context, I am working on https://github.com/mdn/mdn/issues/505 and the page titles are FF errors, so they need to be descriptive and discoverable.

Blocks: jserror
Status: UNCONFIRMED → NEW
Component: Untriaged → JavaScript Engine
Ever confirmed: true
Product: Firefox → Core

I realized this same error is used for any constructor that's not a plain method, such as #constructor and async constructor. If we don't want to make a bunch of error codes for this like V8 does, we should make the message generic like "A class constructor must be declared as a plain method".

Severity: -- → N/A
Priority: -- → P3
Assignee: nobody → sidachen2003
Status: NEW → ASSIGNED
Pushed by mgaudet@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/264cc00a5cfc split "bad method definition" error into three error messages r=mgaudet
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 130 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: