private boolean isDom3Present() { Class<?> nodeClass = Kit.classOrNull("org.w3c.dom.Node"); if (nodeClass == null) return false; // Check to see whether DOM3 is present; use a new method defined in // DOM3 that is vital to our implementation try { nodeClass.getMethod("getUserData", new Class<?>[] { String.class }); return true; } catch (NoSuchMethodException e) { return false; } }
private RuntimeException codeBug() throws RuntimeException { throw Kit.codeBug("ts.cursor=" + ts.cursor + ", ts.tokenBeg=" + ts.tokenBeg + ", currentToken=" + currentToken); } }
@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; }
RegExpProxy getRegExpProxy() { if (regExpProxy == null) { Class<?> cl = Kit.classOrNull( "net.sourceforge.htmlunit.corejs.javascript.regexp.RegExpImpl"); if (cl != null) { regExpProxy = (RegExpProxy)Kit.newInstanceOrNull(cl); } } return regExpProxy; }
/** * @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); }
if (!(sourceReader == null ^ sourceString == null)) Kit.codeBug(); if (!(scope == null ^ returnFunction)) Kit.codeBug(); sourceString = Kit.readReader(sourceReader); sourceReader = null; returnFunction); if (debugger != null) { if (sourceString == null) Kit.codeBug(); if (bytecode instanceof DebuggableScript) { DebuggableScript dscript = (DebuggableScript)bytecode;
/** * Reads the file with the given name and returns its contents as a String. */ private String readFile(String fileName) { String text; try { Reader r = new FileReader(fileName); try { text = Kit.readReader(r); } finally { r.close(); } } catch (IOException ex) { MessageDialogWrapper.showMessageDialog(this, ex.getMessage(), "Error reading "+fileName, JOptionPane.ERROR_MESSAGE); text = null; } return text; }
private void firePropertyChangeImpl(Object listeners, String property, Object oldValue, Object newValue) { for (int i = 0; ; ++i) { Object l = Kit.getListener(listeners, i); if (l == null) break; if (l instanceof PropertyChangeListener) { PropertyChangeListener pcl = (PropertyChangeListener)l; pcl.propertyChange(new PropertyChangeEvent( this, property, oldValue, newValue)); } } }
/** * Register an object to receive notifications when a bound property * has changed * @see java.beans.PropertyChangeEvent * @see #removePropertyChangeListener(java.beans.PropertyChangeListener) * @param l the listener */ public final void addPropertyChangeListener(PropertyChangeListener l) { if (sealed) onSealedMutation(); propertyListeners = Kit.addListener(propertyListeners, l); }
static Evaluator createInterpreter() { return (Evaluator)Kit.newInstanceOrNull(interpreterClass); }
/** * Associate arbitrary application-specific value with this object. * Value can only be associated with the given object and key only once. * The method ignores any subsequent attempts to change the already * associated value. * <p> The associated values are not serialized. * @param key key object to select particular value. * @param value the value to associate * @return the passed value if the method is called first time for the * given key or old value for any subsequent calls. * @see #getAssociatedValue(Object key) */ public synchronized final Object associateValue(Object key, Object value) { if (value == null) throw new IllegalArgumentException(); Map<Object,Object> h = associatedValues; if (h == null) { h = new HashMap<Object,Object>(); associatedValues = h; } return Kit.initHash(h, key, value); }
data = Kit.readStream(is, capacityHint); } finally { if(is != null) {
Object key = Kit.makeHashKeyFromPair( COERCED_INTERFACE_KEY, type); Object old = so.getAssociatedValue(key);
private static VMBridge makeInstance() { String[] classNames = { "net.sourceforge.htmlunit.corejs.javascript.VMBridge_custom", "net.sourceforge.htmlunit.corejs.javascript.jdk15.VMBridge_jdk15", "net.sourceforge.htmlunit.corejs.javascript.jdk13.VMBridge_jdk13", "net.sourceforge.htmlunit.corejs.javascript.jdk11.VMBridge_jdk11", }; for (int i = 0; i != classNames.length; ++i) { String className = classNames[i]; Class<?> cl = Kit.classOrNull(className); if (cl != null) { VMBridge bridge = (VMBridge)Kit.newInstanceOrNull(cl); if (bridge != null) { return bridge; } } } throw new IllegalStateException("Failed to create VMBridge instance"); }
source = Kit.readReader(new InputStreamReader(is)); } finally { is.close();
protected void onContextReleased(Context cx) { Object listeners = this.listeners; for (int i = 0; ; ++i) { Listener l = (Listener)Kit.getListener(listeners, i); if (l == null) break; l.contextReleased(cx); } }
public final void addListener(Listener listener) { checkNotSealed(); synchronized (listenersLock) { if (disabledListening) { throw new IllegalStateException(); } listeners = Kit.addListener(listeners, listener); } }
private Evaluator createCompiler() { Evaluator result = null; if (optimizationLevel >= 0 && codegenClass != null) { result = (Evaluator)Kit.newInstanceOrNull(codegenClass); } if (result == null) { result = createInterpreter(); } return result; }
private static Class<?> findNestedClass(Class<?> parentClass, String name) { String nestedClassName = parentClass.getName() + '$' + name; ClassLoader loader = parentClass.getClassLoader(); if (loader == null) { // ALERT: if loader is null, nested class should be loaded // via system class loader which can be different from the // loader that brought Rhino classes that Class.forName() would // use, but ClassLoader.getSystemClassLoader() is Java 2 only return Kit.classOrNull(nestedClassName); } else { return Kit.classOrNull(loader, nestedClassName); } }