org.mozilla.javascript.Context.toObject()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 JavaScript  
字(8.3k)|赞(0)|评价(0)|浏览(160)

本文整理了Java中org.mozilla.javascript.Context.toObject()方法的一些代码示例,展示了Context.toObject()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.toObject()方法的具体详情如下:
包路径:org.mozilla.javascript.Context
类名称:Context
方法名:toObject

Context.toObject介绍

[英]Convert the value to an JavaScript object value.

Note that a scope must be provided to look up the constructors for Number, Boolean, and String.

See ECMA 9.9.

Additionally, arbitrary Java objects and classes will be wrapped in a Scriptable object with its Java fields and methods reflected as JavaScript properties of the object.
[中]将该值转换为JavaScript对象值。
请注意,必须提供一个范围来查找构造函数中的Number、Boolean和String。
见ECMA 9.9。
此外,任意Java对象和类将封装在可编写脚本的对象中,其Java字段和方法将反映为对象的JavaScript属性。

代码示例

代码示例来源:origin: apache/incubator-druid

@Override
 public Object apply(Object input)
 {
  // ideally we need a close() function to discard the context once it is not used anymore
  Context cx = Context.getCurrentContext();
  if (cx == null) {
   cx = contextFactory.enterContext();
  }
  final Object res = fn.call(cx, scope, scope, new Object[]{input});
  return res != null ? Context.toObject(res, scope) : null;
 }
};

代码示例来源:origin: pentaho/pentaho-kettle

private static Scriptable getIntValue() {
 Value value = new Value();
 value.setValue( 1 );
 return Context.toObject( value, scope );
}

代码示例来源:origin: pentaho/pentaho-kettle

private static Scriptable getDoubleValue() {
 Value value = new Value();
 value.setValue( 1.0 );
 return Context.toObject( value, scope );
}

代码示例来源:origin: pentaho/pentaho-kettle

@Test
public void jsToNumber_NativeNumber() throws Exception {
 Scriptable value = Context.toObject( 1.0, scope );
 Number number = JavaScriptUtils.jsToNumber( value, NATIVE_NUMBER );
 assertEquals( 1.0, number.doubleValue(), 1e-6 );
}

代码示例来源:origin: pentaho/pentaho-kettle

@Test
public void jsToBigNumber_NativeNumber() throws Exception {
 Scriptable value = Context.toObject( 1.0, scope );
 BigDecimal number = JavaScriptUtils.jsToBigNumber( value, NATIVE_NUMBER );
 assertEquals( 1.0, number.doubleValue(), 1e-6 );
}

代码示例来源:origin: pentaho/pentaho-kettle

@Test
public void jsToBigNumber_NativeJavaObject_BigDecimal() throws Exception {
 Value value = new Value();
 value.setValue( BigDecimal.ONE );
 Scriptable object = Context.toObject( value, scope );
 assertEquals( 1.0, JavaScriptUtils.jsToBigNumber( object, JAVA_OBJECT ).doubleValue(), 1e-6 );
}

代码示例来源:origin: pentaho/pentaho-kettle

