Deprecate class static properties that are reserved in JavaScript
Open, NormalPublic

Description

See also: T89721: Static methods can't know which class they belong to or which class they're called with

In order to migrate from our .static container to native properties on the function object. The most common one is name, like in OO.ui.Dialog.static.name.

Here is a complete list of reserved static property names (most of which we are not using, so that's good).

Unsafe:

  • Function (used to interact with class and constructor)
    • fn.constructor
    • fn.prototype
    • fn.length
    • fn.name (instance property, ES6)
    • fn.arguments (useless, obsolete, but not assignable by default)
    • fn.caller (useless, non-standard, but not assignable by default)
    • fn.toString

Safe (can be overridden as own properties, where needed methods can and should be called on foreign objects from the prototype)

  • Object
    • toLocaleString
    • valueOf
    • hasOwnProperty
    • isPrototypeOf
    • propertyIsEnumerable
  • Function
    • fn.apply
    • fn.call
    • fn.bind
    • fn.arity (obsolete, undefined by default, safe to assign)
    • fn.displayName (non-standard Firefox/Chrome, undefined by default, safe to assign)
    • fn.toSource (non-standard Firefox, inherited, though safe to assign)
    • fn.isGenerator (non-standard Firefox, inherited, though safe to assign)
Krinkle created this task.Apr 21 2015, 1:54 AM
Krinkle updated the task description. (Show Details)
Krinkle raised the priority of this task from to Normal.
Krinkle claimed this task.
Krinkle added projects: Patch-For-Review, OOjs.
Krinkle removed Krinkle as the assignee of this task.
Krinkle edited projects, added OOjs-UI, VisualEditor; removed Patch-For-Review.
Krinkle set Security to None.
Krinkle added subscribers: cscott, gerritbot, Krinkle and 3 others.
Krinkle removed a subscriber: gerritbot.

I've searched for all the above mentioned property names with prefix static., using GitHub Code Search on wikimedia/*.

The only match that affects JavaScript (either through JavaScript files or PHP code generating JavaScript) is static.name.

  • OO.Factory.
  • OO.ui.ToolFactory (OO.ui.Tool and OO.ui.ToolGroup subclasses).
  • OO.ui.WindowManager (OO.ui.Dialog subclasses).
  • ve.ce.NodeFactory (ve.ce.Node subclasses).
  • ve.dm.ModelRegistry (ve.dm.Model subclasses).
  • ve.ui.ActionFactory (ve.ui.Action subclasses).
  • ve.ui.ToolFactory (ve.ui.Tool subclasses).
  • ve.ui.DataTransferHandlerFactory (ve.ui.DataTransferHandler subclasses).
  • ve.ui.Command

Most of these should be changed to centrally share retrieval of the name. This'll make it easy to add support for a new property name in a future, because we'll be deprecating name.

While most are related to factories, some are not. We should consider having their new names not be the same.

TODO:

  • Some of these classes are missing a default null declaration and @abstract documentation for their static.name property. Thus making it not obvious that subclasses need to implement it.
  • Our factory/registry classes should document what class they expect to be given.
  • Our entity subclasses should document what registry they're generally used with.
Krinkle moved this task from Inbox to Accepted: Enhancement on the OOjs board.Feb 12 2016, 5:25 PM
Krinkle updated the task description. (Show Details)Mar 8 2017, 7:36 PM