Search in sources :

Example 1 with IdFunctionObject

use of net.sourceforge.htmlunit.corejs.javascript.IdFunctionObject in project htmlunit by HtmlUnit.

the class JavaScriptEngine method configureRhino.

/**
 * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
 *
 * @param webClient the WebClient
 * @param browserVersion the BrowserVersion
 * @param scriptable the window or the DedicatedWorkerGlobalScope
 */
public static void configureRhino(final WebClient webClient, final BrowserVersion browserVersion, final HtmlUnitScriptable scriptable) {
    // Rhino defines too much methods for us, particularly since implementation of ECMAScript5
    final ScriptableObject stringPrototype = (ScriptableObject) ScriptableObject.getClassPrototype(scriptable, "String");
    deleteProperties(stringPrototype, "equals", "equalsIgnoreCase", "toSource");
    final ScriptableObject numberPrototype = (ScriptableObject) ScriptableObject.getClassPrototype(scriptable, "Number");
    deleteProperties(numberPrototype, "toSource");
    final ScriptableObject datePrototype = (ScriptableObject) ScriptableObject.getClassPrototype(scriptable, "Date");
    deleteProperties(datePrototype, "toSource");
    if (!browserVersion.hasFeature(STRING_INCLUDES)) {
        deleteProperties(stringPrototype, "includes");
    }
    if (!browserVersion.hasFeature(STRING_REPEAT)) {
        deleteProperties(stringPrototype, "repeat");
    }
    if (!browserVersion.hasFeature(STRING_STARTS_ENDS_WITH)) {
        deleteProperties(stringPrototype, "startsWith", "endsWith");
    }
    if (!browserVersion.hasFeature(STRING_TRIM_LEFT_RIGHT)) {
        deleteProperties(stringPrototype, "trimLeft", "trimRight");
    }
    deleteProperties(scriptable, "uneval");
    removePrototypeProperties(scriptable, "Object", "toSource");
    removePrototypeProperties(scriptable, "Array", "toSource");
    removePrototypeProperties(scriptable, "Function", "toSource");
    if (browserVersion.hasFeature(JS_WINDOW_ACTIVEXOBJECT_HIDDEN)) {
        ((IdFunctionObject) ScriptableObject.getProperty(scriptable, "Object")).delete("assign");
        // TODO
        deleteProperties(scriptable, "WeakSet");
    }
    deleteProperties(scriptable, "isXMLName");
    NativeFunctionToStringFunction.installFix(scriptable, browserVersion);
    if (!browserVersion.hasFeature(JS_GLOBAL_THIS)) {
        deleteProperties(scriptable, "globalThis");
    }
    datePrototype.defineFunctionProperties(new String[] { "toLocaleDateString", "toLocaleTimeString" }, DateCustom.class, ScriptableObject.DONTENUM);
    if (!browserVersion.hasFeature(JS_OBJECT_GET_OWN_PROPERTY_SYMBOLS)) {
        ((ScriptableObject) ScriptableObject.getProperty(scriptable, "Object")).delete("getOwnPropertySymbols");
    }
    if (!browserVersion.hasFeature(JS_ARRAY_FROM)) {
        deleteProperties((ScriptableObject) ScriptableObject.getProperty(scriptable, "Array"), "from", "of");
    }
    numberPrototype.defineFunctionProperties(new String[] { "toLocaleString" }, NumberCustom.class, ScriptableObject.DONTENUM);
    if (!webClient.getOptions().isWebSocketEnabled()) {
        deleteProperties(scriptable, "WebSocket");
    }
}
Also used : ScriptableObject(net.sourceforge.htmlunit.corejs.javascript.ScriptableObject) IdFunctionObject(net.sourceforge.htmlunit.corejs.javascript.IdFunctionObject)

Aggregations

IdFunctionObject (net.sourceforge.htmlunit.corejs.javascript.IdFunctionObject)1 ScriptableObject (net.sourceforge.htmlunit.corejs.javascript.ScriptableObject)1