/** * 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; } } } }
/** * 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 = WindowJavaScriptEngine.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; } } } }
/** * Constructs new hosted Java method for given parent scope, of the passed object and with the passed overloaded function members. * * @param scope Scope to become the parent scope of this function. * @param object Object with the wrapped method. * @param objectFunctions Overloaded function members which should have the same name. */ public HostedJavaMethod(Scriptable scope, Object object, Set<? extends FunctionMember> objectFunctions) { super(objectFunctions.iterator().next().getMember().getName(), FUNCTION_METHOD, scope); this.object = object; this.objectFunctions = new HashSet<FunctionMember>(); this.objectFunctions.addAll(objectFunctions); TopLevel topLevel = JavaScriptEngine.getObjectTopLevel(scope); Scriptable builtinFunction = topLevel.getBuiltinCtor(Builtins.Function); setPrototype(builtinFunction); }
/** * Constructs new hosted Java method for given parent scope, of the passed object and with the passed overloaded function members. * * @param scope Scope to become the parent scope of this function. * @param object Object with the wrapped method. * @param objectFunctions Overloaded function members which should have the same name. */ public HostedJavaMethod(Scriptable scope, Object object, Set<? extends FunctionMember> objectFunctions) { super(objectFunctions.iterator().next().getMember().getName(), FUNCTION_METHOD, scope); this.object = object; this.objectFunctions = new HashSet<FunctionMember>(); this.objectFunctions.addAll(objectFunctions); TopLevel topLevel = WindowJavaScriptEngine.getObjectTopLevel(scope); Scriptable builtinFunction = topLevel.getBuiltinCtor(Builtins.Function); setPrototype(builtinFunction); }