Skip to content

Commit 797e247

Browse files
mfikesswannodette
authored andcommitted
CLJS-2002: Don't throw when no *print-fn* is set
1 parent ee391d7 commit 797e247

2 files changed

Lines changed: 7 additions & 9 deletions

File tree

src/main/cljs/cljs/core.cljs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,13 @@
6565
^{:doc "Each runtime environment provides a different way to print output.
6666
Whatever function *print-fn* is bound to will be passed any
6767
Strings which should be printed." :dynamic true}
68-
*print-fn*
69-
(fn [_]
70-
(throw (js/Error. "No *print-fn* fn set for evaluation environment"))))
68+
*print-fn* nil)
7169

7270
(defonce
7371
^{:doc "Each runtime environment provides a different way to print error output.
7472
Whatever function *print-err-fn* is bound to will be passed any
7573
Strings which should be printed." :dynamic true}
76-
*print-err-fn*
77-
(fn [_]
78-
(throw (js/Error. "No *print-err-fn* fn set for evaluation environment"))))
74+
*print-err-fn* nil)
7975

8076
(defn set-print-fn!
8177
"Set *print-fn* to f."
@@ -9584,6 +9580,8 @@ reduces them without incurring seq initialization"
95849580
(-write writer s)))
95859581

95869582
(defn string-print [x]
9583+
(when (nil? *print-fn*)
9584+
(throw (js/Error. "No *print-fn* fn set for evaluation environment")))
95879585
(*print-fn* x)
95889586
nil)
95899587

src/main/cljs/cljs/pprint.cljs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ The following keyword arguments can be passed with values:
806806
(binding [*out* base-writer]
807807
(pr object)))
808808
(if (true? optval)
809-
(*print-fn* (str sb)))
809+
(string-print (str sb)))
810810
(if (nil? optval)
811811
(str sb)))))))
812812

@@ -815,7 +815,7 @@ The following keyword arguments can be passed with values:
815815
(let [sb (StringBuffer.)]
816816
(binding [*out* (StringBufferWriter. sb)]
817817
(pprint object *out*)
818-
(*print-fn* (str sb)))))
818+
(string-print (str sb)))))
819819
([object writer]
820820
(with-pretty-writer writer
821821
(binding [*print-pretty* true]
@@ -2736,7 +2736,7 @@ column number or pretty printing"
27362736
(-flush wrapped-stream))))
27372737
(cond
27382738
(not stream) (str sb)
2739-
(true? stream) (*print-fn* (str sb))
2739+
(true? stream) (string-print (str sb))
27402740
:else nil))))
27412741
([format args]
27422742
(map-passing-context

0 commit comments

Comments
 (0)