Refine search
RhinoContextFactory factory = new RhinoContextFactory(timeLimit); Context cx = factory.enterContext(); ScriptableObject scriptable = new ImporterTopLevel(cx); Scriptable scope = cx.initStandardObjects(scriptable); Context.javaToJS(entry.getValue(), scope)); return cx.evaluateString(scope, script, filename, 1, null); } catch (Error e) { throw new ScriptException(e.getMessage());
public GalenJsExecutor() { this.context = Context.enter(); this.scope = new ImporterTopLevel(context); this.loadFunction = new JsFunctionLoad(); scope.defineProperty("load", loadFunction, ScriptableObject.DONTENUM); importAllMajorClasses(); }
/** * initialize the engine. put the manager into the context -> manager * map hashtable too. */ public void initialize(BSFManager mgr, String lang, Vector declaredBeans) throws BSFException { super.initialize(mgr, lang, declaredBeans); // Initialize context and global scope object try { Context cx = Context.enter(); global = cx.initStandardObjects(new ImporterTopLevel(cx)); Scriptable bsf = Context.toObject(new BSFFunctions(mgr, this), global); global.put("bsf", global, bsf); int size = declaredBeans.size(); for (int i = 0; i < size; i++) { declareBean((BSFDeclaredBean) declaredBeans.elementAt(i)); } } finally { Context.exit(); } }
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); }
@SuppressWarnings("unchecked") private Scriptable getRootScope() { if (rootScope == null) { final Context rhinoContext = Context.enter(); try { rhinoContext.setOptimizationLevel(optimizationLevel); rhinoContext.setLanguageVersion(RHINO_LANGUAGE_VERSION); Scriptable tmpScope = rhinoContext.initStandardObjects(new ImporterTopLevel(rhinoContext), false); // default classes addHostObjects(tmpScope, (Class<? extends ScriptableObject>[]) HOSTOBJECT_CLASSES); // provided classes for (RhinoHostObjectProvider provider : hostObjectProvider) { addHostObjects(tmpScope, provider.getHostObjectClasses()); addImportedClasses(rhinoContext, tmpScope, provider.getImportedClasses()); addImportedPackages(rhinoContext, tmpScope, provider.getImportedPackages()); } // only assign the root scope when complete set up rootScope = tmpScope; } finally { // ensure the context is exited after setting up the // the new root scope Context.exit(); } } return rootScope; }
private Object executeScript(String script, Map<String, Object> model, boolean secure) Context cx = Context.enter(); try cx.setWrapFactory(wrapFactory); Scriptable scope; if (!secure) scope = cx.initStandardObjects(); scope = new ImporterTopLevel(cx);
final Context rhinoContext = Context.enter(); rhinoContext.setLanguageVersion(((RhinoJavaScriptEngineFactory)getFactory()).rhinoLanguageVersion()); rhinoContext.setOptimizationLevel(optimizationLevel()); scope = new ImporterTopLevel();
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 void initStandardObjects(Context cx, boolean sealed) { // Assume that Context.initStandardObjects initialize JavaImporter // property lazily so the above init call is not yet called cx.initStandardObjects(this, sealed); topScopeFlag = true; // If seal is true then exportAsJSClass(cx, seal) would seal // this obj. Since this is scope as well, it would not allow // to add variables. IdFunctionObject ctor = exportAsJSClass(MAX_PROTOTYPE_ID, this, false); if (sealed) { ctor.sealObject(); } // delete "constructor" defined by exportAsJSClass so "constructor" // name would refer to Object.constructor // and not to JavaImporter.prototype.constructor. delete("constructor"); }
switch (type) { case IPROXY_COMPILE_SCRIPT: cx.compileString(text, url, 1, null); break; scope = new ImporterTopLevel(cx); cx.evaluateString(scope, text, url, 1, null); booleanResult = cx.stringIsCompilableUnit(text); break;
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 @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; }
private Object js_construct(Scriptable scope, Object[] args) { ImporterTopLevel result = new ImporterTopLevel(); for (int i = 0; i != args.length; ++i) { Object arg = args[i]; if (arg instanceof NativeJavaClass) { result.importClass((NativeJavaClass)arg); } else if (arg instanceof NativeJavaPackage) { result.importPackage((NativeJavaPackage)arg); } else { throw Context.reportRuntimeError1( "msg.not.class.not.pkg", Context.toString(arg)); } } // set explicitly prototype and scope // as otherwise in top scope mode BaseFunction.construct // would keep them set to null. It also allow to use // JavaImporter without new and still get properly // initialized object. result.setParentScope(scope); result.setPrototype(this); return result; }
topLevel = new ImporterTopLevel(cx, false); new LazilyLoadedCtor(topLevel, "JSAdapter", "com.sun.phobos.script.javascript.JSAdapter", cx.exit();
Scriptable scope = new ImporterTopLevel(cx); scope.put("parent", scope, parentContainer); scope.put("assemblyScope", scope, assemblyScope); cx.evaluateReader(scope, getScriptReader(), "picocontainer.js", 1, null); Object pico = scope.get("pico", scope); throw new ScriptedPicoContainerMarkupException("IOException encountered, message -'" + e.getMessage() + "'", e); } finally { Context.exit();
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 Object js_importPackage(Object[] args) { for (int i = 0; i != args.length; i++) { Object arg = args[i]; if (!(arg instanceof NativeJavaPackage)) { throw Context.reportRuntimeError1( "msg.not.pkg", Context.toString(arg)); } importPackage((NativeJavaPackage)arg); } return Undefined.instance; }
private Object js_importClass(Object[] args) { for (int i = 0; i != args.length; i++) { Object arg = args[i]; if (!(arg instanceof NativeJavaClass)) { throw Context.reportRuntimeError1( "msg.not.class", Context.toString(arg)); } importClass((NativeJavaClass)arg); } return Undefined.instance; }
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 static void init(Context cx, Scriptable scope, boolean sealed) { ImporterTopLevel obj = new ImporterTopLevel(); obj.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed); }