This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-15
Channels
- # announcements (1)
- # aws (79)
- # babashka (47)
- # beginners (82)
- # calva (65)
- # cider (27)
- # cljdoc (18)
- # cljs-dev (29)
- # clojure (189)
- # clojure-dev (5)
- # clojure-europe (3)
- # clojure-italy (1)
- # clojure-madison (6)
- # clojure-nl (4)
- # clojure-spec (10)
- # clojure-uk (41)
- # clojured (3)
- # clojurescript (5)
- # clojurex (17)
- # cursive (30)
- # data-science (7)
- # datomic (17)
- # emacs (3)
- # events (6)
- # fulcro (2)
- # funcool (9)
- # graalvm (29)
- # jobs-discuss (3)
- # joker (3)
- # kaocha (6)
- # malli (5)
- # music (6)
- # off-topic (21)
- # reagent (3)
- # reitit (4)
- # rewrite-clj (8)
- # shadow-cljs (49)
- # spacemacs (7)
- # sql (23)
- # tools-deps (15)
- # vim (43)
- # xtdb (19)
Well it does reflection, so it might be somewhat slower? I don’t expect this to be a problem for scripting though
Is it runtime reflection or compile time reflection? (I'd assume the latter, if it works with graal)
Does it matter in binary size?
Interesting!
@borkdude Regarding https://github.com/borkdude/babashka/pull/108 (`.write`), maybe it is better to just close the PR and do it via the new approach once ready? I can use my locally built bb
in the meantime...
if I will give users access to for example all method of String
will they be able to indirectly call (System/exit 1)
even when I haven't given them explicitly a reference to the System
class?
you could also use https://github.com/Raynes/clojail ?
@holyjak sci is kind of a replacement for clojail already. clojail doesn't work on JS
it uses eval which doesn't work on native, which is more or less the entire point of sci
Do you think a method filter is needed?
Right now I give users access to classes with {:classes {'String String 'java.lang.String String}}
. This will let them do everything with strings
But there might be classes where you want to say which methods are only allowed or which methods are not allowed?
something like this:
{:classes {'java.lang.String {:class String
:deny-methods '[getClass]}}
:imports {'String 'java.lang.String}}
Possibly. But do you need to decide it now? Cant you wait to add black/whitelist when you actually need it?
Good point. U guess you cant use metadata here?
it's bit weird really:
user=> (meta (edn/read-string "^:foo dude"))
{:foo true}
user=> (meta ^:foo 'dude)
nil
Could you follow the example of require? Accept either a symbol or vector of symbol + options?
I'll go with the extra level of indirection for now, the convenience option can always be added later
This reflection stuff is starting to pay off:
$ ./sci '(def x "foo") (-> x (.replace \o \i) (.replace "f" "h"))'
"hii"
Note that I'm using two different overloads of .replace
here./sci '((juxt #(.indexOf % "o") #(.indexOf % "o" 2) #(.indexOf % (int \o))) "foo")'
[1 2 1]
I finished the unit tests in the sci / interop branch. Next: add import
and then merge to babashka, add some classes and hopefully profit
no, i think things are fine -- afaiu, there is testing with 1.9.0, 1.10.1, cljs w/ node optimizations none and advanced, as well as native -- each time some tests are added, the effect is a bit amplified, right?
ah, i haven't been paying close enough attention -- i could go back to an earlier commit to compare, but i'm guessing it's not that important
import now works in sci / interop:
$ ./sci "(import clojure.lang.ExceptionInfo) (type ExceptionInfo)"
java.lang.Class
tests passed and:
$ ./sci "(import java.lang.ArithmeticException) (type ArithmeticException)"
java.lang.Class
New version of babashka with refactored Java class support using reflection config: https://1743-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.28-SNAPSHOT-linux-amd64.zip https://1741-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.28-SNAPSHOT-macos-amd64.zip Commit: https://github.com/borkdude/babashka/commit/a0fa854969a4024b126c43b6fd2339b626a543f9 Classes supported:
ArithmeticException
AssertionError
Boolean
Class
Double
Exception
clojure.lang.ExceptionInfo
java.io.File
Integer
java.io.File
java.util.regex.Pattern
String
System
Thread
Please check if nothing broke 🙂Issue automagically fixed: https://github.com/borkdude/babashka/issues/104#issuecomment-554569170