use of org.mozilla.javascript.ScriptableObject in project sling by apache.
the class SlingContext method initStandardObjects.
@Override
public ScriptableObject initStandardObjects(ScriptableObject scope, boolean sealed) {
ScriptableObject rootScope = super.initStandardObjects(scope, sealed);
// prepare the ImporterToplevel host object because it will be
// used as top level scope for the RhinoJavaScriptEngine but is
// not initialized with the rest of the standard objects
ImporterTopLevel.init(this, rootScope, sealed);
// add Sling global objects
SlingGlobal.init(rootScope, sealed);
return rootScope;
}
use of org.mozilla.javascript.ScriptableObject in project sling by apache.
the class ScriptEngineHelper method eval.
public Object eval(String javascriptCode, Map<String, Object> data, final StringWriter sw) throws ScriptException {
final PrintWriter pw = new PrintWriter(sw, true);
ScriptContext ctx = new SimpleScriptContext();
final Bindings b = new SimpleBindings();
b.put("out", pw);
if (data != null) {
for (Map.Entry<String, Object> e : data.entrySet()) {
b.put(e.getKey(), e.getValue());
}
}
ctx.setBindings(b, ScriptContext.ENGINE_SCOPE);
ctx.setWriter(sw);
ctx.setErrorWriter(new OutputStreamWriter(System.err));
Object result = getEngine().eval(javascriptCode, ctx);
if (result instanceof Wrapper) {
result = ((Wrapper) result).unwrap();
}
if (result instanceof ScriptableObject) {
Context.enter();
try {
result = ((ScriptableObject) result).getDefaultValue(null);
} finally {
Context.exit();
}
}
return result;
}
use of org.mozilla.javascript.ScriptableObject in project sling by apache.
the class AsyncExtractor method extract.
public void extract(Object jsObj, UnaryCallback unaryCallback) {
if (!isPromise(jsObj)) {
unaryCallback.invoke(jsObj);
}
if (jsObj instanceof AsyncContainer) {
((AsyncContainer) jsObj).addListener(unaryCallback);
}
if (jsObj instanceof ScriptableObject) {
ScriptableObject scriptableObject = (ScriptableObject) jsObj;
decodeJSPromise(scriptableObject, unaryCallback);
}
}
use of org.mozilla.javascript.ScriptableObject in project sling by apache.
the class SlyBindingsValuesProvider method createQScope.
private ScriptableObject createQScope() {
Context context = Context.enter();
try {
ScriptableObject scope = context.initStandardObjects();
ScriptableObject.putProperty(scope, Variables.SET_IMMEDIATE, TimingFunction.INSTANCE);
ScriptableObject.putProperty(scope, Variables.SET_TIMEOUT, TimingFunction.INSTANCE);
return scope;
} finally {
Context.exit();
}
}
Aggregations