示例#1
0
 /**
  * Get a wrapper for an object that exposes it as Java object to JavaScript.
  *
  * @param object an object
  * @return the object wrapped as native java object
  */
 public Object asJavaObject(Object object) {
   if (object instanceof Wrapper) {
     object = ((Wrapper) object).unwrap();
   }
   Context cx = Context.getCurrentContext();
   return wrapFactory.wrapAsJavaObject(cx, globalScope, object, null);
 }
示例#2
0
 /**
  * Get a wrapper for a string that exposes the java.lang.String methods to JavaScript This is
  * useful for accessing strings as java.lang.String without the cost of creating a new instance.
  *
  * @param object an object
  * @return the object converted to a string and wrapped as native java object
  */
 public Object asJavaString(Object object) {
   if (!(object instanceof String)) {
     object = object.toString();
   }
   Context cx = Context.getCurrentContext();
   return wrapFactory.wrapAsJavaObject(cx, globalScope, object, null);
 }