WIP Instance methods level control#1027
Open
jeroenvandijk wants to merge 4 commits intobabashka:masterfrom
Open
WIP Instance methods level control#1027jeroenvandijk wants to merge 4 commits intobabashka:masterfrom
jeroenvandijk wants to merge 4 commits intobabashka:masterfrom
Conversation
(some-> x :field) expands to (if (nil? x) nil (:field x)) so adds some unnecessary overhead when fields are never nil
Does not interfere with :allow :all
E.g.
(sci/eval-string "(.toString \"your name\")"
{:classes {'java.lang.String
{:class java.lang.String
:instance-methods {'toString
(fn [_s]
:dude)}}}})
Contributor
Author
|
This approach also works nicely with the new 1.12+ way of referring to an instance method: 'java.io.BufferedReader {:class java.io.BufferedReader
:instance-methods
{:deny true
'close java.io.BufferedReader/.close}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please answer the following questions and leave the below in as part of your PR.
I have read the developer documentation.
This PR corresponds to an issue with a clear problem statement.
This PR contains a test to prevent against future regressions
Sci already offers control over what functions can and can't be called, and each function can get a custom implementation. For interop there is no such feature yet. Right now, you can either call an instance method as per the original implementation or you can't (configured via
:classes). Ideally, there would be a middle ground where you can offer an alternative implementation to an otherwise potentially harmful method, or in some cases deny certain methods entirely.This is a first take at adding method level based control to Sci. It should allow to give access to functionality of configured classes while blocking other undesirable functionality, e.g. think access control of a filesystem.
The implementation in this PR allows to add a custom implementation of a method (as a function) and other methods can be denied.
E.g.
I believe the overhead per method invocation of this feature to traditional paths is limited to:
The option
:allowis checked first and if true, the rest is ignored and interop is applied directly (like before), so no overhead in that case.The option
:denyin:instance-methodscould be extended to static methods, static fields and instance fields.