本文整理了Java中org.mozilla.javascript.Context.newArray()
方法的一些代码示例,展示了Context.newArray()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.newArray()
方法的具体详情如下:
包路径:org.mozilla.javascript.Context
类名称:Context
方法名:newArray
[英]Create an array with a specified initial length.
[中]创建具有指定初始长度的数组。
代码示例来源:origin: rnewson/couchdb-lucene
private Scriptable convertArray(final JSONArray array) throws JSONException {
final Scriptable result = context.newArray(scope, array.length());
for (int i = 0, max = array.length(); i < max; i++) {
ScriptableObject.putProperty(result, i, convert(array.get(i)));
}
return result;
}
代码示例来源:origin: stackoverflow.com
public class RJsDemo {
@Test
public void simpleRhinoTest() throws FileNotFoundException, IOException {
Context cx = Context.enter();
final JsRuntimeSupport browserSupport = new JsRuntimeSupport();
final ScriptableObject sharedScope = cx.initStandardObjects(browserSupport, true);
String[] names = { "print", "load" };
sharedScope.defineFunctionProperties(names, sharedScope.getClass(), ScriptableObject.DONTENUM);
Scriptable argsObj = cx.newArray(sharedScope, new Object[] {});
sharedScope.defineProperty("arguments", argsObj, ScriptableObject.DONTENUM);
cx.evaluateReader(sharedScope, new FileReader("./r.js"), "require", 1, null);
cx.evaluateReader(sharedScope, new FileReader("./loader.js"), "loader", 1, null);
Context.exit();
}
}
代码示例来源:origin: com.atlassian.pluginkit/ringojs-kit
public static Object toJSON(Context context, Scriptable thisObj, Object[] args, Function fn)
{
return context.newArray(thisObj, (((MyScriptableList) thisObj).list).toArray());
}
}
代码示例来源:origin: org.apache.pig/pig
/**
* creates a new javascript array
* @param size the size of the array
* @return an empty array of the given size
*/
public Scriptable jsNewArray(long size) {
return getContext().newArray(scope, (int)size);
}
代码示例来源:origin: mulesoft-labs/rhinodo
@Override
public Object call(Context cx2, Scriptable scope2, Scriptable thisObj2, Object[] args2) {
String[] list = file.list();
if ( list == null ) {
return callback.call(cx, scope, thisObj, new Object[] {null, Undefined.instance});
}
Object[] objects = new Object[list.length];
System.arraycopy(list, 0, objects, 0, list.length);
return callback.call(cx, scope, thisObj, new Object[] {null, cx.newArray(scope, objects)});
}
});
代码示例来源:origin: org.alfresco/alfresco-repository
/**
* @return Array of permissions applied directly to this Node (does not include inherited).
* Strings returned are of the format [ALLOWED|DENIED];[USERNAME|GROUPNAME];PERMISSION for example
* ALLOWED;kevinr;Consumer so can be easily tokenized on the ';' character.
*/
public Scriptable getDirectPermissions()
{
return Context.getCurrentContext().newArray(this.scope, retrieveAllSetPermissions(true, false));
}
代码示例来源:origin: com.github.tntim96/rhino
private static void match_glob(GlobData mdata, Context cx,
Scriptable scope, int count,
RegExpImpl reImpl)
{
if (mdata.arrayobj == null) {
mdata.arrayobj = cx.newArray(scope, 0);
}
SubString matchsub = reImpl.lastMatch;
String matchstr = matchsub.toString();
mdata.arrayobj.put(count, mdata.arrayobj, matchstr);
}
代码示例来源:origin: org.kohsuke.httpunit/httpunit
private Object toScriptable( ScriptableDelegate[] list ) {
Object[] delegates = new Object[ list.length ];
for (int i = 0; i < delegates.length; i++) {
delegates[i] = toScriptable( list[i] );
}
return Context.getCurrentContext().newArray( this, delegates );
}
代码示例来源:origin: geogebra/geogebra
private static void match_glob(GlobData mdata, Context cx,
Scriptable scope, int count,
RegExpImpl reImpl)
{
if (mdata.arrayobj == null) {
mdata.arrayobj = cx.newArray(scope, 0);
}
SubString matchsub = reImpl.lastMatch;
String matchstr = matchsub.toString();
mdata.arrayobj.put(count, mdata.arrayobj, matchstr);
}
代码示例来源:origin: httpunit/httpunit
private Object toScriptable( ScriptableDelegate[] list ) {
Object[] delegates = new Object[ list.length ];
for (int i = 0; i < delegates.length; i++) {
delegates[i] = toScriptable( list[i] );
}
return Context.getCurrentContext().newArray( this, delegates );
}
代码示例来源:origin: org.alfresco/alfresco-repository
/**
* @return Returns a JavaScript array of Nodes at the specified XPath starting at this Node.
* So a valid call might be <code>mynode.childrenByXPath("*[@cm:name='Testing']/*");</code>
*/
public Scriptable childrenByXPath(String xpath)
{
return Context.getCurrentContext().newArray(this.scope, getChildrenByXPath(xpath, null, false));
}
代码示例来源:origin: io.apigee/rhino
private static void match_glob(GlobData mdata, Context cx,
Scriptable scope, int count,
RegExpImpl reImpl)
{
if (mdata.arrayobj == null) {
mdata.arrayobj = cx.newArray(scope, 0);
}
SubString matchsub = reImpl.lastMatch;
String matchstr = matchsub.toString();
mdata.arrayobj.put(count, mdata.arrayobj, matchstr);
}
代码示例来源:origin: ro.isdc.wro4j/rhino
private static void match_glob(GlobData mdata, Context cx,
Scriptable scope, int count,
RegExpImpl reImpl)
{
if (mdata.arrayobj == null) {
mdata.arrayobj = cx.newArray(scope, 0);
}
SubString matchsub = reImpl.lastMatch;
String matchstr = matchsub.toString();
mdata.arrayobj.put(count, mdata.arrayobj, matchstr);
}
代码示例来源:origin: javanettasks/httpunit
private Object toScriptable( ScriptableDelegate[] list ) {
Object[] delegates = new Object[ list.length ];
for (int i = 0; i < delegates.length; i++) {
delegates[i] = toScriptable( list[i] );
}
return Context.getCurrentContext().newArray( this, delegates );
}
代码示例来源:origin: org.alfresco/alfresco-repository
/**
* @return Array of all permissions applied to this Node, including inherited.
* Strings returned are of the format [ALLOWED|DENIED];[USERNAME|GROUPNAME];PERMISSION;[INHERITED|DIRECT]
* for example: ALLOWED;kevinr;Consumer;DIRECT so can be easily tokenized on the ';' character.
*/
public Scriptable getFullPermissions()
{
return Context.getCurrentContext().newArray(this.scope, retrieveAllSetPermissions(false, true));
}
代码示例来源:origin: org.alfresco/alfresco-repository
public Scriptable getPeoplePaging(String filter, ScriptPagingDetails pagingRequest, String sortBy, Boolean sortAsc)
{
List<PersonInfo> persons = getPeopleImpl(filter, pagingRequest, sortBy, sortAsc);
Object[] peopleRefs = new Object[persons.size()];
for (int i = 0; i < peopleRefs.length; i++)
{
peopleRefs[i] = persons.get(i).getNodeRef();
}
return Context.getCurrentContext().newArray(getScope(), peopleRefs);
}
代码示例来源:origin: org.alfresco/alfresco-repository
/**
* @return Array of settable permissions for this Node
*/
public Scriptable getSettablePermissions()
{
Set<String> permissions = this.services.getPermissionService().getSettablePermissions(getNodeRef());
Object[] result = permissions.toArray(new Object[0]);
return Context.getCurrentContext().newArray(this.scope, result);
}
代码示例来源:origin: Alfresco/alfresco-repository
/**
* @return Array of settable permissions for this Node
*/
public Scriptable getSettablePermissions()
{
Set<String> permissions = this.services.getPermissionService().getSettablePermissions(getNodeRef());
Object[] result = permissions.toArray(new Object[0]);
return Context.getCurrentContext().newArray(this.scope, result);
}
代码示例来源:origin: org.alfresco/alfresco-repository
/**
* Find all the category nodes in a given classification.
*
* @param aspect String
* @return Scriptable
*/
public Scriptable getAllCategoryNodes(String aspect)
{
Object[] cats = buildCategoryNodes(services.getCategoryService().getCategories(
storeRef, createQName(aspect), CategoryService.Depth.ANY));
return Context.getCurrentContext().newArray(getScope(), cats);
}
代码示例来源:origin: org.alfresco/alfresco-repository
/**
* Get the root categories in a classification.
*
* @param aspect String
* @return Scriptable
*/
public Scriptable getRootCategories(String aspect)
{
Object[] cats = buildCategoryNodes(services.getCategoryService().getRootCategories(
storeRef, createQName(aspect)));
return Context.getCurrentContext().newArray(getScope(), cats);
}
内容来源于网络,如有侵权,请联系作者删除!