List of usage examples for jdk.nashorn.internal.runtime JSType toString
public static String toString(final double num)
From source file:com.eas.client.RemoteModulesProxy.java
@Override public ModuleStructure getModule(String aName, Scripts.Space aSpace, Consumer<ModuleStructure> onSuccess, Consumer<Exception> onFailure) throws Exception { if (onSuccess != null) { requestModuleStructure(aName, aSpace, (ModuleStructureRequest.Response structureResp) -> { try { ModuleStructure structure = new ModuleStructure(); JSObject jsStructure = (JSObject) aSpace.parseJson(structureResp.getJson()); readCommons(jsStructure, structure); JSObject jsParts = (JSObject) jsStructure.getMember(STRUCTURE_PROP_NAME); int partsLength = JSType.toInteger(jsParts.getMember(LENGTH_PROP_NAME)); for (int i = 0; i < partsLength; i++) { String resourceName = JSType.toString(jsParts.getSlot(i)); getResource(resourceName, aSpace, (File aSynced) -> { structure.getParts().addFile(aSynced); if (structure.getParts().getFiles().size() == partsLength) { id2files.put(aName, structure.getParts() .findFileByExtension(PlatypusFiles.JAVASCRIPT_EXTENSION)); onSuccess.accept(structure); }// w ww . j a v a 2 s . com }, onFailure); } } catch (Exception ex) { if (onFailure != null) { onFailure.accept(ex); } } }, onFailure); return null; } else { ModuleStructureRequest.Response structureResp = requestModuleStructure(aName, null, null, null); ModuleStructure structure = new ModuleStructure(); JSObject jsStructure = (JSObject) aSpace.parseJson(structureResp.getJson()); readCommons(jsStructure, structure); JSObject jsParts = (JSObject) jsStructure.getMember(STRUCTURE_PROP_NAME); int partsLength = JSType.toInteger(jsParts.getMember(LENGTH_PROP_NAME)); for (int i = 0; i < partsLength; i++) { String resourceName = JSType.toString(jsParts.getSlot(i)); File synced = getResource(resourceName, aSpace, null, null); structure.getParts().addFile(synced); } id2files.put(aName, structure.getParts().findFileByExtension(PlatypusFiles.JAVASCRIPT_EXTENSION)); return structure; } }
From source file:com.eas.client.RemoteModulesProxy.java
private void readCommons(JSObject jsStructure, ModuleStructure structure) { JSObject jsClientDependencies = (JSObject) jsStructure.getMember(CLIENT_DEPENDENCIES_PROP_NAME); int clientDepsLength = JSType.toInteger(jsClientDependencies.getMember(LENGTH_PROP_NAME)); for (int i = 0; i < clientDepsLength; i++) { String dep = JSType.toString(jsClientDependencies.getSlot(i)); structure.getClientDependencies().add(dep); }//from w w w.j a v a 2s . c o m JSObject jsQueryDependencies = (JSObject) jsStructure.getMember(QUERY_DEPENDENCIES_PROP_NAME); int queryDepsLength = JSType.toInteger(jsQueryDependencies.getMember(LENGTH_PROP_NAME)); for (int i = 0; i < queryDepsLength; i++) { String dep = JSType.toString(jsQueryDependencies.getSlot(i)); structure.getQueryDependencies().add(dep); } JSObject jsServerDependencies = (JSObject) jsStructure.getMember(SERVER_DEPENDENCIES_PROP_NAME); int serverDepsLength = JSType.toInteger(jsServerDependencies.getMember(LENGTH_PROP_NAME)); for (int i = 0; i < serverDepsLength; i++) { String dep = JSType.toString(jsServerDependencies.getSlot(i)); structure.getServerDependencies().add(dep); } }
From source file:com.eas.client.RemoteServerModulesProxy.java
private ServerModuleInfo readInfo(String aModuleName, JSObject jsProxy) { Set<String> functions = new HashSet<>(); JSObject jsFunctions = (JSObject) jsProxy.getMember(CREATE_MODULE_RESPONSE_FUNCTIONS_PROP); int length = JSType.toInteger(jsFunctions.getMember(LENGTH_PROP_NAME)); for (int i = 0; i < length; i++) { String fName = JSType.toString(jsFunctions.getSlot(i)); functions.add(fName);//from w w w .jav a 2 s. com } boolean permitted = JSType.toBoolean(jsProxy.getMember(CREATE_MODULE_RESPONSE_IS_PERMITTED_PROP)); return new ServerModuleInfo(aModuleName, functions, permitted); }
From source file:com.eas.client.threetier.json.FieldsJSONReader.java
public static void readFields(JSObject pa, Fields aFields) { int length = JSType.toInteger(pa.getMember("length")); for (int i = 0; i < length; i++) { JSObject po = (JSObject) pa.getSlot(i); assert po != null; String name = JSType.toString(po.getMember(NAME_PROP_NAME)); String desc = JSType.toString(po.getMember(DESCRIPTION_PROP_NAME)); String type = po.hasMember(TYPE_PROP_NAME) && po.getMember(TYPE_PROP_NAME) != null ? JSType.toString(po.getMember(TYPE_PROP_NAME)) : null;// w ww . ja va2 s . co m boolean pk = JSType.toBoolean(po.getMember(PK_PROP_NAME)); boolean nullable = JSType.toBoolean(po.getMember(NULLABLE_PROP_NAME)); Field f = aFields instanceof Parameters ? new Parameter(name) : new Field(name); f.setDescription(desc); f.setType(type); f.setPk(pk); f.setNullable(nullable); aFields.add(f); } }
From source file:com.eas.client.threetier.json.QueryJSONReader.java
public static PlatypusQuery read(JSObject o) { PlatypusQuery query = new PlatypusQuery(null); String title = JSType.toString(o.getMember(TITLE_PROP_NAME)); query.setTitle(title);//from ww w . ja v a 2 s . c om String entityName = JSType.toString(o.getMember(APP_ELEMENT_PROP_NAME)); query.setEntityName(entityName); // parameters JSObject jsParameters = (JSObject) o.getMember(PARAMETERS_PROP_NAME); assert jsParameters != null && jsParameters.isArray(); Parameters params = new Parameters(); FieldsJSONReader.readFields(jsParameters, params); for (int i = 0; i < params.getParametersCount(); i++) { Parameter p = params.get(i + 1); query.putParameter(p.getName(), p.getType(), p.getValue()); } // fields JSObject jsFields = (JSObject) o.getMember(FIELDS_PROP_NAME); assert jsFields != null && jsFields.isArray(); Fields fields = new Fields(); FieldsJSONReader.readFields(jsFields, fields); query.setFields(fields); return query; }
From source file:io.stallion.plugins.javascript.JavascriptShell.java
License:Open Source License
private static int readEvalPrint(InputStream input, OutputStream out, Context context, Global global) throws IOException, ScriptException { JsPluginSettings pluginSettings = new JsPluginSettings(); //context.eval(global, ""); //Global global = context.createGlobal(); //ScriptEnvironment env = context.getEnv(); String prompt = bundle.getString("shell.prompt"); //BufferedReader in = new BufferedReader(new InputStreamReader(input)); ConsoleReader in = new ConsoleReader(); PrintWriter err = context.getErr(); Global oldGlobal = Context.getGlobal(); boolean globalChanged = oldGlobal != global; ScriptEnvironment env = context.getEnv(); if (DB.available()) { global.put("DB", DB.instance(), false); }/*from w w w . j a v a2s . c om*/ try { if (globalChanged) { Context.setGlobal(global); } global.addShellBuiltins(); // Load builtins global.put("javaToJsHelpers", new JavaToJsHelpers(Sandbox.allPermissions()), true); SandboxedContext ctx = new SandboxedContext(Settings.instance().getTargetFolder() + "/js", Sandbox.allPermissions(), pluginSettings); global.put("myContext", ctx, true); String stallionSharedJs = IOUtils .toString(JavascriptShell.class.getResource("/jslib/stallion_shared.js"), UTF8); context.eval(global, "load(" + JSON.stringify( map(val("script", stallionSharedJs), val("name", "stallion_shared.js"))) + ");", global, "<shellboot>"); global.put("stallionClassLoader", new UnrestrictedJsClassLoader(), true); while (true) { String source; do { //err.print(prompt); //err.flush(); source = ""; try { source = in.readLine(prompt); } catch (IOException var14) { err.println(var14.toString()); } if (source == null) { return 0; } } while (source.isEmpty()); try { Object e = context.eval(global, source, global, "<shell>"); if (e != ScriptRuntime.UNDEFINED) { err.println(JSType.toString(e)); } } catch (Exception var15) { err.println(var15); if (env._dump_on_error) { var15.printStackTrace(err); } } } } finally { if (globalChanged) { Context.setGlobal(oldGlobal); } } }
From source file:org.kihara.util.JavascriptEngine.java
License:Open Source License
/** * read-eval-print loop for Nashorn shell. * * @param context the nashorn context/*ww w . j ava 2 s.c om*/ * @param global global scope object to use * @return return code */ @SuppressWarnings("resource") private static int readEvalPrint(final Context context, final ScriptObject global) { final String prompt = "> ";//bundle.getString("shell.prompt"); final BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); final PrintWriter err = context.getErr(); final ScriptObject oldGlobal = Context.getGlobal(); final boolean globalChanged = (oldGlobal != global); final ScriptEnvironment env = context.getEnv(); try { if (globalChanged) { Context.setGlobal(global); } // initialize with "shell.js" script try { final Source source = Source.sourceFor("<shell.js>", JavascriptEngine.SHELL_INIT_JS); context.eval(global, source.getString(), global, "<shell.js>", false, false); // custom scripts context.eval(global, script.get(), global, "<shell.js>", false, false); } catch (final Exception e) { err.println(e); if (env._dump_on_error) { e.printStackTrace(err); } return INTERNAL_ERROR; } while (true) { err.print(prompt); err.flush(); String source = ""; try { source = in.readLine(); } catch (final IOException ioe) { err.println(ioe.toString()); } if (source == null) { break; } if (source.isEmpty()) { continue; } Object res; try { res = context.eval(global, source, global, "<shell>", env._strict, false); } catch (final Exception e) { err.println(e); if (env._dump_on_error) { e.printStackTrace(err); } continue; } if (res != ScriptRuntime.UNDEFINED) { err.println(JSType.toString(res)); } } } finally { if (globalChanged) { Context.setGlobal(global); } } return SUCCESS; }