/** * 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; } } } }
/** * Initializes global top level scope. * * @return New top level scope. */ protected TopLevel initializeTopLevel() { @SuppressWarnings("unchecked") Object object = (scriptSettings != null)? ((GlobalObjectScriptSettings<GlobalObject>)scriptSettings).getGlobalObject() : null; if (object == null) { TopLevel topLevel = new TopLevel(); Context cx = enterContext(); try { cx.initStandardObjects(topLevel, true); } finally { exitContext(); } return topLevel; } return new ObjectTopLevel(object, this); }
/** * Initializes global top level scope. * * @return New top level scope. */ protected TopLevel initializeTopLevel() { Object object = (scriptSettings != null)? scriptSettings.getGlobalObject() : null; if (object == null) { TopLevel topLevel = new TopLevel(); Context cx = enterContext(); try { cx.initStandardObjects(topLevel, true); } finally { exitContext(); } return topLevel; } return new ObjectTopLevel(object, this); }
/** * 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); }
@Override public BrowserScriptEngine getScriptEngineProtected(final Object object) { return new WindowJavaScriptEngine(null, null, new CollectionsContextFactory()) { @Override protected TopLevel initializeTopLevel() { return new ObjectTopLevel(object, this); } @Override protected ClassMembersResolverFactory initializeClassMembersResolverFactory() { return new DefaultClassMembersResolverFactory(); } }; }
@Override public BrowserScriptEngine getScriptEngineProtected(final Object object) { return new WindowJavaScriptEngine(this, null) { @Override protected TopLevel initializeTopLevel() { return new ObjectTopLevel(object, this); } }; }
@Override public BrowserScriptEngine getScriptEngineProtected(final Object object) { return new WindowJavaScriptEngine(null, null, new DefaultContextFactory()) { @Override protected TopLevel initializeTopLevel() { return new ObjectTopLevel(object, this); } @Override protected ClassMembersResolverFactory initializeClassMembersResolverFactory() { return new DefaultClassMembersResolverFactory(); } }; }
NativeRegExp(Scriptable scope, RECompiled regexpCompiled) { this.re = regexpCompiled; this.lastIndex = 0d; ScriptRuntime.setBuiltinProtoAndParent(this, scope, TopLevel.Builtins.RegExp); }
NativeRegExp(Scriptable scope, Object regexpCompiled) { this.re = (RECompiled)regexpCompiled; this.lastIndex = 0; ScriptRuntime.setBuiltinProtoAndParent(this, scope, TopLevel.Builtins.RegExp); }
NativeRegExp(Scriptable scope, RECompiled regexpCompiled) { this.re = regexpCompiled; this.lastIndex = 0; ScriptRuntime.setBuiltinProtoAndParent(this, scope, TopLevel.Builtins.RegExp); }