Scriptable jsR = Context.toObject( jsScripts[i].getScript(), jsscope );
jsscope.put( jsScripts[i].getScriptName(), jsscope, jsR );
Scriptable jsvalue = Context.toObject( dummyStep, jsscope );
jsscope.put( "_step_", jsscope, jsvalue );
Scriptable jsRowMeta = Context.toObject( prev, jsscope );
jsscope.put( "rowMeta", jsscope, jsRowMeta );
for ( int i = 0; i < prev.size(); i++ ) {
  Scriptable jsarg = Context.toObject( value, jsscope );
  jsscope.put( valueMeta.getName(), jsscope, jsarg );
 } else {
  Scriptable jsarg = Context.toObject( valueData, jsscope );
  jsscope.put( valueMeta.getName(), jsscope, jsarg );
Scriptable jsval = Context.toObject( Value.class, jsscope );
jsscope.put( "Value", jsscope, jsval );
 Scriptable jsV2Row = Context.toObject( v2Row, jsscope );
 jsscope.put( "row", jsscope, jsV2Row );
} else {
 Scriptable jsRow = Context.toObject( row, jsscope );
 jsscope.put( "row", jsscope, jsRow );

代码示例来源:origin: pentaho/pentaho-kettle

Scriptable jsR = Context.toObject( sItem.getText(), jsscope );
jsscope.put( folder.getItem( i ).getText(), jsscope, jsR );
 Scriptable jsvalue = Context.toObject( dummyStep, jsscope );
 jsscope.put( "_step_", jsscope, jsvalue );
  Scriptable jsRowMeta = Context.toObject( rowMeta, jsscope );
  jsscope.put( "rowMeta", jsscope, jsRowMeta );
  for ( int i = 0; i < rowMeta.size(); i++ ) {
    Scriptable jsarg = Context.toObject( value, jsscope );
    jsscope.put( valueMeta.getName(), jsscope, jsarg );
   } else {
    Scriptable jsarg = Context.toObject( valueData, jsscope );
    jsscope.put( valueMeta.getName(), jsscope, jsarg );
  Scriptable jsval = Context.toObject( Value.class, jsscope );
  jsscope.put( "Value", jsscope, jsval );
   Scriptable jsV2Row = Context.toObject( v2Row, jsscope );
   jsscope.put( "row", jsscope, jsV2Row );
  } else {
   Scriptable jsRow = Context.toObject( row, jsscope );
   jsscope.put( "row", jsscope, jsRow );

代码示例来源:origin: pentaho/pentaho-kettle

Scriptable jsR = Context.toObject( sItem.getText(), jsscope );
jsscope.put( folder.getItem( i ).getText(), jsscope, jsR );
 Scriptable jsvalue = Context.toObject( dummyStep, jsscope );
 jsscope.put( "_step_", jsscope, jsvalue );
  Scriptable jsRowMeta = Context.toObject( rowMeta, jsscope );
  jsscope.put( "rowMeta", jsscope, jsRowMeta );
  for ( int i = 0; i < rowMeta.size(); i++ ) {
   Scriptable jsarg = Context.toObject( valueData, jsscope );
   jsscope.put( valueMeta.getName(), jsscope, jsarg );
  Scriptable jsval = Context.toObject( Value.class, jsscope );
  jsscope.put( "Value", jsscope, jsval );
  Scriptable jsRow = Context.toObject( row, jsscope );
  jsscope.put( "row", jsscope, jsRow );

代码示例来源:origin: pentaho/pentaho-kettle

Scriptable jsvalue = Context.toObject( this, data.scope );
data.scope.put( "_step_", data.scope, jsvalue );
 Scriptable jsR = Context.toObject( jsScripts[ i ].getScript(), data.scope );
 data.scope.put( jsScripts[ i ].getScriptName(), data.scope, jsR );
  Scriptable jsV2Row = Context.toObject( v2Row, data.scope );
  data.scope.put( "row", data.scope, jsV2Row );
 } else {
  Scriptable jsrow = Context.toObject( row, data.scope );
  data.scope.put( "row", data.scope, jsrow );
   Scriptable jsarg = Context.toObject( data.values_used[ i ], data.scope );
   data.scope.put( valueMeta.getName(), data.scope, jsarg );
  } else {
   Scriptable jsarg;
   if ( normalStorageValueData != null ) {
    jsarg = Context.toObject( normalStorageValueData, data.scope );
   } else {
    jsarg = null;
 Scriptable jsrowMeta = Context.toObject( rowMeta, data.scope );
 data.scope.put( "rowMeta", data.scope, jsrowMeta );
 if ( meta.isCompatible() ) {
  Row v2Row = RowMeta.createOriginalRow( rowMeta, row );
  Scriptable jsV2Row = Context.toObject( v2Row, data.scope );
  data.scope.put( "row", data.scope, jsV2Row );

代码示例来源:origin: org.zkoss.zk/zkmax

private Object toJS(Object value) {
  return value == null || (value instanceof Number) ||
    (value instanceof String) || (value instanceof Boolean) ?
      value: Context.toObject(value, _global);
}
protected void unset(String name) {

代码示例来源:origin: apache/batik

public Object run(Context cx) {
    Object a = Context.toObject(arg, globalObject);
    Object[] args = { a };
    handler.call(cx, globalObject, globalObject, args);
    return null;
  }
});

代码示例来源:origin: org.apache.cocoon/cocoon-flowscript-impl

public Scriptable getLog() {
  if (log != null) {
    return log;
  }
  log = org.mozilla.javascript.Context.toObject(getLogger(), getParentScope());
  return log;
}

代码示例来源:origin: org.ofbiz/ofbcore-jira-share

public void declareBean(BSFDeclaredBean bean) throws BSFException {
  // Must wrap non-scriptable objects before presenting to Rhino
  Scriptable wrapped = Context.toObject(bean.bean, global);
  global.put(bean.name, global, wrapped);
}

代码示例来源:origin: fr.avianey.apache-xmlgraphics/batik

public Object run(Context cx) {
    Object a = Context.toObject(arg, globalObject);
    Object[] args = { a };
    handler.call(cx, globalObject, globalObject, args);
    return null;
  }
});

代码示例来源:origin: org.apache.cocoon/cocoon-flowscript-impl

/**
 * Get the current settings object for java script.
 */
public Scriptable jsGet_settings() {
  final Settings s = this.getSettings();
  return org.mozilla.javascript.Context.toObject(s, getParentScope());
}

代码示例来源:origin: org.apache.cocoon/cocoon-flowscript-impl

/**
 * Get the current application context for java script.
 */
public Scriptable jsGet_applicationContext() {
  final WebApplicationContext w = this.getApplicationContext();
  return org.mozilla.javascript.Context.toObject(w, getParentScope());
}

代码示例来源:origin: org.apache.druid/java-util

@Override
 public Object apply(Object input)
 {
  // ideally we need a close() function to discard the context once it is not used anymore
  Context cx = Context.getCurrentContext();
  if (cx == null) {
   cx = contextFactory.enterContext();
  }
  final Object res = fn.call(cx, scope, scope, new Object[]{input});
  return res != null ? Context.toObject(res, scope) : null;
 }
};

代码示例来源:origin: org.apache.cocoon/cocoon-flowscript-impl

public Scriptable getResponse() {
  if (response != null) {
    return response;
  }
  response = org.mozilla.javascript.Context.toObject(
      ObjectModelHelper.getResponse(this.getObjectModel()),
      getParentScope());
  return response;
}

代码示例来源:origin: org.visallo/visallo-core

public Scriptable getScriptable(UserContext userContext) {
  Map<String, Scriptable> scopes = threadLocalScope.get();
  String mapKey = userContext.locale.toString() + userContext.timeZone;
  Scriptable scope = scopes.get(mapKey);
  if (scope == null) {
    scope = setupContext(getOntologyJson(userContext.getWorkspaceId()), getConfigurationJson(userContext.locale, userContext.getWorkspaceId()), userContext.timeZone);
    scopes.put(mapKey, scope);
  } else {
    scope.put("ONTOLOGY_JSON", scope, Context.toObject(getOntologyJson(userContext.getWorkspaceId()), scope));
  }
  return scope;
}

相关文章

微信公众号

Context类方法