Search in sources :

Example 1 with PropertyInfo

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

the class JavaScriptEngine method configureProperties.

private static void configureProperties(final ClassConfiguration config, final ScriptableObject scriptable) {
    final Map<String, PropertyInfo> propertyMap = config.getPropertyMap();
    if (propertyMap != null) {
        for (final Entry<String, PropertyInfo> propertyEntry : propertyMap.entrySet()) {
            final PropertyInfo info = propertyEntry.getValue();
            final Method readMethod = info.getReadMethod();
            final Method writeMethod = info.getWriteMethod();
            scriptable.defineProperty(propertyEntry.getKey(), null, readMethod, writeMethod, ScriptableObject.EMPTY);
        }
    }
}
Also used : Method(java.lang.reflect.Method) PropertyInfo(com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration.PropertyInfo)

Example 2 with PropertyInfo

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

the class JavaScriptEngine method configureStaticProperties.

private static void configureStaticProperties(final ClassConfiguration config, final ScriptableObject scriptable) {
    final Map<String, PropertyInfo> staticPropertyMap = config.getStaticPropertyMap();
    if (staticPropertyMap != null) {
        for (final Entry<String, ClassConfiguration.PropertyInfo> propertyEntry : staticPropertyMap.entrySet()) {
            final String propertyName = propertyEntry.getKey();
            final Method readMethod = propertyEntry.getValue().getReadMethod();
            final Method writeMethod = propertyEntry.getValue().getWriteMethod();
            final int flag = ScriptableObject.EMPTY;
            scriptable.defineProperty(propertyName, null, readMethod, writeMethod, flag);
        }
    }
}
Also used : Method(java.lang.reflect.Method) PropertyInfo(com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration.PropertyInfo)

Example 3 with PropertyInfo

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

the class CSSStyleDeclarationTest method styleAttributes.

/**
 * Tests that all getters and setters {@link CSSStyleDeclaration} have correct browser support
 * as defined in {@link StyleAttributes}.
 *
 * @throws Exception if an error occurs
 */
