Package net.sourceforge.htmlunit.corejs.javascript

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


    @Override
    public Scriptable wrapAsJavaObject(final Context context,
            final Scriptable scope, final Object javaObject, final Class< ? > staticType) {

        // TODO: should depend on the js configuration file
        final Scriptable resp;
        if (NodeList.class.equals(staticType)
                || NamedNodeMap.class.equals(staticType)) {
            resp = new ScriptableWrapper(scope, javaObject, staticType);
        }
        else {
View Full Code Here


            final String line = getFirstLine(cx);
            final String source = getSourceName(cx);
            sb.append(source).append(":").append(line).append(" ");

            Scriptable parent = activation.getParentScope();
            while (parent != null) {
                sb.append("   ");
                parent = parent.getParentScope();
            }
            final String functionName = getFunctionName(thisObj);
            sb.append(functionName).append("(");
            final int nbParams = functionOrScript_.getParamCount();
            for (int i = 0; i < nbParams; i++) {
View Full Code Here

            // on our SimpleScriptable we need to avoid looking at the properties we have defined => TODO: improve it
            if (thisObj instanceof SimpleScriptable) {
                return "[anonymous]";
            }

            Scriptable obj = thisObj;
            while (obj != null) {
                for (final Object id : obj.getIds()) {
                    if (id instanceof String) {
                        final String s = (String) id;
                        if (obj instanceof ScriptableObject) {
                            Object o = ((ScriptableObject) obj).getGetterOrSetter(s, 0, false);
                            if (o == null) {
                                o = ((ScriptableObject) obj).getGetterOrSetter(s, 0, true);
                                if (o != null && o instanceof Callable) {
                                    return "__defineSetter__ " + s;
                                }
                            }
                            else if (o instanceof Callable) {
                                return "__defineGetter__ " + s;
                            }
                        }
                        final Object o = obj.get(s, obj);
                        if (o instanceof NativeFunction) {
                            final NativeFunction f = (NativeFunction) o;
                            if (f.getDebuggableView() == this.functionOrScript_) {
                                return s;
                            }
                        }
                    }
                }
                obj = obj.getPrototype();
            }
            // Unable to intuit a name -- doh!
            return "[anonymous]";
        }
        // Just a script -- no function name.
View Full Code Here

        }
        throw new ParseException("Empty JSON string");
    }

    private Object readObject() throws ParseException {
        Scriptable object = cx.newObject(scope);
        String id;
        Object value;
        boolean needsComma = false;
        consumeWhitespace();
        while (pos < length) {
            char c = src.charAt(pos++);
            switch(c) {
                case '}':
                    return object;
                case ',':
                    if (!needsComma) {
                        throw new ParseException("Unexpected comma in object literal");
                    }
                    needsComma = false;
                    break;
                case '"':
                    if (needsComma) {
                        throw new ParseException("Missing comma in object literal");
                    }
                    id = readString();
                    consume(':');
                    value = readValue();

                    double d = ScriptRuntime.toNumber(id);
                    int index = (int) d;
                    if (d != index) {
                      object.put(id, object, value);
                    } else {
                      object.put(index, object, value);
                    }

                    needsComma = true;
                    break;
                default:
View Full Code Here

        }
        return super.get(name, start);
    }

    private static Scriptable getTopScope(final Scriptable s) {
        Scriptable top = s;
        while (top != null && top.getParentScope() != null) {
            top = top.getParentScope();
        }
        return top;
    }
View Full Code Here

                break;
            m--;
        }
        String namesAndDots = buffer.substring(m+1, cursor);
        String[] names = namesAndDots.split("\\.", -1);
        Scriptable obj = this.global;
        for (int i=0; i < names.length - 1; i++) {
            Object val = obj.get(names[i], global);
            if (val instanceof Scriptable)
                obj = (Scriptable) val;
            else {
                return buffer.length(); // no matches
            }
        }
        Object[] ids = (obj instanceof ScriptableObject)
                       ? ((ScriptableObject)obj).getAllIds()
                       : obj.getIds();
        String lastPart = names[names.length-1];
        for (int i=0; i < ids.length; i++) {
            if (!(ids[i] instanceof String))
                continue;
            String id = (String)ids[i];
            if (id.startsWith(lastPart)) {
                if (obj.get(id, obj) instanceof Function)
                    id += "(";
                candidates.add(id);
            }
        }
        return buffer.length() - lastPart.length();
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 (String file: fileList) {
            processSource(cx, file);
View Full Code Here

        /**
         * Performs the download and calls the callback method.
         */
        public void run() {
            final WebClient client = getWindow().getWebWindow().getWebClient();
            final Scriptable scope = callback_.getParentScope();
            final WebRequestSettings settings = new WebRequestSettings(url_);
            try {
                final WebResponse webResponse = client.loadWebResponse(settings);
                final String content = webResponse.getContentAsString();
                LOG.debug("Downloaded content: " + StringUtils.abbreviate(content, 512));
View Full Code Here

            LOG.debug("Property \"" + name + "\" evaluated (by name) to " + array + " with "
                    + subElements.size() + " elements");
            return array;
        }
        else if (subElements.size() == 1) {
            final Scriptable singleResult = getScriptableForElement(subElements.get(0));
            LOG.debug("Property \"" + name + "\" evaluated (by name) to " + singleResult);
            return singleResult;
        }

        // Nothing was found.
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.