Refine search
@Override public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { if (args.length == 0) { throw new RuntimeException("'load' function takes at least one argument"); } for (Object arg : args) { if (arg instanceof NativeArray) { NativeArray array = (NativeArray)arg; for (int i = 0; i < array.getLength(); i++) { Object path = array.get(i); if (path != null) { load(path.toString(), cx, scope); } else { throw new NullPointerException("Cannot have null argument in load function"); } } } else if (arg == null) { throw new NullPointerException("Cannot have null argument in load function"); } else { load(arg.toString(), cx, scope); } } return null; }
Context cx = Context.enter(); Scriptable scope = cx.initStandardObjects(); NativeObject configObject = config.toNativeObject(); for (int i = 0; i < rows.size(); i++) { Object o = rows.get(i, rows); sb.append((String)NativeJSON.stringify(cx, scope, o, null, null)); if (i < rows.size()-1) { sb.append(","); return sb.toString(); } finally { Context.exit();
Context cx = Context.enter(); try { Scriptable scope = cx.initStandardObjects(); List<DBObject> objects = this.fongoDBCollection.find(query).sort(sort).limit(limit).toArray(); List<String> javascriptFunctions = constructJavascriptFunction(objects); for (String jsFunction : javascriptFunctions) { try { cx.evaluateString(scope, jsFunction, "<map-reduce>", 0, null); } catch (RhinoException e) { LOG.error("Exception running script {}", jsFunction, e); for (int i = 0; i < outs.getLength(); i++) { NativeObject out = (NativeObject) outs.get(i, outs); outmode.newResult(coll, getObject(out));
public RhinoCompiler(LessOptions options, ResourceLoader loader, URL less, URL env, URL engine, URL cssmin, URL sourceMap) throws IOException { Context cx = Context.enter(); logger.debug("Using implementation version: " + cx.getImplementationVersion()); cx.setOptimizationLevel(-1); Global global = new Global(); global.init(cx); lessEnv.put("loader", lessEnv, Context.javaToJS(loader, scope)); if(options.getPaths() != null) { NativeArray nativeArray = new NativeArray(options.getPaths()); lessEnv.put("paths", lessEnv, nativeArray);
rhino.setOptimizationLevel(-1); Scriptable scope = rhino.initStandardObjects(); ScriptableObject.putProperty(scope, "javaContext", Context.javaToJS(this, scope)); rhino.evaluateString(scope, jsSource, "ScriptAPI", 1, null); String[][] javaArray = new String[nativeArray.size()][((NativeArray)nativeArray.get(0)).size()]; for (Integer row : nativeArray.getIndexIds()) { for(int column=0;column<((NativeArray)nativeArray.get(row)).size();column++){ javaArray[row][column] = (String)((NativeArray) nativeArray.get(row)).get(column);
propertyList = new LinkedList<Object>(); NativeArray replacerArray = (NativeArray) replacer; for (int i : replacerArray.getIndexIds()) { Object v = replacerArray.get(i, replacerArray); if (v instanceof String || v instanceof Number) { propertyList.add(v); } else if (v instanceof NativeString || v instanceof NativeNumber) { propertyList.add(ScriptRuntime.toString(v)); space = ScriptRuntime.toNumber(space); } else if (space instanceof NativeString) { space = ScriptRuntime.toString(space); wrapper.setParentScope(scope); wrapper.setPrototype(ScriptableObject.getObjectPrototype(scope)); wrapper.defineProperty("", value, 0); return str("", wrapper, state);
if (filename == null) { console.println(cx.getImplementationVersion()); if (cx.stringIsCompilableUnit(source)) break; prompt = prompts[1]; Script script = cx.compileString(source, "<stdin>", lineno, null); if (script != null) { Object result = script.exec(cx, scope); h.put((int)h.getLength(), h, source);
final List<List<Object>> data = new ArrayList<>(); final NativeArray array = NativeArray.class.cast(args[2]); final Object[] ids = array.getIds(); for (int i = 0; i < array.getLength(); i++) { data.add(asList(array.get((int)ids[i], null))); final String[] columns = new String[args.length]; for (int i = 0; i < args.length; i++) { columns[i] = Context.toString(args[i]);
for (Object nao: na.getIds()) target = findObject(na.get(index, null), targetAttributeKey, targetAttributeValue, delete, results); if (target != null) ScriptableObject.callMethod(Context.getCurrentContext(), na, "splice",
double d = ScriptRuntime.toNumber(val); long longVal = ScriptRuntime.toUint32(d); if (longVal != d) { String msg = ScriptRuntime.getMessage0("msg.arraylength.bad"); throw ScriptRuntime.constructError("RangeError", msg); } else if (longVal < MAX_PRE_GROW_SIZE && longVal < (length * GROW_FACTOR) && ensureCapacity((int)longVal)) Object[] e = getIds(); // will only find in object itself for (int i=0; i < e.length; i++) { Object id = e[i]; long index = toArrayIndex(strId); if (index >= longVal) delete(strId); } else { int index = ((Integer)id).intValue(); if (index >= longVal) delete(index); deleteElem(this, i);
if (root instanceof JavaScriptException) { Scriptable value = (Scriptable) ((JavaScriptException) root).getValue(); String type = (String) ScriptableObject.getProperty(value, "type") + " Error"; String message = (String) ScriptableObject.getProperty(value, "message"); String filename = ""; if (ScriptableObject.hasProperty(value, "filename")) { filename = (String) ScriptableObject.getProperty(value, "filename"); if (ScriptableObject.hasProperty(value, "extract")) { NativeArray extract = (NativeArray) ScriptableObject.getProperty(value, "extract"); for (int i = 0; i < extract.getLength(); i++) { if (extract.get(i, extract) instanceof String) { extractList.add(((String) extract.get(i, extract)).replace("\t", " "));
return ScriptRuntime.toString(value); return ScriptRuntime.toString(value); long length = array.getLength(); Class<?> arrayType = type.getComponentType(); Object Result = Array.newInstance(arrayType, (int)length); try { Array.set(Result, i, coerceType(arrayType, array.get(i, array))); Object key = Kit.makeHashKeyFromPair( COERCED_INTERFACE_KEY, type); Object old = so.getAssociatedValue(key); if (old != null) { Context cx = Context.getContext(); Object glue = InterfaceAdapter.create(cx, type, (Callable)value); glue = so.associateValue(key, glue); return glue;
public Object jsGet_content() throws CarbonException { try { Object result = this.resource.getContent(); String mediaType = this.resource.getMediaType(); if (result instanceof byte[]) { //if mediaType is xml related one, we return an e4x xml object if(mediaType.matches(".*[\\/].*[xX][mM][lL].*")) { return context.newObject(this, "XML", new Object[]{new String((byte[]) result)}); } return new String((byte[]) result); } else if (result instanceof String[]) { return new NativeArray((String[])result); } else { return Context.toObject(result, this); } } catch (RegistryException e) { throw new CarbonException("Registry Exception while reading content property", e); } }
public NativeArray jsFunction_getChildren() throws Exception { List list = wk.getChildren(); NativeArray arr = (NativeArray)org.mozilla.javascript.Context.getCurrentContext().newObject(getParentScope(), "Array", new Object[]{new Integer(list.size())}); Iterator iter = list.iterator(); for (int i = 0; iter.hasNext(); i++) { WebContinuation child = (WebContinuation)iter.next(); FOM_WebContinuation cwk = new FOM_WebContinuation(child); cwk.setParentScope(getParentScope()); cwk.setPrototype(getClassPrototype(getParentScope(), cwk.getClassName())); arr.put(i, arr, cwk); } return arr; }
Scriptable value = (Scriptable) ((JavaScriptException) root) .getValue(); String type = ScriptableObject.getProperty(value, "type") .toString() + " Error"; String message = ScriptableObject.getProperty(value, "message") .toString(); String filename = ""; if (hasProperty(value, "filename")) { filename = ScriptableObject.getProperty(value, "filename") .toString(); NativeArray extract = (NativeArray) ScriptableObject .getProperty(value, "extract"); for (int i = 0; i < extract.getLength(); i++) { if (extract.get(i, extract) instanceof String) { extractList.add(((String) extract.get(i, extract)) .replace("\t", " "));
Object[] params = new Object[]{numberOfWeeks, weeklyDisposable, easing, safetyZone, safetyZoneEasing, overSpentThisWeek}; // function doesn't return anything jsFunction.call(rhino, scope, scope, params); NativeArray resultArray = (NativeArray) scope.get("resultArray", scope); double result = ((Number) resultArray.get(numberOfWeeks)).getDoubleValue(); Log.d(TAG, "SKN-calculate3=" + result);
static long getLengthProperty(Context cx, Scriptable obj) { // These will both give numeric lengths within Uint32 range. if (obj instanceof NativeString) { return ((NativeString)obj).getLength(); } else if (obj instanceof NativeArray) { return ((NativeArray)obj).getLength(); } Object len = ScriptableObject.getProperty(obj, "length"); if (len == Scriptable.NOT_FOUND) { // toUint32(undefined) == 0 return 0; } return ScriptRuntime.toUint32(len); }
/** * See ECMA 15.4.1,2 */ private static Object jsConstructor(Context cx, Scriptable scope, Object[] args) { if (args.length == 0) return new NativeArray(0); // Only use 1 arg as first element for version 1.2; for // any other version (including 1.3) follow ECMA and use it as // a length. if (cx.getLanguageVersion() == Context.VERSION_1_2) { return new NativeArray(args); } else { Object arg0 = args[0]; if (args.length > 1 || !(arg0 instanceof Number)) { return new NativeArray(args); } else { long len = ScriptRuntime.toUint32(arg0); if (len != ((Number)arg0).doubleValue()) { String msg = ScriptRuntime.getMessage0("msg.arraylength.bad"); throw ScriptRuntime.constructError("RangeError", msg); } return new NativeArray(len); } } }