Skip to content

Commit

Permalink
MATCH-67: CLJS support regression
Browse files Browse the repository at this point in the history
syntax for try/catch in ClojureScript chagned to match clojure. We can
no longer catch 0 since `0 instanceof Number` is false in
JavaScript. We now catch a preallocated Error just like we do in
Clojure proper. Users must now include `clojure.core.match` namespace as
well as requiring the macros files.

Started adding tests so we can notice ClojureScript regression sooner.
  • Loading branch information
swannodette committed Feb 15, 2013
1 parent 68709c4 commit 3bab92b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions project.clj
Expand Up @@ -11,19 +11,19 @@

:dependencies [[org.clojure/clojure "1.4.0"]
[org.clojure/clojurescript "0.0-1576"]]
:dev-dependencies [[nrepl "0.2.1"]]
:dev-dependencies [[org.clojure/tools.nrepl "0.2.1"]]
:plugins [[lein-cljsbuild "0.3.0"]]

:cljsbuild
{:builds
[{:id "test"
:source-paths ["src/test/cljs"]
:compiler {:output-js "test.js"
:compiler {:output-to "test.js"
:pretty-print true
:static-fns true
:optimizations :simple}}
{:id "test-adv"
:source-paths ["src/test/cljs"]
:compiler {:output-js "test-adv.js"
:compiler {:output-to "test-adv.js"
:pretty-print true
:optimizations :advanced}}]})
6 changes: 3 additions & 3 deletions src/main/clojure/clojure/core/match.clj
Expand Up @@ -79,7 +79,7 @@

(defn backtrack-expr []
(if *clojurescript*
`(throw 0)
`(throw clojure.core.match/backtrack)
`(throw clojure.core.match/backtrack)))

(defn warn [msg]
Expand Down Expand Up @@ -439,8 +439,8 @@

(defn catch-error [& body]
(if *clojurescript*
`(catch e#
(if (identical? e# 0)
`(catch js/Error e#
(if (identical? e# clojure.core.match/backtrack)
(do
~@body)
(throw e#)))
Expand Down
3 changes: 3 additions & 0 deletions src/main/clojure/clojure/core/match.cljs
@@ -0,0 +1,3 @@
(ns clojure.core.match)

(def backtrack (js/Error.))
3 changes: 2 additions & 1 deletion src/test/cljs/clojure/core/match/js/tests.cljs
@@ -1,5 +1,6 @@
(ns clojure.core.match.js.tests
(:use-macros [clojure.core.match.js :only [match]]))
(:use-macros [clojure.core.match.js :only [match]])
(:require [clojure.core.match]))

(defn js-print [& args]
(if (js* "typeof console != 'undefined'")
Expand Down

0 comments on commit 3bab92b

Please sign in to comment.