Package com.gargoylesoftware.htmlunit.javascript

Examples of com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$FallbackCaller


     * When we deserialize, re-initializie transient fields.
     */
    private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
        in.defaultReadObject();
        webConnection_ = new HttpWebConnection(this);
        scriptEngine_ = new JavaScriptEngine(this);
    }
View Full Code Here


        if (stateChangeHandler_ != null && (ie || async_)) {
            if (context == null) {
                context = Context.getCurrentContext();
            }
            final Scriptable scope = stateChangeHandler_.getParentScope();
            final JavaScriptEngine jsEngine = containingPage_.getWebClient().getJavaScriptEngine();

            final int nbExecutions;
            if (async_ && STATE_LOADING == state) {
                // quite strange but IE and Mozilla seem both to fire state loading twice
                // in async mode (at least with HTML of the unit tests)
                nbExecutions = 2;
            }
            else {
                nbExecutions = 1;
            }

            final Scriptable thisValue;
            if (getBrowserVersion().hasFeature(BrowserVersionFeatures.XMLHTTPREQUEST_HANDLER_THIS_IS_FUNCTION)) {
                thisValue = stateChangeHandler_;
            }
            else {
                thisValue = this;
            }
            for (int i = 0; i < nbExecutions; i++) {
                LOG.debug("Calling onreadystatechange handler for state " + state);
                jsEngine.callFunction(containingPage_, stateChangeHandler_, context,
                        scope, thisValue, ArrayUtils.EMPTY_OBJECT_ARRAY);
                LOG.debug("onreadystatechange handler: " + context.decompileFunction(stateChangeHandler_, 4));
                LOG.debug("Calling onreadystatechange handler for state " + state + ". Done.");
            }
        }

        // Firefox has a separate onload handler, too.
        if (!ie && loadHandler_ != null && state == STATE_COMPLETED) {
            if (context == null) {
                context = Context.getCurrentContext();
            }
            final Scriptable scope = loadHandler_.getParentScope();
            final JavaScriptEngine jsEngine = containingPage_.getWebClient().getJavaScriptEngine();
            jsEngine.callFunction(containingPage_, loadHandler_, context, scope, this, ArrayUtils.EMPTY_OBJECT_ARRAY);
        }
    }
View Full Code Here

        if (errorHandler_ != null && !getBrowserVersion().isIE()) {
            if (context == null) {
                context = Context.getCurrentContext();
            }
            final Scriptable scope = errorHandler_.getParentScope();
            final JavaScriptEngine jsEngine = containingPage_.getWebClient().getJavaScriptEngine();

            LOG.debug("Calling onerror handler");
            jsEngine.callFunction(containingPage_, errorHandler_, context, this, scope, ArrayUtils.EMPTY_OBJECT_ARRAY);
            LOG.debug("onerror handler: " + context.decompileFunction(errorHandler_, 4));
            LOG.debug("Calling onerror handler done.");
        }
    }
View Full Code Here

                    executeScriptIfNeeded(true);
                }
            }
        };
        if (postponed && getTextContent().length() == 0) {
            final JavaScriptEngine engine = getPage().getWebClient().getJavaScriptEngine();
            engine.addPostponedAction(action);
        }
        else {
            try {
                action.execute();
            }
View Full Code Here

        if (isStateUpdateFirst()) {
            doClickAction();
            stateUpdated = true;
        }

        final JavaScriptEngine jsEngine = page.getWebClient().getJavaScriptEngine();
        jsEngine.holdPosponedActions();
        final ScriptResult scriptResult = fireEvent(event);

        final boolean pageAlreadyChanged = contentPage != page.getEnclosingWindow().getEnclosedPage();
        if (!pageAlreadyChanged && !stateUpdated && !event.isAborted(scriptResult)) {
            doClickAction();
        }
        jsEngine.processPostponedActions();

        return (P) getPage().getWebClient().getCurrentWindow().getEnclosedPage();
    }
View Full Code Here

        if (!getWebClient().isJavaScriptEnabled()) {
            return new ScriptResult(null, this);
        }

        final JavaScriptEngine engine = getWebClient().getJavaScriptEngine();
        final Object result = engine.callFunction(this, function, thisObject, args, htmlElementScope);

        return new ScriptResult(result, getWebClient().getCurrentWindow().getEnclosedPage());
    }
View Full Code Here

                scriptEncoding = TextUtil.DEFAULT_CHARSET;
            }
        }

        final String scriptCode = response.getContentAsString(scriptEncoding);
        final JavaScriptEngine javaScriptEngine = client.getJavaScriptEngine();
        final Script script = javaScriptEngine.compile(this, scriptCode, url.toExternalForm(), 1);
        if (script != null) {
            cache.cacheIfPossible(request, response, script);
        }

        return script;
View Full Code Here



   public void testTreeItemLoaded() throws IOException, Exception
   {
      JavaScriptEngine jse = client.getContentPage().getEnclosingWindow().getWebClient().getJavaScriptEngine();

      log.info( "Script is "+ (jse.isScriptRunning()?"":"not") +" running." );

      Object jsTreeItem = jse.execute((HtmlPage) client.getContentPage(), "Tree.Item", "testTreeItemLoaded", 0);
      log.info( jsTreeItem.getClass().getName() );
      log.info( ObjectUtils.toString(jsTreeItem) );

      //org.mozilla.javascript.InterpretedFunction
      // extends NativeFunction implements Script
      // extends BaseFunction
      NativeFunction func = (NativeFunction) jsTreeItem;
      log.info( "Source: " + func.getEncodedSource() );



      // JS null object?
      jsTreeItem = jse.execute((HtmlPage) client.getContentPage(), "null", "testTreeItemLoaded", 0);
      if( null == jsTreeItem ){
        // True.
      }
      else {
        log.info( jsTreeItem.getClass().getName() );
View Full Code Here

      }
    }

    protected void setupWebClient(WebClient webClient) {
      if (developmentMode) {
        JavaScriptEngine hostedEngine = new HostedJavaScriptEngine(webClient,
            treeLogger);
        webClient.setJavaScriptEngine(hostedEngine);
      }
    }
View Full Code Here

      }
    }

    protected void setupWebClient(WebClient webClient) {
      if (developmentMode) {
        JavaScriptEngine hostedEngine = new HostedJavaScriptEngine(webClient,
            treeLogger);
        webClient.setJavaScriptEngine(hostedEngine);
      }
    }
View Full Code Here

TOP

Related Classes of com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$FallbackCaller

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.