gt: 	protected Object wrapObject(Object object) {		
context: /**
   * Hostedobject.java
   * (c) Radim Loskot and Radek Burget, 2013-2014
   *
   * ScriptBox is free software: you can redistribute it and/or modify
   * it under the terms of the GNU Lesser General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *  
   * ScriptBox is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   * GNU Lesser General Public License for more details.
   *  
   * You should have received a copy of the GNU Lesser General Public License
   * along with ScriptBox. If not, see <http://www.gnu.org/licenses/>.
   * 
   */
  
  package com.jsen.javascript.java;
  
  import java.lang.reflect.Constructor;
  import java.lang.reflect.Method;
  import java.util.Arrays;
  import java.util.HashSet;
  import java.util.Set;
  
  import org.apache.commons.lang3.ClassUtils;
  import org.mozilla.javascript.Context;
  import org.mozilla.javascript.Function;
  import org.mozilla.javascript.NativeObject;
  import org.mozilla.javascript.Scriptable;
  import org.mozilla.javascript.TopLevel;
  import org.mozilla.javascript.TopLevel.Builtins;
  import org.mozilla.javascript.Undefined;
  import org.mozilla.javascript.Wrapper;
  
  import com.jsen.core.exceptions.FieldException;
  import com.jsen.core.exceptions.FunctionException;
  import com.jsen.core.exceptions.InternalException;
  import com.jsen.core.exceptions.ObjectException;
  import com.jsen.core.exceptions.UnknownException;
  import com.jsen.core.reflect.ClassConstructor;
  import com.jsen.core.reflect.ClassField;
  import com.jsen.core.reflect.ClassFunction;
  import com.jsen.core.reflect.ClassMember;
  import com.jsen.core.reflect.ConstructorMember;
  import com.jsen.core.reflect.DefaultObjectMembers;
  import com.jsen.core.reflect.InvocableMember;
  import com.jsen.core.reflect.ObjectGetter;
  import com.jsen.core.reflect.ObjectMembers;
  import com.jsen.javascript.JavaScriptEngine;
  import com.jsen.javascript.JsCallback;
  import com.jsen.javascript.wrap.FunctionJsCallbackAdapter;
  
  /**
   * Creates scope for native Java object which contains its class 
   * member properties. In other words, wraps the native Java object
   * and makes it accessible from the JavaScript.
   * 
   * @author Radim Loskot
   * @version 0.9
   * @since 0.9 - 21.4.2014
   */
  public class HostedJavaObject extends ObjectScriptable implements Wrapper, Function {
  
  	private static final long serialVersionUID = 6761328943903362404L;
  	
  	protected boolean hasNonObjectGetterGet;
  		
  	protected ObjectMembers objectMembers;
  	
  	/**
  	 * Constructs new scope representing the native Java object.
  	 * 
  	 * @param scope Scope to become the parent scope of this Java object.
  	 * @param object Java object to be wrapped.
  	 */
  	public HostedJavaObject(Scriptable scope, Object object) {
  		this(scope, DefaultObjectMembers.getObjectMembers(object));
  	}
  	
  	/**
  	 * Constructs new scope that contains the passed object members.
  	 * 
  	 * @param scope Scope to become the parent scope of this Java object.
  	 * @param objectMembers Object and its members to be put into this new scope.
  	 */
  	public HostedJavaObject(Scriptable scope, ObjectMembers objectMembers) {
  		super(objectMembers.getObject(), scope, null);
  		
  		this.objectMembers = objectMembers;
  		
  		TopLevel topLevel = JavaScriptEngine.getObjectTopLevel(scope);
  		Scriptable builtinObject = topLevel.getBuiltinCtor(Builtins.Object);
  		setPrototype(builtinObject);
  		
  		if (object instanceof ObjectGetter) {
  			Class<?>[] getterArgs = ObjectGetter.METHOD_ARG_TYPES;
  			String getterName = ObjectGetter.METHOD_NAME;
  			for (Method method : objectClass.getMethods()) {
  				String methodName = method.getName();
  				Class<?>[] methodParams = method.getParameterTypes();
  				if (methodName.equals(getterName) && !Arrays.equals(methodParams, getterArgs)) {
  					hasNonObjectGetterGet = true;
  					break;
  				}
  			}
  		}
  	}
  	
  	@Override
  	public String getClassName() {
  		return "Hostedobject";
  	}
  	
  	@Override
  	public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
  		return Undefined.instance;
  	}
  	
  	@Override
  	public Scriptable construct(Context cx, Scriptable scope, Object[] args) {
  		Scriptable result = new NativeObject();
  		result.setParentScope(getParentScope());
  		
  		Set<ClassConstructor> constructors = objectMembers.getConstructors();
  		
  		if (constructors == null || constructors.isEmpty()) {
  			throw new ObjectException("Object does not contain any constructors!");
  		}
  		
  		InvocableMember<?> nearestInvocable = HostedJavaMethod.getNearestObjectFunction(args, constructors);
  
  		if (nearestInvocable == null) {
  			throw new FunctionException("Unable to match nearest constructor");
  		}
  		
  		ConstructorMember nearestConstructorMember = (ConstructorMember)nearestInvocable;
  		
  		Constructor<?> constructor = nearestConstructorMember.getMember();
  		
  		Class<?> expectedTypes[] = constructor.getParameterTypes();
  		Object[] castedArgs = HostedJavaMethod.castArgs(expectedTypes, args);
  		
  		try {
  			Object newInstance = constructor.newInstance(castedArgs);
  			newInstance = wrapObject(newInstance);
  			
  			if (newInstance instanceof Scriptable) {
  				result = (Scriptable)newInstance;
  			}
  			
  		} catch (Exception e) {
  			throw new UnknownException("Unable to construct object " + nearestConstructorMember.getName(), e);
  		}
  		
  		
  		return result;
  	}
  	
  	@Override
  	public Object get(int index, Scriptable start) {		
  		Object object;
  		
  		object = super.get(index, start);
  		object = (object == Scriptable.NOT_FOUND)? objectGetterGet(index) : object;
  		
  		return finalizeGet(object);
  	}
  	
  	@Override
  	public Object get(String name, Scriptable start) {
  		Object object;
  		
  		object = super.get(name, start);
  		object = (object == Scriptable.NOT_FOUND)? hostGet(name) : object;
  		object = (object == Scriptable.NOT_FOUND)? objectGetterGet(name) : object;
  		
  		return finalizeGet(object);
  	}
  		
  	@Override
  	public void put(String name, Scriptable start, Object value) {
  		if (objectMembers.hasMemberWithName(name)) {
  			hostPut(name, value);
  		} else {
  			super.put(name, start, value);
  		}
  	}
  	
  	@Override
  	public void delete(String name) {
  		if (objectMembers.hasMemberWithName(name)) {
  			hostDelete(name);
  		} else {
  			super.delete(name);
  		}
  	}
  	
  	@Override
  	public boolean has(String name, Scriptable start) {
  		boolean hasProperty = super.has(name, start);
  				
  		if (hasProperty && name.equals(ObjectGetter.METHOD_NAME)) {
  			return hasNonObjectGetterGet;
  		}
  		
  		return (hasProperty)? true : objectMembers.hasMemberWithName(name);
  	}
  	
  	@Override
  	public Object[] getIds() {
  		Object[] superIds = super.getAllIds();
  		return getIds(objectMembers, superIds);
  	}
  		
  	@Override
  	public Object unwrap() {
  		if (object instanceof com.jsen.core.Wrapper) {
  			return ((com.jsen.core.Wrapper<?>)object).unwrap();
  		}
  		return object;
  	}
  	
  	@Override
  	public String toString() {
  		return object.toString();
  	}
  
  	/**
  	 * Wraps the given object.
  	 * 
  	 * @param object Object to be wrapped.
  	 * @return Wrapped passed object.
  	 */
  