Skip to content

Commit 7e15b1f

Browse files
author
dnolen
committed
CLJS-1658: testing for protocol membership may return false positives
use a defonc'ed sentinel value instead of checking for true Thomas Heller provided the original patch on which this is based
1 parent d87ac45 commit 7e15b1f

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
(def *unchecked-if* false)
2121

22+
(defonce PROTOCOL_SENTINEL #js {})
23+
2224
(goog-define
2325
^{:dynamic true
2426
:doc "Var bound to the name value of the compiler build :target option.

src/main/clojure/cljs/core.cljc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,7 @@
14541454
(add-obj-methods type type-sym sigs)
14551455
(concat
14561456
(core/when-not (skip-flag psym)
1457-
[`(set! ~(extend-prefix type-sym pprefix) true)])
1457+
[`(set! ~(extend-prefix type-sym pprefix) cljs.core/PROTOCOL_SENTINEL)])
14581458
(mapcat
14591459
(core/fn [sig]
14601460
(if (= psym 'cljs.core/IFn)
@@ -2014,13 +2014,13 @@
20142014
`(let [~xsym ~x]
20152015
(if ~xsym
20162016
(if (or ~(if bit `(unsafe-bit-and (. ~xsym ~msym) ~bit) false)
2017-
~(bool-expr `(. ~xsym ~(symbol (core/str "-" prefix)))))
2017+
(identical? cljs.core/PROTOCOL_SENTINEL (. ~xsym ~(symbol (core/str "-" prefix)))))
20182018
true
20192019
false)
20202020
false))
20212021
`(if-not (nil? ~x)
20222022
(if (or ~(if bit `(unsafe-bit-and (. ~x ~msym) ~bit) false)
2023-
~(bool-expr `(. ~x ~(symbol (core/str "-" prefix)))))
2023+
(identical? cljs.core/PROTOCOL_SENTINEL (. ~x ~(symbol (core/str "-" prefix)))))
20242024
true
20252025
false)
20262026
false))))
@@ -2040,15 +2040,15 @@
20402040
`(let [~xsym ~x]
20412041
(if-not (nil? ~xsym)
20422042
(if (or ~(if bit `(unsafe-bit-and (. ~xsym ~msym) ~bit) false)
2043-
~(bool-expr `(. ~xsym ~(symbol (core/str "-" prefix)))))
2043+
(identical? cljs.core/PROTOCOL_SENTINEL (. ~xsym ~(symbol (core/str "-" prefix)))))
20442044
true
20452045
(if (coercive-not (. ~xsym ~msym))
20462046
(cljs.core/native-satisfies? ~psym ~xsym)
20472047
false))
20482048
(cljs.core/native-satisfies? ~psym ~xsym)))
20492049
`(if-not (nil? ~x)
20502050
(if (or ~(if bit `(unsafe-bit-and (. ~x ~msym) ~bit) false)
2051-
~(bool-expr `(. ~x ~(symbol (core/str "-" prefix)))))
2051+
(identical? cljs.core/PROTOCOL_SENTINEL (. ~x ~(symbol (core/str "-" prefix)))))
20522052
true
20532053
(if (coercive-not (. ~x ~msym))
20542054
(cljs.core/native-satisfies? ~psym ~x)

0 commit comments

Comments
 (0)