    private void init(final WebWindow webWindow, final Context context) throws Exception {
        final WebClient webClient = webWindow.getWebClient();
        final Map prototypes = new HashMap();
        final Map prototypesPerJSName = new HashMap();
        final Window window = new Window(this);
        final JavaScriptConfiguration jsConfig = JavaScriptConfiguration.getInstance(webClient.getBrowserVersion());
        context.initStandardObjects(window);
        StringPrimitivePrototypeBugFixer.installWorkaround(window);
        final Scriptable fallbackCaller = new ScriptableObject()
        {
            private static final long serialVersionUID = -7124423159070941606L;
            public Object get(final String name, final Scriptable start) {
                if (start instanceof ScriptableWithFallbackGetter) {
                    return ((ScriptableWithFallbackGetter) start).getWithFallback(name);
                }
                return NOT_FOUND;
            }
            public String getClassName() {
                return "htmlUnitHelper-fallbackCaller";
            }
        };
        ScriptableObject.getObjectPrototype(window).setPrototype(fallbackCaller);
        final Iterator it = jsConfig.keySet().iterator();
        while (it.hasNext()) {
            final String jsClassName = (String) it.next();
            final ClassConfiguration config = jsConfig.getClassConfiguration(jsClassName);
            final boolean isWindow = Window.class.getName().equals(config.getLinkedClass().getName());
            if (isWindow) {
                configureConstantsPropertiesAndFunctions(config, window);
            }
            else {
                final Scriptable prototype = configureClass(config, window);
                if (config.isJsObject()) {
                    prototypes.put(config.getLinkedClass(), prototype);
                    if (!getWebClient().getBrowserVersion().isIE()) {
                        final Scriptable obj = (Scriptable) config.getLinkedClass().newInstance();
                        obj.put("prototype", obj, prototype);
                        obj.setPrototype(prototype);
                        ScriptableObject.defineProperty(window,
                                config.getClassName(), obj, ScriptableObject.DONTENUM);
                    }
                }
                prototypesPerJSName.put(config.getClassName(), prototype);
            }
        }
        final Scriptable objectPrototype = ScriptableObject.getObjectPrototype(window);
        for (final Iterator iter = prototypesPerJSName.entrySet().iterator(); iter.hasNext();) {
            final Map.Entry entry = (Map.Entry) iter.next();
            final String name = (String) entry.getKey();
            final ClassConfiguration config = jsConfig.getClassConfiguration(name);
            final Scriptable prototype = (Scriptable) entry.getValue();
            if (!StringUtils.isEmpty(config.getExtendedClass())) {
                final Scriptable parentPrototype = (Scriptable) prototypesPerJSName.get(config.getExtendedClass());
                prototype.setPrototype(parentPrototype);
            }
            else {
                prototype.setPrototype(objectPrototype);
            }
        }
        final Class[] evalFnTypes = {String.class};
        final Member evalFn = Window.class.getMethod("custom_eval", evalFnTypes);
        final FunctionObject jsCustomEval = new FunctionObject("eval", evalFn, window);
        window.associateValue("custom_eval", jsCustomEval);
        for (final Iterator classnames = jsConfig.keySet().iterator(); classnames.hasNext();) {
            final String jsClassName = (String) classnames.next();
            final ClassConfiguration config = jsConfig.getClassConfiguration(jsClassName);
            final Method jsConstructor = config.getJsConstructor();
            if (jsConstructor != null) {
                final Scriptable prototype = (Scriptable) prototypesPerJSName.get(jsClassName);
                if (prototype != null) {
                    final FunctionObject jsCtor = new FunctionObject(jsClassName, jsConstructor, window);
                    jsCtor.addAsConstructor(window, prototype);
                }
            }
        }
        window.setPrototypes(prototypes);
        window.initialize(webWindow);
    }

    private void init(final WebWindow webWindow, final Context context) throws Exception {
        final WebClient webClient = webWindow.getWebClient();
        final Map prototypes = new HashMap();
        final Map prototypesPerJSName = new HashMap();
        final Window window = new Window(this);
        final JavaScriptConfiguration jsConfig = JavaScriptConfiguration.getInstance(webClient.getBrowserVersion());
        context.initStandardObjects(window);
        StringPrimitivePrototypeBugFixer.installWorkaround(window);
        final Scriptable fallbackCaller = new ScriptableObject()
        {
            private static final long serialVersionUID = -7124423159070941606L;
            public Object get(final String name, final Scriptable start) {
                if (start instanceof ScriptableWithFallbackGetter) {
                    return ((ScriptableWithFallbackGetter) start).getWithFallback(name);
                }
                return NOT_FOUND;
            }
            public String getClassName() {
                return "htmlUnitHelper-fallbackCaller";
            }
        };
        ScriptableObject.getObjectPrototype(window).setPrototype(fallbackCaller);
        final Iterator it = jsConfig.keySet().iterator();
        while (it.hasNext()) {
            final String jsClassName = (String) it.next();
            final ClassConfiguration config = jsConfig.getClassConfiguration(jsClassName);
            final boolean isWindow = Window.class.getName().equals(config.getLinkedClass().getName());
            if (isWindow) {
                configureConstantsPropertiesAndFunctions(config, window);
            }
            else {
                final Scriptable prototype = configureClass(config, window);
                if (config.isJsObject()) {
                    prototypes.put(config.getLinkedClass(), prototype);
                    if (!getWebClient().getBrowserVersion().isIE()) {
                        final Scriptable obj = (Scriptable) config.getLinkedClass().newInstance();
                        obj.put("prototype", obj, prototype);
                        obj.setPrototype(prototype);
                        obj.setParentScope(window);
                        ScriptableObject.defineProperty(window,
                                config.getClassName(), obj, ScriptableObject.DONTENUM);
                    }
                }
                prototypesPerJSName.put(config.getClassName(), prototype);
            }
        }
        final Scriptable objectPrototype = ScriptableObject.getObjectPrototype(window);
        for (final Iterator iter = prototypesPerJSName.entrySet().iterator(); iter.hasNext();) {
            final Map.Entry entry = (Map.Entry) iter.next();
            final String name = (String) entry.getKey();
            final ClassConfiguration config = jsConfig.getClassConfiguration(name);
            final Scriptable prototype = (Scriptable) entry.getValue();
            if (!StringUtils.isEmpty(config.getExtendedClass())) {
                final Scriptable parentPrototype = (Scriptable) prototypesPerJSName.get(config.getExtendedClass());
                prototype.setPrototype(parentPrototype);
            }
            else {
                prototype.setPrototype(objectPrototype);
            }
        }
        final Class[] evalFnTypes = {String.class};
        final Member evalFn = Window.class.getMethod("custom_eval", evalFnTypes);
        final FunctionObject jsCustomEval = new FunctionObject("eval", evalFn, window);
        window.associateValue("custom_eval", jsCustomEval);
        for (final Iterator classnames = jsConfig.keySet().iterator(); classnames.hasNext();) {
            final String jsClassName = (String) classnames.next();
            final ClassConfiguration config = jsConfig.getClassConfiguration(jsClassName);
            final Method jsConstructor = config.getJsConstructor();
            if (jsConstructor != null) {
                final Scriptable prototype = (Scriptable) prototypesPerJSName.get(jsClassName);
                if (prototype != null) {
                    final FunctionObject jsCtor = new FunctionObject(jsClassName, jsConstructor, window);
                    jsCtor.addAsConstructor(window, prototype);
                }
            }
        }
        window.setPrototypes(prototypes);
        window.initialize(webWindow);
    }
