@Override protected Object getInterfaceProxyHelper(ContextFactory cf, Class<?>[] interfaces) { // XXX: How to handle interfaces array withclasses from different // class loaders? Using cf.getApplicationClassLoader() ? ClassLoader loader = interfaces[0].getClassLoader(); Class<?> cl = Proxy.getProxyClass(loader, interfaces); Constructor<?> c; try { c = cl.getConstructor(new Class[] { InvocationHandler.class }); } catch (NoSuchMethodException ex) { // Should not happen throw Kit.initCause(new IllegalStateException(), ex); } return c; }
private static void initJavaPolicySecuritySupport() { Throwable exObj; try { Class<?> cl = Class.forName ("org.mozilla.javascript.tools.shell.JavaPolicySecurity"); securityImpl = (SecurityProxy)cl.newInstance(); SecurityController.initGlobal(securityImpl); return; } catch (ClassNotFoundException ex) { exObj = ex; } catch (IllegalAccessException ex) { exObj = ex; } catch (InstantiationException ex) { exObj = ex; } catch (LinkageError ex) { exObj = ex; } throw Kit.initCause(new IllegalStateException( "Can not load security support: "+exObj), exObj); }
/** * @deprecated * @see #jsToJava(Object, Class) * @throws IllegalArgumentException if the conversion cannot be performed. * Note that {@link #jsToJava(Object, Class)} throws * {@link EvaluatorException} instead. */ public static Object toType(Object value, Class<?> desiredType) throws IllegalArgumentException { try { return jsToJava(value, desiredType); } catch (EvaluatorException ex) { IllegalArgumentException ex2 = new IllegalArgumentException(ex.getMessage()); Kit.initCause(ex2, ex); throw ex2; } }
/** * @deprecated * @see ContextFactory#addListener(ContextFactory.Listener) * @see ContextFactory#getGlobal() */ public static void addContextListener(ContextListener listener) { // Special workaround for the debugger String DBG = "net.sourceforge.htmlunit.corejs.javascript.tools.debugger.Main"; if (DBG.equals(listener.getClass().getName())) { Class<?> cl = listener.getClass(); Class<?> factoryClass = Kit.classOrNull( "net.sourceforge.htmlunit.corejs.javascript.ContextFactory"); Class<?>[] sig = { factoryClass }; Object[] args = { ContextFactory.getGlobal() }; try { Method m = cl.getMethod("attachTo", sig); m.invoke(listener, args); } catch (Exception ex) { RuntimeException rex = new RuntimeException(); Kit.initCause(rex, ex); throw rex; } return; } ContextFactory.getGlobal().addListener(listener); }
/** * @see Context#throwAsScriptRuntimeEx(Throwable e) */ public WrappedException(Throwable exception) { super("Wrapped "+exception.toString()); this.exception = exception; Kit.initCause(this, exception); int[] linep = { 0 }; String sourceName = Context.getSourcePositionFromStack(linep); int lineNumber = linep[0]; if (sourceName != null) { initSourceName(sourceName); } if (lineNumber != 0) { initLineNumber(lineNumber); } // fix up the stack trace of chained exceptions for(Throwable t=getCause(); t!=null; t=t.getCause()) overwriteStackTrace(t); }