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

The following examples show how to use net.sourceforge.htmlunit.corejs.javascript.ScriptableObject#getTopLevelScope() . 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: SimpleScriptable.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the window that is the top scope for the specified object.
 * @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);
}
 
Example 2
Source File: Document.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the value of the {@code frames} property.
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms537459.aspx">MSDN documentation</a>
 * @return the live collection of frames contained by this document
 */
@JsxGetter(IE)
public Object getFrames() {
    if (ScriptableObject.getTopLevelScope(this) == null) {
        throw ScriptRuntime.constructError("Error", "Not implemented");
    }
    return getWindow().getFrames_js();
}
 
Example 3
Source File: DOMStringMap.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void put(final String name, final Scriptable start, final Object value) {
    if (!(ScriptableObject.getTopLevelScope(this) instanceof Window) || getWindow().getWebWindow() == null) {
        super.put(name, start, value);
    }
    else {
        final HtmlElement e = (HtmlElement) getDomNodeOrNull();
        if (e != null) {
            e.setAttribute("data-" + decamelize(name), Context.toString(value));
        }
    }
}
 
Example 4
Source File: SimpleScriptable.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the window that is the top scope for the specified object.
 * @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);
}
 
Example 5
Source File: Document.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the value of the {@code frames} property.
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms537459.aspx">MSDN documentation</a>
 * @return the live collection of frames contained by this document
 */
@JsxGetter(IE)
public Object getFrames() {
    if (ScriptableObject.getTopLevelScope(this) == null) {
        throw ScriptRuntime.constructError("Error", "Not implemented");
    }
    return getWindow().getFrames_js();
}
 
Example 6
Source File: DOMStringMap.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void put(final String name, final Scriptable start, final Object value) {
    if (!(ScriptableObject.getTopLevelScope(this) instanceof Window) || getWindow().getWebWindow() == null) {
        super.put(name, start, value);
    }
    else {
        final HtmlElement e = (HtmlElement) getDomNodeOrNull();
        if (e != null) {
            e.setAttribute("data-" + decamelize(name), Context.toString(value));
        }
    }
}