@Test
public void styleAttributes() throws Exception {
    final List<String> allProperties = new ArrayList<>();
    for (final BrowserVersion browserVersion : allBrowsers()) {
        final ClassConfiguration config = AbstractJavaScriptConfiguration.getClassConfiguration(CSSStyleDeclaration.class, browserVersion);
        for (final Definition definition : StyleAttributes.getDefinitions(browserVersion)) {
            if (!definition.name().endsWith("_")) {
                final String propertyName = definition.getPropertyName();
                final PropertyInfo info = config.getPropertyMap().get(propertyName);
                if (info != null) {
                    allProperties.add(propertyName);
                }
            }
        }
    }
    final BrowserVersion browserVersion = getBrowserVersion();
    final ClassConfiguration config = AbstractJavaScriptConfiguration.getClassConfiguration(CSSStyleDeclaration.class, browserVersion);
    for (final Definition definition : StyleAttributes.getDefinitions(browserVersion)) {
        if (!definition.name().endsWith("_")) {
            final String propertyName = definition.getPropertyName();
            final PropertyInfo info = config.getPropertyMap().get(propertyName);
            if (allProperties.contains(propertyName) && (info == null || info.getReadMethod() == null || info.getWriteMethod() == null)) {
                fail("CSSStyleDeclaration: " + propertyName + " must support " + browserVersion.getNickname());
            }
        }
    }
    for (final String propertyName : config.getPropertyMap().keySet()) {
        if (!"length".equals(propertyName) && !"parentRule".equals(propertyName) && !"cssText".equals(propertyName) && StyleAttributes.getDefinition(propertyName, browserVersion) == null) {
            fail("CSSStyleDeclaration: incorrectly defines " + propertyName + " for " + browserVersion.getNickname());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Definition(com.gargoylesoftware.htmlunit.css.StyleAttributes.Definition) PropertyInfo(com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration.PropertyInfo) BrowserVersion(com.gargoylesoftware.htmlunit.BrowserVersion) ClassConfiguration(com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration) Test(org.junit.Test)

Example 4 with PropertyInfo

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

the class CSSStyleDeclarationTest method defaultImplementation.

/**
 * Ensures no default implementation is being used.
 *
 * When no JavaScript method is defined, {@link StyleAttributes} values are used, this can be overridden only
 * when a different implementation is needed.
 *
 * @throws Exception if an error occurs
 */
@Test
public void defaultImplementation() throws Exception {
    final BrowserVersion browserVersion = getBrowserVersion();
    final ClassConfiguration config = AbstractJavaScriptConfiguration.getClassConfiguration(CSSStyleDeclaration.class, browserVersion);
    final Map<String, PropertyInfo> propertyMap = config.getPropertyMap();
    final File cssFolder = new File("src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/");
    final List<String> cssLines = FileUtils.readLines(new File(cssFolder, "CSSStyleDeclaration.java"), ISO_8859_1);
    final List<String> computedLines = FileUtils.readLines(new File(cssFolder, "ComputedCSSStyleDeclaration.java"), ISO_8859_1);
    for (final Map.Entry<String, PropertyInfo> entry : propertyMap.entrySet()) {
        final PropertyInfo info = entry.getValue();
        if (info.getReadMethod() == null) {
            fail(browserVersion.getNickname() + " CSSStyleDeclaration: no getter for " + entry.getKey());
        }
        if (info.getWriteMethod() == null && !"length".equals(entry.getKey())) {
            fail(browserVersion.getNickname() + " CSSStyleDeclaration: no setter for " + entry.getKey());
        }
        if (isDefaultGetter(cssLines, info) && isDefaultSetter(cssLines, info) && isDefaultGetterComputed(computedLines, info)) {
            fail(browserVersion.getNickname() + " CSSStyleDeclaration: default implementation for " + entry.getKey());
        }
    }
}
Also used : PropertyInfo(com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration.PropertyInfo) BrowserVersion(com.gargoylesoftware.htmlunit.BrowserVersion) File(java.io.File) Map(java.util.Map) ClassConfiguration(com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration) Test(org.junit.Test)

Example 5 with PropertyInfo

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

the class MSXMLJavaScriptEnvironment method configureConstantsPropertiesAndFunctions.

/**
 * Configures constants, properties and functions on the object.
 * @param config the configuration for the object
 * @param scriptable the object to configure
 */
private static void configureConstantsPropertiesAndFunctions(final ClassConfiguration config, final ScriptableObject scriptable) {
    // the constants
    configureConstants(config, scriptable);
    // the properties
    final Map<String, PropertyInfo> propertyMap = config.getPropertyMap();
    if (propertyMap != null) {
        for (final Map.Entry<String, PropertyInfo> entry : propertyMap.entrySet()) {
            final PropertyInfo info = entry.getValue();
            final Method readMethod = info.getReadMethod();
            final Method writeMethod = info.getWriteMethod();
            scriptable.defineProperty(entry.getKey(), null, readMethod, writeMethod, ScriptableObject.EMPTY);
        }
    }
    final int attributes = ScriptableObject.DONTENUM;
    // the functions
    final Map<String, Method> functionMap = config.getFunctionMap();
    if (functionMap != null) {
        for (final Entry<String, Method> functionInfo : functionMap.entrySet()) {
            final String functionName = functionInfo.getKey();
            final Method method = functionInfo.getValue();
            final FunctionObject functionObject = new FunctionObject(functionName, method, scriptable);
            scriptable.defineProperty(functionName, functionObject, attributes);
        }
    }
}
Also used : Method(java.lang.reflect.Method) PropertyInfo(com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration.PropertyInfo) FunctionObject(net.sourceforge.htmlunit.corejs.javascript.FunctionObject) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

PropertyInfo (com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration.PropertyInfo)5 Method (java.lang.reflect.Method)3 BrowserVersion (com.gargoylesoftware.htmlunit.BrowserVersion)2 ClassConfiguration (com.gargoylesoftware.htmlunit.javascript.configuration.ClassConfiguration)2 Map (java.util.Map)2 Test (org.junit.Test)2 Definition (com.gargoylesoftware.htmlunit.css.StyleAttributes.Definition)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 FunctionObject (net.sourceforge.htmlunit.corejs.javascript.FunctionObject)1