本文整理了Java中org.mozilla.javascript.NativeArray
类的一些代码示例,展示了NativeArray
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NativeArray
类的具体详情如下:
包路径:org.mozilla.javascript.NativeArray
类名称:NativeArray
[英]This class implements the Array native object.
[中]此类实现了数组本机对象。
代码示例来源:origin: stackoverflow.com
NativeArray arr = (NativeArray) result;
Object [] array = new Object[(int) arr.getLength()];
for (Object o : arr.getIds()) {
int index = (Integer) o;
array[index] = arr.get(index, null);
}
代码示例来源:origin: galenframework/galen
@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;
}
代码示例来源:origin: com.couchbase.mock/CouchbaseMock
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();
代码示例来源:origin: com.foursquare/fongo
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));
代码示例来源:origin: com.asual.lesscss/lesscss-engine
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);
代码示例来源:origin: org.apache.cocoon/cocoon-expression-language-impl
public Object next() {
Context.enter();
try {
Object result = arr.get(index++, arr);
return unwrap(result);
} finally {
Context.exit();
}
}
代码示例来源:origin: stackoverflow.com
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);
代码示例来源:origin: io.apigee/rhino
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);
代码示例来源:origin: ro.isdc.wro4j/rhino
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);
代码示例来源:origin: cardillo/joinery
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]);
代码示例来源:origin: org.springframework.extensions.surf/spring-surf
for (Object nao: na.getIds())
target = findObject(na.get(index, null), targetAttributeKey, targetAttributeValue, delete, results);
if (target != null)
ScriptableObject.callMethod(Context.getCurrentContext(),
na,
"splice",
代码示例来源:origin: geogebra/geogebra
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);
代码示例来源:origin: com.google.code.maven-play-plugin.com.asual.lesscss/lesscss-engine
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", " "));
代码示例来源:origin: rhino/js
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;
代码示例来源:origin: org.wso2.carbon.governance/org.wso2.carbon.mashup.javascript.hostobjects.registry
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);
}
}
代码示例来源:origin: org.apache.cocoon/cocoon-flowscript-impl
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;
}
代码示例来源:origin: com.asual.lesscss/lesscss-engine
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", " "));
代码示例来源:origin: stackoverflow.com
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);
代码示例来源:origin: geogebra/geogebra
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);
}
代码示例来源:origin: io.apigee/rhino
/**
* 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);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!