add clojure function to easily toggle dynamic scope creation on/off
This commit is contained in:
parent
e0ecb7e62b
commit
19aab9c19d
|
@ -2,7 +2,7 @@
|
||||||
(:refer-clojure :exclude (eval get get-in set!))
|
(:refer-clojure :exclude (eval get get-in set!))
|
||||||
(:import [org.mozilla.javascript Context UniqueTag NativeArray NativeObject
|
(:import [org.mozilla.javascript Context UniqueTag NativeArray NativeObject
|
||||||
BaseFunction]
|
BaseFunction]
|
||||||
[org.marianoguerra.rhino TimedContextFactory]))
|
[org.marianoguerra.rhino TimedContextFactory DynamicScopeContextFactory]))
|
||||||
|
|
||||||
(defprotocol RhinoConvertible
|
(defprotocol RhinoConvertible
|
||||||
(-to-rhino [object scope ctx] "convert a value to a rhino compatible type"))
|
(-to-rhino [object scope ctx] "convert a value to a rhino compatible type"))
|
||||||
|
@ -11,6 +11,11 @@
|
||||||
(-from-rhino [object]
|
(-from-rhino [object]
|
||||||
"convert a value from rhino to a more clojure friendly representation"))
|
"convert a value from rhino to a more clojure friendly representation"))
|
||||||
|
|
||||||
|
(defn toggle-dynamic-scope! [enable]
|
||||||
|
"enables/disables creation of either 'normal' scopes or dynamic scopes. this
|
||||||
|
will only affect scopes that are created after calling this function."
|
||||||
|
(DynamicScopeContextFactory/toggleDynamicScopeCreation enable))
|
||||||
|
|
||||||
(defn with-context [fun]
|
(defn with-context [fun]
|
||||||
"create a context call fun with it and safelly exit the context"
|
"create a context call fun with it and safelly exit the context"
|
||||||
(let [ctx (Context/enter)]
|
(let [ctx (Context/enter)]
|
||||||
|
|
Reference in a new issue