本文整理了Java中org.mozilla.javascript.Context.newObject()
方法的一些代码示例,展示了Context.newObject()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.newObject()
方法的具体详情如下:
包路径:org.mozilla.javascript.Context
类名称:Context
方法名:newObject
[英]Create a new JavaScript object. Equivalent to evaluating "new Object()".
[中]创建一个新的JavaScript对象。相当于计算“newobject()”。
代码示例来源:origin: stackoverflow.com
String script = "function abc(x,y) {return x+y;}";
Context context = Context.enter();
try {
ScriptableObject scope = context.initStandardObjects();
Scriptable that = context.newObject(scope);
Function fct = context.compileFunction(scope, script, "script", 1, null);
Object result = fct.call(
context, scope, that, new Object[] {2, 3});
System.out.println(Context.jsToJava(result, int.class));
} finally {
Context.exit();
}
代码示例来源:origin: pentaho/pentaho-kettle
@Test
public void jsToDate_NativeDate() throws Exception {
Date date = new Date( 1 );
Scriptable value = ctx.newObject( scope, "Date", new Object[] { date.getTime() } );
assertEquals( date, JavaScriptUtils.jsToDate( value, "org.mozilla.javascript.NativeDate" ) );
}
代码示例来源:origin: rnewson/couchdb-lucene
private Scriptable convertObject(final JSONObject obj) throws JSONException {
if (obj == JSONObject.NULL) {
return null;
}
final Scriptable result = context.newObject(scope);
final Iterator<?> it = obj.keys();
while (it.hasNext()) {
final String key = (String) it.next();
final Object value = obj.get(key);
ScriptableObject.putProperty(result, key, convert(value));
}
return result;
}
代码示例来源:origin: rhino/js
/**
* Create a new JavaScript object.
*
* Equivalent to evaluating "new Object()".
* @param scope the scope to search for the constructor and to evaluate
* against
* @return the new object
*/
public final Scriptable newObject(Scriptable scope)
{
return newObject(scope, "Object", ScriptRuntime.emptyArgs);
}
代码示例来源:origin: geogebra/geogebra
private NativeArrayBuffer makeArrayBuffer(Context cx, Scriptable scope, int length)
{
return (NativeArrayBuffer)cx.newObject(scope, NativeArrayBuffer.CLASS_NAME,
new Object[] { length });
}
代码示例来源:origin: com.sun.phobos/phobos-rhino
/**
* Create a new JavaScript object.
*
* Equivalent to evaluating "new Object()".
* @param scope the scope to search for the constructor and to evaluate
* against
* @return the new object
*/
public final Scriptable newObject(Scriptable scope)
{
return newObject(scope, "Object", ScriptRuntime.emptyArgs);
}
代码示例来源:origin: com.googlecode.jslint4java/jslint4java
public Object run(Context cx) {
applyDefaultOptions();
Scriptable opts = cx.newObject(lintFunc);
for (Entry<Option, Object> entry : options.entrySet()) {
String key = entry.getKey().getLowerName();
// Use our "custom" version in order to get native arrays.
Object value = Util.javaToJS(entry.getValue(), opts);
opts.put(key, opts, value);
}
return opts;
}
});
代码示例来源:origin: cardillo/joinery
public static Scriptable jsStaticFunction_readXls(final Context ctx, final Scriptable object, final Object[] args, final Function func)
throws IOException {
final String file = Context.toString(args[0]);
final DataFrame<Object> df = DataFrame.readXls(file);
return new DataFrameAdapter(ctx.newObject(object, df.getClass().getSimpleName()), df);
}
代码示例来源:origin: io.apigee.trireme/trireme-util
@Override
public Scriptable registerExports(Context cx, Scriptable global, NodeRuntime runtime)
throws InvocationTargetException, IllegalAccessException, InstantiationException
{
ScriptableObject.defineClass(global, XmlWrapImpl.class);
XmlWrapImpl wrap = (XmlWrapImpl)cx.newObject(global, XmlWrapImpl.CLASS_NAME);
wrap.initTransformer(cx, runtime);
return wrap;
}
代码示例来源:origin: joinery/joinery-dataframe
public static Scriptable jsStaticFunction_readCsv(final Context ctx, final Scriptable object, final Object[] args, final Function func)
throws IOException {
final String file = Context.toString(args[0]);
final DataFrame<Object> df = DataFrame.readCsv(file);
return new DataFrameAdapter(ctx.newObject(object, df.getClass().getSimpleName()), df);
}
代码示例来源:origin: io.apigee.trireme/trireme-util
@Override
public Scriptable registerExports(Context cx, Scriptable global, NodeRuntime runtime)
throws InvocationTargetException, IllegalAccessException, InstantiationException
{
ScriptableObject.defineClass(global, IconvModuleImpl.class);
Scriptable exports = cx.newObject(global, IconvModuleImpl.CLASS_NAME);
ScriptableObject.defineClass(exports, IconvImpl.class);
return exports;
}
代码示例来源:origin: httpunit/httpunit
static ElementArray newElementArray( Scriptable parent ) {
try {
return (ElementArray) Context.getCurrentContext().newObject( parent, "ElementArray" );
} catch (PropertyException e) {
throw new RhinoException( e );
} catch (NotAFunctionException e) {
throw new RhinoException( e );
} catch (JavaScriptException e) {
throw new RhinoException( e );
}
}
代码示例来源:origin: io.apigee.trireme/trireme-util
@JSFunction
@SuppressWarnings("unused")
public static Object createDocument(Context cx, Scriptable thisObj, Object[] args, Function funObj)
{
ensureArg(args, 0);
XmlWrapImpl self = (XmlWrapImpl)thisObj;
Source src = self.getSource(cx, args[0]);
ScriptableObject ret = (ScriptableObject)cx.newObject(thisObj);
ret.associateValue("document", src);
return ret;
}
代码示例来源:origin: httpunit/httpunit
public Scriptable jsGet_frames() throws SAXException, PropertyException, JavaScriptException, NotAFunctionException {
if (_frames == null) {
WebResponse.Scriptable scriptables[] = getDelegate().getFrames();
Window[] frames = new Window[ scriptables.length ];
for (int i = 0; i < frames.length; i++) {
frames[ i ] = (Window) toScriptable( scriptables[ i ] );
}
_frames = (ElementArray) Context.getCurrentContext().newObject( this, "ElementArray" );
_frames.initialize( frames );
}
return _frames;
}
代码示例来源:origin: httpunit/httpunit
private void initializeControls() throws PropertyException, NotAFunctionException, JavaScriptException {
ScriptableDelegate scriptables[] = getDelegate().getElementDelegates();
Control[] controls = new Control[ scriptables.length ];
for (int i = 0; i < controls.length; i++) {
controls[ i ] = (Control) toScriptable( scriptables[ i ] );
}
_controls = (ElementArray) Context.getCurrentContext().newObject( this, "ElementArray" );
_controls.initialize( controls );
}
代码示例来源:origin: com.google.code.scriptengines/scriptengines-javascript
public static void init(Context cx, Scriptable scope, boolean sealed)
throws RhinoException {
JSAdapter obj = new JSAdapter(cx.newObject(scope));
obj.setParentScope(scope);
obj.setPrototype(getFunctionPrototype(scope));
obj.isPrototype = true;
ScriptableObject.defineProperty(scope, "JSAdapter", obj,
ScriptableObject.DONTENUM);
}
代码示例来源:origin: javanettasks/httpunit
public Scriptable jsGet_frames() throws SAXException, PropertyException, JavaScriptException, NotAFunctionException {
if (_frames == null) {
WebResponse.Scriptable scriptables[] = getDelegate().getFrames();
Window[] frames = new Window[ scriptables.length ];
for (int i = 0; i < frames.length; i++) {
frames[ i ] = (Window) toScriptable( scriptables[ i ] );
}
_frames = (ElementArray) Context.getCurrentContext().newObject( this, "ElementArray" );
_frames.initialize( frames );
}
return _frames;
}
代码示例来源:origin: io.apigee.trireme/trireme-util
@Override
public Scriptable registerExports(Context cx, Scriptable global, NodeRuntime runtime)
throws InvocationTargetException, IllegalAccessException, InstantiationException
{
ScriptableObject.defineClass(global, Referenceable.class);
ScriptableObject.defineClass(global, JdbcImpl.class);
ScriptableObject.defineClass(global, JdbcConnection.class, false, true);
ScriptableObject.defineClass(global, JdbcResultHandle.class);
JdbcImpl impl = (JdbcImpl)cx.newObject(global, JdbcImpl.CLASS_NAME);
impl.init(runtime);
return impl;
}
代码示例来源:origin: io.apisense/rhino-android
public static void init(Context cx, Scriptable scope, boolean sealed)
throws RhinoException {
JSAdapter obj = new JSAdapter(cx.newObject(scope));
obj.setParentScope(scope);
obj.setPrototype(getFunctionPrototype(scope));
obj.isPrototype = true;
ScriptableObject.defineProperty(scope, "JSAdapter", obj,
ScriptableObject.DONTENUM);
}
代码示例来源:origin: org.kohsuke.httpunit/httpunit
public Scriptable jsGet_frames() throws SAXException, PropertyException, JavaScriptException, NotAFunctionException {
if (_frames == null) {
WebResponse.Scriptable scriptables[] = getDelegate().getFrames();
Window[] frames = new Window[ scriptables.length ];
for (int i = 0; i < frames.length; i++) {
frames[ i ] = (Window) toScriptable( scriptables[ i ] );
}
_frames = (ElementArray) Context.getCurrentContext().newObject( this, "ElementArray" );
_frames.initialize( frames );
}
return _frames;
}
内容来源于网络,如有侵权,请联系作者删除!