code: public Scriptable wrapNewObject(Context cx, Scriptable scope, Object obj)
      {
          if (obj instanceof Scriptable) {
              return (Scriptable)obj;
          }
          Class<?> cls = obj.getClass();
          if (cls.isArray()) {
              return NativeJavaArray.wrap(scope, obj);
          }
          return wrapAsJavaObject(cx, scope, obj, null);
      }
docs: Wrap an object newly created by a constructor call.
  @param cx the current Context for this thread
  @param scope the scope of the executing script
  @param obj the object to be wrapped
  @return the wrapped value.