use of org.apache.sling.scripting.sightly.js.impl.cjs.CommonJsModule in project sling by apache.
the class JsEnvironment method runResource.
public void runResource(Resource scriptResource, Bindings globalBindings, Bindings arguments, UnaryCallback callback) {
ScriptContext scriptContext = new SimpleScriptContext();
CommonJsModule module = new CommonJsModule();
Bindings scriptBindings = buildBindings(scriptResource, globalBindings, arguments, module);
scriptContext.setBindings(scriptBindings, ScriptContext.ENGINE_SCOPE);
scriptContext.setAttribute(ScriptEngine.FILENAME, scriptResource.getPath(), ScriptContext.ENGINE_SCOPE);
runScript(scriptResource, scriptContext, callback, module);
}
use of org.apache.sling.scripting.sightly.js.impl.cjs.CommonJsModule in project sling by apache.
the class SlyBindingsValuesProvider method createQInstance.
private Object createQInstance(Context context, Script qScript) {
CommonJsModule module = new CommonJsModule();
Scriptable tempScope = context.newObject(qScope);
ScriptableObject.putProperty(tempScope, Variables.MODULE, module);
ScriptableObject.putProperty(tempScope, Variables.EXPORTS, module.getExports());
qScript.exec(context, tempScope);
return module.getExports();
}
Aggregations