/** * 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. */ 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); }
/** * Return the current WrapFactory, or null if none is defined. * @see WrapFactory * @since 1.5 Release 4 */ public final WrapFactory getWrapFactory() { if (wrapFactory == null) { wrapFactory = new WrapFactory(); } return wrapFactory; }
return obj; if (!isJavaPrimitiveWrap()) { if (obj instanceof String || obj instanceof Number || obj instanceof Boolean) return NativeJavaArray.wrap(scope, obj); return wrapAsJavaObject(cx, scope, obj, staticType);
@Override public Object get(int index, Scriptable start) { if (0 <= index && index < length) { Context cx = Context.getContext(); Object obj = Array.get(array, index); return cx.getWrapFactory().wrap(cx, this, obj, cls); } return Undefined.instance; }
return cx.getWrapFactory().wrapNewObject(cx, topLevel, instance);
/** @deprecated Use {@link Context#getWrapFactory()} together with calling {@link WrapFactory#wrap(Context, Scriptable, Object, Class)} */ public static Object wrap(Scriptable scope, Object obj, Class<?> staticType) { Context cx = Context.getContext(); return cx.getWrapFactory().wrap(cx, scope, obj, staticType); }
/** * Wraps some objects used by HtmlUnit (like {@link NodeList}), or delegates directly to the parent class. * {@inheritDoc} * @see WrapFactory#wrapAsJavaObject(Context, Scriptable, Object, Class) */ @Override public Scriptable wrapAsJavaObject(final Context context, final Scriptable scope, final Object javaObject, final Class<?> staticType) { // TODO: should depend on the js configuration file final Scriptable resp; if (NodeList.class.equals(staticType) || NamedNodeMap.class.equals(staticType)) { resp = new ScriptableWrapper(scope, javaObject, staticType); } else { resp = super.wrapAsJavaObject(context, scope, javaObject, staticType); } return resp; } }
private static Object doCall(Context cx, Scriptable scope, Scriptable thisObj, Function f, Object[] args, long argsToWrap) { // Wrap the rest of objects for (int i = 0; i != args.length; ++i) { if (0 != (argsToWrap & (1 << i))) { Object arg = args[i]; if (!(arg instanceof Scriptable)) { args[i] = cx.getWrapFactory().wrap(cx, scope, arg, null); } } } return f.call(cx, scope, thisObj, args); }
/** * Wraps some objects used by HtmlUnit (like {@link NodeList}), or delegates directly to the parent class. * {@inheritDoc} * @see WrapFactory#wrapAsJavaObject(Context, Scriptable, Object, Class) */ @Override public Scriptable wrapAsJavaObject(final Context context, final Scriptable scope, final Object javaObject, final Class< ? > staticType) { // TODO: should depend on the js configuration file final Scriptable resp; if (NodeList.class.equals(staticType) || NamedNodeMap.class.equals(staticType)) { resp = new ScriptableWrapper(scope, javaObject, staticType); } else { resp = super.wrapAsJavaObject(context, scope, javaObject, staticType); } return resp; } }
@Override public Object getDefaultValue(Class<?> hint) { if (hint == ScriptRuntime.FunctionClass) return this; Object rval; Class<?> type; try { rval = field.get(javaObject); type = field.getType(); } catch (IllegalAccessException accEx) { throw Context.reportRuntimeError1( "msg.java.internal.private", field.getName()); } Context cx = Context.getContext(); rval = cx.getWrapFactory().wrap(cx, this, rval, type); if (rval instanceof Scriptable) { rval = ((Scriptable) rval).getDefaultValue(hint); } return rval; }
/** * Wraps some objects used by HtmlUnit (like {@link NodeList}), or delegates directly to the parent class. * {@inheritDoc} * @see WrapFactory#wrapAsJavaObject(Context, Scriptable, Object, Class) */ @Override public Scriptable wrapAsJavaObject(final Context context, final Scriptable scope, final Object javaObject, final Class< ? > staticType) { // TODO: should depend on the js configuration file final Scriptable resp; if (NodeList.class.equals(staticType) || NamedNodeMap.class.equals(staticType)) { resp = new ScriptableWrapper(scope, javaObject, staticType); } else { resp = super.wrapAsJavaObject(context, scope, javaObject, staticType); } return resp; } }
} else { Context cx = Context.getContext(); return cx.getWrapFactory().wrap(cx, scope, value, null);
/** * Wraps some objects used by HtmlUnit (like {@link NodeList}), or delegates directly to the parent class. * {@inheritDoc} * @see WrapFactory#wrapAsJavaObject(Context, Scriptable, Object, Class) */ @Override public Scriptable wrapAsJavaObject(final Context context, final Scriptable scope, final Object javaObject, final Class< ? > staticType) { // TODO: should depend on the js configuration file final Scriptable resp; if (NodeList.class.equals(staticType) || NamedNodeMap.class.equals(staticType)) { resp = new ScriptableWrapper(scope, javaObject, staticType); } else { resp = super.wrapAsJavaObject(context, scope, javaObject, staticType); } return resp; } }
Object invokeImpl(Context cx, Object target, Scriptable topScope, Method method, Object[] args) { int N = (args == null) ? 0 : args.length; Callable function = (Callable)target; Scriptable thisObj = topScope; Object[] jsargs = new Object[N + 1]; jsargs[N] = method.getName(); if (N != 0) { WrapFactory wf = cx.getWrapFactory(); for (int i = 0; i != N; ++i) { jsargs[i] = wf.wrap(cx, topScope, args[i], null); } } Object result = function.call(cx, topScope, thisObj, jsargs); Class<?> javaResultType = method.getReturnType(); if (javaResultType == Void.TYPE) { result = null; } else { result = Context.jsToJava(result, javaResultType); } return result; } }
/** * Wraps some objects used by HtmlUnit (like {@link NodeList}), or delegates directly to the parent class. * {@inheritDoc} * @see WrapFactory#wrapAsJavaObject(Context, Scriptable, Object, Class) */ @Override public Scriptable wrapAsJavaObject(final Context context, final Scriptable scope, final Object javaObject, final Class<?> staticType) { // TODO: should depend on the js configuration file final Scriptable resp; if (NodeList.class.equals(staticType) || NamedNodeMap.class.equals(staticType)) { resp = new ScriptableWrapper(scope, javaObject, staticType); } else { resp = super.wrapAsJavaObject(context, scope, javaObject, staticType); } return resp; } }
return cx.getWrapFactory().wrap(cx, scope, rval, type);
Context cx = Context.getContext(); Scriptable scope = ScriptableObject.getTopLevelScope(start); return cx.getWrapFactory().wrap(cx, scope, javaObject, ScriptRuntime.ClassClass);
Object wrapped = cx.getWrapFactory().wrap(cx, scope, val, null); if (wrapped instanceof Scriptable) return (Scriptable) wrapped;
Object wrapped = cx.getWrapFactory().wrap(cx, scope, retval, staticType); if (debug) {