private Scriptable setupScope(Context cx, ScriptContext context) { ScriptableObject scriptable = new ImporterTopLevel(cx); Scriptable scope = cx.initStandardObjects(scriptable); //ScriptableObject.putProperty(scope, "argv", Context.javaToJS(args, scope)); return scope; } }
public GalenJsExecutor() { this.context = Context.enter(); this.scope = new ImporterTopLevel(context); this.loadFunction = new JsFunctionLoad(); scope.defineProperty("load", loadFunction, ScriptableObject.DONTENUM); importAllMajorClasses(); }
private @NonNull ScriptableObject initJsScope(@NonNull Context jsContext) { // Set the main Rhino goodies ImporterTopLevel importerTopLevel = new ImporterTopLevel(jsContext); ScriptableObject scope = jsContext.initStandardObjects(importerTopLevel, false); ScriptableObject.putProperty(scope, "context", Context.javaToJS(mContext, scope)); try { importClasses(jsContext, scope); importPackages(jsContext, scope); importConsole(scope); importVariables(scope); importFunctions(scope); } catch (StethoJsException e) { String message = String.format("%s\n%s", e.getMessage(), Log.getStackTraceString(e)); LogUtil.e(e, message); CLog.writeToConsole(Console.MessageLevel.ERROR, Console.MessageSource.JAVASCRIPT, message); } return scope; }
RhinoContextFactory factory = new RhinoContextFactory(timeLimit); Context cx = factory.enterContext(); ScriptableObject scriptable = new ImporterTopLevel(cx); Scriptable scope = cx.initStandardObjects(scriptable);
public static void init(Context cx, Scriptable scope, boolean sealed) { ImporterTopLevel obj = new ImporterTopLevel(); obj.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed); }
public static void init(Context cx, Scriptable scope, boolean sealed) { ImporterTopLevel obj = new ImporterTopLevel(); obj.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed); }
public static void init(Context cx, Scriptable scope, boolean sealed) { ImporterTopLevel obj = new ImporterTopLevel(); obj.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed); }
public static void init(Context cx, Scriptable scope, boolean sealed) { ImporterTopLevel obj = new ImporterTopLevel(); obj.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed); }
public static void init(Context cx, Scriptable scope, boolean sealed) { ImporterTopLevel obj = new ImporterTopLevel(); obj.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed); }
public static void init(Context cx, Scriptable scope, boolean sealed) { ImporterTopLevel obj = new ImporterTopLevel(); obj.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed); }
public static ScriptableObject getGlobal(Context cx) { final String GLOBAL_CLASS = "org.mozilla.javascript.tools.shell.Global"; Class<?> globalClass = Kit.classOrNull(GLOBAL_CLASS); if (globalClass != null) { try { Class<?>[] parm = { ScriptRuntime.ContextClass }; Constructor<?> globalClassCtor = globalClass.getConstructor(parm); Object[] arg = { cx }; return (ScriptableObject) globalClassCtor.newInstance(arg); } catch (Exception e) { // fall through... } } return new ImporterTopLevel(cx); }
public static ScriptableObject getGlobal(Context cx) { final String GLOBAL_CLASS = "org.mozilla.javascript.tools.shell.Global"; Class globalClass = Kit.classOrNull(GLOBAL_CLASS); if (globalClass != null) { try { Class[] parm = { ScriptRuntime.ContextClass }; Constructor globalClassCtor = globalClass.getConstructor(parm); Object[] arg = { cx }; return (ScriptableObject) globalClassCtor.newInstance(arg); } catch (Exception e) { // fall through... } } return new ImporterTopLevel(cx); }
public JsScriptEngine() { Context context = getContext(); scope = new ImporterTopLevel(context); // so that we can use importPackage() context.evaluateString(scope, printSource, "print", 1, null); // so that we can print on std out }
public GalenJsExecutor() { this.context = Context.enter(); this.scope = new ImporterTopLevel(context); this.loadFunction = new JsFunctionLoad(); scope.defineProperty("load", loadFunction, ScriptableObject.DONTENUM); importAllMajorClasses(); }
public JavascriptRun() { Context cx = Context.enter(); scope = new ImporterTopLevel(cx); try { cx.evaluateString(scope, COLLATE_JS, "collate.js", 1, null); cx.evaluateString(scope, VIEWIDXR_JS, "viewidxr.js", 1, null); } finally { Context.exit(); } execFunc = (Function) scope.get("execute", scope); }
private Reducer(String reduceTxt, Context cx) { Scriptable scope = new ImporterTopLevel(cx); cx.evaluateString(scope, REDUCE_JS, "reduce.js", 1, null); Scriptable builtins = (Scriptable) scope.get("BUILTIN_REDUCERS", scope); if (builtins.has(reduceTxt, builtins)) { reduceFunc = (Function)builtins.get(reduceTxt, builtins); } else { reduceFunc = cx.compileFunction(scope, reduceTxt, "reduce", 1, null); } }
private Reducer(String reduceTxt, Context cx) { Scriptable scope = new ImporterTopLevel(cx); cx.evaluateString(scope, REDUCE_JS, "reduce.js", 1, null); Scriptable builtins = (Scriptable) scope.get("BUILTIN_REDUCERS", scope); if (builtins.has(reduceTxt, builtins)) { reduceFunc = (Function)builtins.get(reduceTxt, builtins); } else { reduceFunc = cx.compileFunction(scope, reduceTxt, "reduce", 1, null); } }
public JavascriptRun() { Context cx = Context.enter(); scope = new ImporterTopLevel(cx); try { cx.evaluateString(scope, COLLATE_JS, "collate.js", 1, null); cx.evaluateString(scope, VIEWIDXR_JS, "viewidxr.js", 1, null); } finally { Context.exit(); } execFunc = (Function) scope.get("execute", scope); }
private Indexer(String mapTxt, Context cx) { scope = new ImporterTopLevel(cx); cx.evaluateString(scope, INDEX_JS, "index.js", 1, null); // Index source cx.evaluateString(scope, JavascriptRun.getCollateJS(), "collate.js", 1, null); // Collation mapFunction = cx.compileFunction(scope, mapTxt, "map", 1, null); // var index = new Index() indexResults = cx.newObject(scope, "Index"); indexFunction = (Function) indexResults.getPrototype().get("indexDoc", indexResults); // var emit = index.emit Function emitFunc = (Function) indexResults.getPrototype().get("emit", indexResults); emitFunc = new BoundFunction(cx, scope, emitFunc, indexResults, NO_ARGS); scope.put("emit", scope, emitFunc); }
private Indexer(String mapTxt, Context cx) { scope = new ImporterTopLevel(cx); cx.evaluateString(scope, INDEX_JS, "index.js", 1, null); // Index source cx.evaluateString(scope, JavascriptRun.getCollateJS(), "collate.js", 1, null); // Collation mapFunction = cx.compileFunction(scope, mapTxt, "map", 1, null); // var index = new Index() indexResults = cx.newObject(scope, "Index"); indexFunction = (Function) indexResults.getPrototype().get("indexDoc", indexResults); // var emit = index.emit Function emitFunc = (Function) indexResults.getPrototype().get("emit", indexResults); emitFunc = new BoundFunction(cx, scope, emitFunc, indexResults, NO_ARGS); scope.put("emit", scope, emitFunc); }