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

The following examples show how to use net.sourceforge.htmlunit.corejs.javascript.ScriptableObject#hasProperty() . 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: HTMLOptionsCollection.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * <p>If IE is emulated, and this class does not have the specified property, and the owning
 * select *does* have the specified property, this method delegates the call to the parent
 * select element.</p>
 *
 * @param name {@inheritDoc}
 * @param start {@inheritDoc}
 * @param value {@inheritDoc}
 */
@Override
public void put(final String name, final Scriptable start, final Object value) {
    if (htmlSelect_ == null) {
        // This object hasn't been initialized; it's probably being used as a prototype.
        // Just pretend we didn't even see this invocation and let Rhino handle it.
        super.put(name, start, value);
        return;
    }

    final HTMLSelectElement parent = htmlSelect_.getScriptableObject();

    if (!has(name, start) && ScriptableObject.hasProperty(parent, name)) {
        ScriptableObject.putProperty(parent, name, value);
    }
    else {
        super.put(name, start, value);
    }
}
 
Example 2
Source File: HTMLOptionsCollection.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
/**
 * <p>If IE is emulated, and this class does not have the specified property, and the owning
 * select *does* have the specified property, this method delegates the call to the parent
 * select element.</p>
 *
 * @param name {@inheritDoc}
 * @param start {@inheritDoc}
 * @param value {@inheritDoc}
 */
@Override
public void put(final String name, final Scriptable start, final Object value) {
    if (htmlSelect_ == null) {
        // This object hasn't been initialized; it's probably being used as a prototype.
        // Just pretend we didn't even see this invocation and let Rhino handle it.
        super.put(name, start, value);
        return;
    }

    final HTMLSelectElement parent = (HTMLSelectElement) htmlSelect_.getScriptableObject();

    if (!has(name, start) && ScriptableObject.hasProperty(parent, name)) {
        ScriptableObject.putProperty(parent, name, value);
    }
    else {
        super.put(name, start, value);
    }
}
 
Example 3
Source File: Attr.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Returns {@code true} if the attribute is a custom property.
 * @return {@code true} if the attribute is a custom property
 */
@JsxGetter(IE)
public boolean isExpando() {
    final Object owner = getOwnerElement();
    if (null == owner) {
        return false;
    }
    return !ScriptableObject.hasProperty((Scriptable) owner, getName());
}
 
Example 4
Source File: MessageEvent.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes an event object.
 * @param type the event type
 * @param canBubble can the event bubble
 * @param cancelable can the event be canceled
 * @param data the message
 * @param origin the scheme, hostname and port of the document that caused the event
 * @param lastEventId the identifier of the last event
 * @param source the window object that contains the document that caused the event
 * @param ports the message ports
 */
@JsxFunction
public void initMessageEvent(
        final String type,
        final boolean canBubble,
        final boolean cancelable,
        final Object data,
        final String origin,
        final String lastEventId,
        final Window source,
        final Object ports) {
    initEvent(type, canBubble, cancelable);
    data_ = data;
    origin_ = origin;
    lastEventId_ = lastEventId;
    source_ = source;

    if (Undefined.isUndefined(ports)
        || ports instanceof NativeArray
        || (ports instanceof Scriptable && ScriptableObject.hasProperty((Scriptable) ports, "length"))) {
        ports_ = ports;
    }
    else {
        throw ScriptRuntime.typeError(
                "Argument 8 of MessageEvent.initMessageEvent can't be converted to a sequence.");
    }
}
 
Example 5
Source File: Attr.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns {@code true} if the attribute is a custom property.
 * @return {@code true} if the attribute is a custom property
 */
@JsxGetter(IE)
public boolean isExpando() {
    final Object owner = getOwnerElement();
    if (null == owner) {
        return false;
    }
    return !ScriptableObject.hasProperty((Scriptable) owner, getName());
}
 
Example 6
Source File: Reflect.java    From htmlunit with Apache License 2.0 2 votes vote down vote up
/**
 * The static Reflect.has() method works like the in operator as a function.
 *
 * @param target The target object in which to look for the property.
 * @param propertyKey The name of the property to check.
 * @return true or false
 */
@JsxStaticFunction
public boolean has(final Scriptable target, final String propertyKey) {
    return ScriptableObject.hasProperty(target, propertyKey);
}
 
Example 7
Source File: Reflect.java    From HtmlUnit-Android with Apache License 2.0 2 votes vote down vote up
/**
 * The static Reflect.has() method works like the in operator as a function.
 *
 * @param target The target object in which to look for the property.
 * @param propertyKey The name of the property to check.
 * @return true or false
 */
@JsxStaticFunction
public boolean has(final Scriptable target, final String propertyKey) {
    return ScriptableObject.hasProperty(target, propertyKey);
}