Package net.sourceforge.htmlunit.corejs.javascript

Examples of net.sourceforge.htmlunit.corejs.javascript.Scriptable


  public void setSealedStdLib( boolean value ) {
    sealedStdLib = value;
  }

  private static Global getInstance( Function function ) {
    Scriptable scope = scopes.get(function.getParentScope().getClassName());

    if ( !( scope instanceof Global ) )
      throw reportRuntimeError( "msg.shell.bad.function.scope",
              String.valueOf( scope ) );
    return (Global) scope;
View Full Code Here


   public Environment(ScriptableObject scope) {
       setParentScope(scope);
       Object ctor = ScriptRuntime.getTopLevelProp(scope, "Environment");
       if (ctor != null && ctor instanceof Scriptable) {
           Scriptable s = (Scriptable) ctor;
           setPrototype((Scriptable) s.get("prototype", s));
       }
   }
View Full Code Here

       // define "arguments" array in the top-level object:
       // need to allocate new array since newArray requires instances
       // of exactly Object[], not ObjectSubclass[]
       Object[] array = new Object[args.length];
       System.arraycopy(args, 0, array, 0, args.length);
       Scriptable argsObj = cx.newArray(global, array);
       global.defineProperty("arguments", argsObj,
                             ScriptableObject.DONTENUM);

       for (int i=0; i < fileList.size(); i++) {
           processSource(cx, (String) fileList.elementAt(i));
View Full Code Here

  }

  @Override
  public void freeValue(BrowserChannelClient channel, int[] ids) {
    for (int id : ids) {
      Scriptable scriptable = refToJsObject.remove(id);
      if (scriptable != null) {
        jsObjectToRef.remove(scriptable);
      }
    }
  }
View Full Code Here

        return value.getString();
      case JAVA_OBJECT:
        JavaObjectRef javaRef = value.getJavaObject();
        return JavaObject.getOrCreateJavaObject(javaRef, sessionData, jsContext);
      case JS_OBJECT:
        Scriptable scriptable = refToJsObject.get(value.getJsObject().getRefid());
        assert scriptable != null;
        return scriptable;
      case UNDEFINED:
        return Undefined.instance;
    }
View Full Code Here

     * @param javaScriptClass the host class
     * @return the prototype
     */
    @SuppressWarnings("unchecked")
    protected Scriptable getPrototype(final Class< ? extends SimpleScriptable> javaScriptClass) {
        final Scriptable prototype = getWindow().getPrototype(javaScriptClass);
        if (prototype == null && javaScriptClass != SimpleScriptable.class) {
            return getPrototype((Class< ? extends SimpleScriptable>) javaScriptClass.getSuperclass());
        }
        return prototype;
    }
View Full Code Here

     * @param s the JavaScript object whose associated window is to be returned
     * @return the window associated with the specified JavaScript object
     * @throws RuntimeException if the window cannot be found, which should never occur
     */
    protected static Window getWindow(final Scriptable s) throws RuntimeException {
        final Scriptable top = ScriptableObject.getTopLevelScope(s);
        if (top instanceof Window) {
            return (Window) top;
        }
        throw new RuntimeException("Unable to find window associated with " + s);
    }
View Full Code Here

     * Sets case sensitivity of all properties of this scriptable.
     * @param caseSensitive case sensitive or no
     */
    public void setCaseSensitive(final boolean caseSensitive) {
        caseSensitive_ = caseSensitive;
        final Scriptable prototype = getPrototype();
        if (prototype instanceof SimpleScriptable) {
            ((SimpleScriptable) prototype).setCaseSensitive(caseSensitive);
        }
    }
View Full Code Here

        final boolean ie = getBrowserVersion().isIE();
        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

    private void processError(Context context) {
        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));
View Full Code Here

TOP

Related Classes of net.sourceforge.htmlunit.corejs.javascript.Scriptable

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.