ClojureScript

Compiler should warn on any attempted extension of protocols to base JavaScript types

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

...specifically, anything that is otherwise covered by cljs.core/base-type:

  • js/Object
  • js/String
  • js/Number
  • js/Array
  • js/Function
  • js/Boolean

Extending protocols to any of these is impolite (pollution of shared prototypes, esp. after Google Closure compilation), and leads to undefined behaviour, e.g.:

(defprotocol P (m [this]))

(extend-protocol P
  js/Boolean
  (m [this] "hi"))

ClojureScript:cljs.user> (m true)
"hi"
ClojureScript:cljs.user> (m false)
"Error evaluating:" (m false) :as "cljs.user.m.call(null,false)"
org.mozilla.javascript.JavaScriptException: Error: No protocol method P.m defined for type boolean: false

The warning should suggest the symbol that should be used to name the intended type, e.g. number instead of js/Number.

Activity

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: