Search in sources :

Example 1 with ConstantInfo

use of com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration.ConstantInfo in project htmlunit by HtmlUnit.

the class HostConstantsTest method getExpectedString.

private String getExpectedString() throws Exception {
    if (host_.endsWith("Array") || "Image".equals(host_) || "Option".equals(host_)) {
        return "";
    }
    if ("Error".equals(host_) && getBrowserVersion().hasFeature(JS_ERROR_STACK_TRACE_LIMIT)) {
        return "stackTraceLimit:10";
    }
    final JavaScriptConfiguration javaScriptConfig = JavaScriptConfiguration.getInstance(getBrowserVersion());
    final List<String> constants = new ArrayList<>();
    ClassConfiguration classConfig = javaScriptConfig.getClassConfiguration(host_);
    boolean first = true;
    while (classConfig != null) {
        if (first && !classConfig.isJsObject()) {
            break;
        }
        if (first || classConfig.getJsConstructor() != null) {
            final List<ConstantInfo> constantInfos = classConfig.getConstants();
            if (constantInfos != null) {
                for (final ConstantInfo constantInfo : constantInfos) {
                    constants.add(constantInfo.getName() + ":" + constantInfo.getValue());
                }
            }
        }
        classConfig = javaScriptConfig.getClassConfiguration(classConfig.getExtendedClassName());
        first = false;
    }
    Collections.sort(constants, new Comparator<String>() {

        @Override
        public int compare(final String o1, final String o2) {
            return o1.substring(0, o1.indexOf(':')).compareTo(o2.substring(0, o2.indexOf(':')));
        }
    });
    final StringBuilder builder = new StringBuilder();
    for (final String key : constants) {
        builder.append(key).append(' ');
    }
    return builder.toString().trim();
}
Also used : ConstantInfo(com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration.ConstantInfo) ArrayList(java.util.ArrayList) JavaScriptConfiguration(com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration) ClassConfiguration(com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration)

Example 2 with ConstantInfo

use of com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration.ConstantInfo in project htmlunit by HtmlUnit.

the class RecursiveFunctionObject method get.

/**
 * {@inheritDoc}
 */
@Override
public Object get(final String name, final Scriptable start) {
    final String superFunctionName = super.getFunctionName();
    if ("prototype".equals(name)) {
        if ("Proxy".equals(superFunctionName)) {
            return NOT_FOUND;
        }
    }
    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) {
                final List<ConstantInfo> constants = config.getConstants();
                if (constants != null) {
                    for (final ConstantInfo constantInfo : constants) {
                        if (constantInfo.getName().equals(name)) {
                            value = ScriptableObject.getProperty((Scriptable) getPrototypeProperty(), name);
                            break;
                        }
                    }
                }
            }
            klass = klass.getSuperclass();
        }
    }
    return value;
}
Also used : ConstantInfo(com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration.ConstantInfo) ScriptableObject(net.sourceforge.htmlunit.corejs.javascript.ScriptableObject) FunctionObject(net.sourceforge.htmlunit.corejs.javascript.FunctionObject) Scriptable(net.sourceforge.htmlunit.corejs.javascript.Scriptable) BrowserVersion(com.gargoylesoftware.htmlunit.BrowserVersion) ClassConfiguration(com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration)

Aggregations

ClassConfiguration (com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration)2 ConstantInfo (com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration.ConstantInfo)2 BrowserVersion (com.gargoylesoftware.htmlunit.BrowserVersion)1 JavaScriptConfiguration (com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration)1 ArrayList (java.util.ArrayList)1 FunctionObject (net.sourceforge.htmlunit.corejs.javascript.FunctionObject)1 Scriptable (net.sourceforge.htmlunit.corejs.javascript.Scriptable)1 ScriptableObject (net.sourceforge.htmlunit.corejs.javascript.ScriptableObject)1