Java Code Examples for net.sourceforge.htmlunit.corejs.javascript.ScriptableObject#getProperty()

The following examples show how to use net.sourceforge.htmlunit.corejs.javascript.ScriptableObject#getProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HTMLFormElement.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Object call(final Context cx, final Scriptable scope, final Scriptable thisObj, final Object[] args) {
    if (!getBrowserVersion().hasFeature(JS_FORM_USABLE_AS_FUNCTION)) {
        throw Context.reportRuntimeError("Not a function.");
    }
    if (args.length > 0) {
        final Object arg = args[0];
        if (arg instanceof String) {
            return ScriptableObject.getProperty(this, (String) arg);
        }
        else if (arg instanceof Number) {
            return ScriptableObject.getProperty(this, ((Number) arg).intValue());
        }
    }
    return Undefined.instance;
}
 
Example 2
Source File: HTMLFormElement.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Object call(final Context cx, final Scriptable scope, final Scriptable thisObj, final Object[] args) {
    if (!getBrowserVersion().hasFeature(JS_FORM_USABLE_AS_FUNCTION)) {
        throw Context.reportRuntimeError("Not a function.");
    }
    if (args.length > 0) {
        final Object arg = args[0];
        if (arg instanceof String) {
            return ScriptableObject.getProperty(this, (String) arg);
        }
        else if (arg instanceof Number) {
            return ScriptableObject.getProperty(this, ((Number) arg).intValue());
        }
    }
    return Undefined.instance;
}
 
Example 3
Source File: RecursiveFunctionObject.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Object get(final String name, final Scriptable start) {
    final String superFunctionName = super.getFunctionName();
    if ("prototype".equals(name)) {
        switch (superFunctionName) {
            case "CSS":
            case "Proxy":
                return NOT_FOUND;

            default:
        }
    }
    Object value = super.get(name, start);

    if (value == NOT_FOUND && !"Image".equals(superFunctionName) && !"Option".equals(superFunctionName)
            && (!"WebGLContextEvent".equals(superFunctionName)
                    || getBrowserVersion().hasFeature(JS_WEBGL_CONTEXT_EVENT_CONSTANTS))) {
        Class<?> klass = getPrototypeProperty().getClass();

        final BrowserVersion browserVersion = getBrowserVersion();
        while (value == NOT_FOUND && HtmlUnitScriptable.class.isAssignableFrom(klass)) {
            final ClassConfiguration config = AbstractJavaScriptConfiguration.getClassConfiguration(
                    klass.asSubclass(HtmlUnitScriptable.class), browserVersion);
            if (config != null) {
                for (final ConstantInfo constantInfo : config.getConstants()) {
                    if (constantInfo.getName().equals(name)) {
                        value = ScriptableObject.getProperty((Scriptable) getPrototypeProperty(), name);
                        break;
                    }
                }
            }
            klass = klass.getSuperclass();
        }
    }
    return value;
}
 
Example 4
Source File: RecursiveFunctionObject.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Object get(final String name, final Scriptable start) {
    final String superFunctionName = super.getFunctionName();
    if ("prototype".equals(name)) {
        switch (superFunctionName) {
            case "CSS":
            case "Proxy":
                return NOT_FOUND;

            default:
        }
    }
    Object value = super.get(name, start);

    if (value == NOT_FOUND && !"Image".equals(superFunctionName) && !"Option".equals(superFunctionName)
            && (!"WebGLContextEvent".equals(superFunctionName)
                    || getBrowserVersion().hasFeature(JS_WEBGL_CONTEXT_EVENT_CONSTANTS))) {
        Class<?> klass = getPrototypeProperty().getClass();

        final BrowserVersion browserVersion = getBrowserVersion();
        while (value == NOT_FOUND && HtmlUnitScriptable.class.isAssignableFrom(klass)) {
            final ClassConfiguration config = AbstractJavaScriptConfiguration.getClassConfiguration(
                    klass.asSubclass(HtmlUnitScriptable.class), browserVersion);
            if (config != null) {
                for (final ConstantInfo constantInfo : config.getConstants()) {
                    if (constantInfo.getName().equals(name)) {
                        value = ScriptableObject.getProperty((Scriptable) getPrototypeProperty(), name);
                        break;
                    }
                }
            }
            klass = klass.getSuperclass();
        }
    }
    return value;
}
 
Example 5
Source File: ArrayBufferViewBase.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Sets multiple values in the typed array, reading input values from a specified array.
 * @param sourceArray the source array
 * @param offset the offset into the target array at which to begin writing values from the source one
 */
@JsxFunction
public void set(final ScriptableObject sourceArray, final int offset) {
    final Object lengthProperty = ScriptableObject.getProperty(sourceArray, "length");
    if (lengthProperty instanceof Number) {
        final int length = ((Number) lengthProperty).intValue();
        for (int i = 0; i < length; i++) {
            put(i + offset, this, sourceArray.get(i));
        }
    }
}
 
Example 6
Source File: Map.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Replacement of {@link NativeArray#toArray()}.
 */
private static Object[] toArray(final NativeArray narray) {
    final long longLen = narray.getLength();
    if (longLen > Integer.MAX_VALUE) {
        throw new IllegalStateException();
    }

    final int len = (int) longLen;
    final Object[] arr = new Object[len];
    for (int i = 0; i < len; i++) {
        arr[i] = ScriptableObject.getProperty(narray, i);
    }
    return arr;
}
 
Example 7
Source File: Map.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Object get(final String name, final Scriptable start) {
    // A hack to handle Rhino not supporting "get(Object object, Scriptable start)"
    if (name.equals(Symbol.ITERATOR_STRING)) {
        return ScriptableObject.getProperty(start, "entries");
    }
    return super.get(name, start);
}
 
Example 8
Source File: Set.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Object get(final String name, final Scriptable start) {
    // A hack to handle Rhino not supporting "get(Object object, Scriptable start)"
    if (name.equals(Symbol.ITERATOR_STRING)) {
        return ScriptableObject.getProperty(start, "values");
    }
    return super.get(name, start);
}
 
Example 9
Source File: WeakMap.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Replacement of {@link NativeArray#toArray()}.
 */
private static Object[] toArray(final NativeArray narray) {
    final long longLen = narray.getLength();
    if (longLen > Integer.MAX_VALUE) {
        throw new IllegalStateException();
    }

    final int len = (int) longLen;
    final Object[] arr = new Object[len];
    for (int i = 0; i < len; i++) {
        arr[i] = ScriptableObject.getProperty(narray, i);
    }
    return arr;
}