Java Code Examples for jdk.nashorn.internal.runtime.options.Options#getString()

The following examples show how to use jdk.nashorn.internal.runtime.options.Options#getString() . 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: Context.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor
 *
 * @param options options from command line or Context creator
 * @param errors  error manger
 * @param out     output writer for this Context
 * @param err     error writer for this Context
 * @param appLoader application class loader
 * @param classFilter class filter to use
 */
public Context(final Options options, final ErrorManager errors, final PrintWriter out, final PrintWriter err, final ClassLoader appLoader, final ClassFilter classFilter) {
    final SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(new RuntimePermission(NASHORN_CREATE_CONTEXT));
    }

    this.classFilter = classFilter;
    this.env       = new ScriptEnvironment(options, out, err);
    this._strict   = env._strict;
    if (env._loader_per_compile) {
        this.scriptLoader = null;
        this.uniqueScriptId = null;
    } else {
        this.scriptLoader = createNewLoader();
        this.uniqueScriptId = new AtomicLong();
    }
    this.errors    = errors;

    // if user passed -classpath option, make a URLClassLoader with that and
    // the app loader as the parent.
    final String classPath = options.getString("classpath");
    if (!env._compile_only && classPath != null && !classPath.isEmpty()) {
        // make sure that caller can create a class loader.
        if (sm != null) {
            sm.checkCreateClassLoader();
        }
        this.appLoader = NashornLoader.createClassLoader(classPath, appLoader);
    } else {
        this.appLoader = appLoader;
    }

    final int cacheSize = env._class_cache_size;
    if (cacheSize > 0) {
        classCache = new ClassCache(cacheSize);
    }

    if (env._persistent_cache) {
        codeStore = newCodeStore(this);
    }

    // print version info if asked.
    if (env._version) {
        getErr().println("nashorn " + Version.version());
    }

    if (env._fullversion) {
        getErr().println("nashorn full version " + Version.fullVersion());
    }

    if (Options.getBooleanProperty("nashorn.fields.dual")) {
        fieldMode = FieldMode.DUAL;
    } else if (Options.getBooleanProperty("nashorn.fields.objects")) {
        fieldMode = FieldMode.OBJECTS;
    } else {
        fieldMode = FieldMode.AUTO;
    }

    initLoggers();
}
 
Example 2
Source File: Context.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor
 *
 * @param options options from command line or Context creator
 * @param errors  error manger
 * @param out     output writer for this Context
 * @param err     error writer for this Context
 * @param appLoader application class loader
 * @param classFilter class filter to use
 */
public Context(final Options options, final ErrorManager errors, final PrintWriter out, final PrintWriter err, final ClassLoader appLoader, final ClassFilter classFilter) {
    final SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(new RuntimePermission(NASHORN_CREATE_CONTEXT));
    }

    this.classFilter = classFilter;
    this.env       = new ScriptEnvironment(options, out, err);
    this._strict   = env._strict;
    this.appLoader = appLoader;
    if (env._loader_per_compile) {
        this.scriptLoader = null;
        this.uniqueScriptId = null;
    } else {
        this.scriptLoader = createNewLoader();
        this.uniqueScriptId = new AtomicLong();
    }
    this.errors    = errors;

    // if user passed -classpath option, make a class loader with that and set it as
    // thread context class loader so that script can access classes from that path.
    final String classPath = options.getString("classpath");
    if (!env._compile_only && classPath != null && !classPath.isEmpty()) {
        // make sure that caller can create a class loader.
        if (sm != null) {
            sm.checkPermission(new RuntimePermission("createClassLoader"));
        }
        this.classPathLoader = NashornLoader.createClassLoader(classPath);
    } else {
        this.classPathLoader = null;
    }

    final int cacheSize = env._class_cache_size;
    if (cacheSize > 0) {
        classCache = new ClassCache(cacheSize);
    }

    if (env._persistent_cache) {
        codeStore = newCodeStore(this);
    }

    // print version info if asked.
    if (env._version) {
        getErr().println("nashorn " + Version.version());
    }

    if (env._fullversion) {
        getErr().println("nashorn full version " + Version.fullVersion());
    }

    if (Options.getBooleanProperty("nashorn.fields.dual")) {
        fieldMode = FieldMode.DUAL;
    } else if (Options.getBooleanProperty("nashorn.fields.objects")) {
        fieldMode = FieldMode.OBJECTS;
    } else {
        fieldMode = FieldMode.AUTO;
    }

    initLoggers();
}
 
Example 3
Source File: Context.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor
 *
 * @param options options from command line or Context creator
 * @param errors  error manger
 * @param out     output writer for this Context
 * @param err     error writer for this Context
 * @param appLoader application class loader
 * @param classFilter class filter to use
 */
public Context(final Options options, final ErrorManager errors, final PrintWriter out, final PrintWriter err, final ClassLoader appLoader, final ClassFilter classFilter) {
    final SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(new RuntimePermission(NASHORN_CREATE_CONTEXT));
    }

    this.classFilter = classFilter;
    this.env       = new ScriptEnvironment(options, out, err);
    this._strict   = env._strict;
    if (env._loader_per_compile) {
        this.scriptLoader = null;
        this.uniqueScriptId = null;
    } else {
        this.scriptLoader = createNewLoader();
        this.uniqueScriptId = new AtomicLong();
    }
    this.errors    = errors;

    // if user passed -classpath option, make a URLClassLoader with that and
    // the app loader as the parent.
    final String classPath = options.getString("classpath");
    if (!env._compile_only && classPath != null && !classPath.isEmpty()) {
        // make sure that caller can create a class loader.
        if (sm != null) {
            sm.checkCreateClassLoader();
        }
        this.appLoader = NashornLoader.createClassLoader(classPath, appLoader);
    } else {
        this.appLoader = appLoader;
    }

    final int cacheSize = env._class_cache_size;
    if (cacheSize > 0) {
        classCache = new ClassCache(cacheSize);
    }

    if (env._persistent_cache) {
        codeStore = newCodeStore(this);
    }

    // print version info if asked.
    if (env._version) {
        getErr().println("nashorn " + Version.version());
    }

    if (env._fullversion) {
        getErr().println("nashorn full version " + Version.fullVersion());
    }

    if (Options.getBooleanProperty("nashorn.fields.dual")) {
        fieldMode = FieldMode.DUAL;
    } else if (Options.getBooleanProperty("nashorn.fields.objects")) {
        fieldMode = FieldMode.OBJECTS;
    } else {
        fieldMode = FieldMode.AUTO;
    }

    initLoggers();
}
 
Example 4
Source File: Context.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor
 *
 * @param options options from command line or Context creator
 * @param errors  error manger
 * @param out     output writer for this Context
 * @param err     error writer for this Context
 * @param appLoader application class loader
 * @param classFilter class filter to use
 */
public Context(final Options options, final ErrorManager errors, final PrintWriter out, final PrintWriter err, final ClassLoader appLoader, final ClassFilter classFilter) {
    final SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(new RuntimePermission(NASHORN_CREATE_CONTEXT));
    }

    this.classFilter = classFilter;
    this.env       = new ScriptEnvironment(options, out, err);
    this._strict   = env._strict;
    if (env._loader_per_compile) {
        this.scriptLoader = null;
        this.uniqueScriptId = null;
    } else {
        this.scriptLoader = createNewLoader();
        this.uniqueScriptId = new AtomicLong();
    }
    this.errors    = errors;

    // if user passed -classpath option, make a URLClassLoader with that and
    // the app loader as the parent.
    final String classPath = options.getString("classpath");
    if (!env._compile_only && classPath != null && !classPath.isEmpty()) {
        // make sure that caller can create a class loader.
        if (sm != null) {
            sm.checkCreateClassLoader();
        }
        this.appLoader = NashornLoader.createClassLoader(classPath, appLoader);
    } else {
        this.appLoader = appLoader;
    }

    final int cacheSize = env._class_cache_size;
    if (cacheSize > 0) {
        classCache = new ClassCache(cacheSize);
    }

    if (env._persistent_cache) {
        codeStore = newCodeStore(this);
    }

    // print version info if asked.
    if (env._version) {
        getErr().println("nashorn " + Version.version());
    }

    if (env._fullversion) {
        getErr().println("nashorn full version " + Version.fullVersion());
    }

    if (Options.getBooleanProperty("nashorn.fields.dual")) {
        fieldMode = FieldMode.DUAL;
    } else if (Options.getBooleanProperty("nashorn.fields.objects")) {
        fieldMode = FieldMode.OBJECTS;
    } else {
        fieldMode = FieldMode.AUTO;
    }

    initLoggers();
}
 
Example 5
Source File: Context.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor
 *
 * @param options options from command line or Context creator
 * @param errors  error manger
 * @param out     output writer for this Context
 * @param err     error writer for this Context
 * @param appLoader application class loader
 * @param classFilter class filter to use
 */
public Context(final Options options, final ErrorManager errors, final PrintWriter out, final PrintWriter err, final ClassLoader appLoader, final ClassFilter classFilter) {
    final SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(new RuntimePermission(NASHORN_CREATE_CONTEXT));
    }

    this.classFilter = classFilter;
    this.env       = new ScriptEnvironment(options, out, err);
    this._strict   = env._strict;
    this.appLoader = appLoader;
    if (env._loader_per_compile) {
        this.scriptLoader = null;
        this.uniqueScriptId = null;
    } else {
        this.scriptLoader = createNewLoader();
        this.uniqueScriptId = new AtomicLong();
    }
    this.errors    = errors;

    // if user passed -classpath option, make a class loader with that and set it as
    // thread context class loader so that script can access classes from that path.
    final String classPath = options.getString("classpath");
    if (!env._compile_only && classPath != null && !classPath.isEmpty()) {
        // make sure that caller can create a class loader.
        if (sm != null) {
            sm.checkPermission(new RuntimePermission("createClassLoader"));
        }
        this.classPathLoader = NashornLoader.createClassLoader(classPath);
    } else {
        this.classPathLoader = null;
    }

    final int cacheSize = env._class_cache_size;
    if (cacheSize > 0) {
        classCache = new ClassCache(cacheSize);
    }

    if (env._persistent_cache) {
        codeStore = newCodeStore(this);
    }

    // print version info if asked.
    if (env._version) {
        getErr().println("nashorn " + Version.version());
    }

    if (env._fullversion) {
        getErr().println("nashorn full version " + Version.fullVersion());
    }

    if (Options.getBooleanProperty("nashorn.fields.dual")) {
        fieldMode = FieldMode.DUAL;
    } else if (Options.getBooleanProperty("nashorn.fields.objects")) {
        fieldMode = FieldMode.OBJECTS;
    } else {
        fieldMode = FieldMode.AUTO;
    }

    initLoggers();
}
 
Example 6
Source File: Context.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor
 *
 * @param options options from command line or Context creator
 * @param errors  error manger
 * @param out     output writer for this Context
 * @param err     error writer for this Context
 * @param appLoader application class loader
 */
public Context(final Options options, final ErrorManager errors, final PrintWriter out, final PrintWriter err, final ClassLoader appLoader) {
    final SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(new RuntimePermission(NASHORN_CREATE_CONTEXT));
    }

    this.env       = new ScriptEnvironment(options, out, err);
    this._strict   = env._strict;
    this.appLoader = appLoader;
    if (env._loader_per_compile) {
        this.scriptLoader = null;
        this.uniqueScriptId = null;
    } else {
        this.scriptLoader = createNewLoader();
        this.uniqueScriptId = new AtomicLong();
    }
    this.errors    = errors;
    this.uniqueEvalId = new AtomicLong();

    // if user passed -classpath option, make a class loader with that and set it as
    // thread context class loader so that script can access classes from that path.
    final String classPath = options.getString("classpath");
    if (! env._compile_only && classPath != null && !classPath.isEmpty()) {
        // make sure that caller can create a class loader.
        if (sm != null) {
            sm.checkPermission(new RuntimePermission("createClassLoader"));
        }
        this.classPathLoader = NashornLoader.createClassLoader(classPath);
    } else {
        this.classPathLoader = null;
    }

    // print version info if asked.
    if (env._version) {
        getErr().println("nashorn " + Version.version());
    }

    if (env._fullversion) {
        getErr().println("nashorn full version " + Version.fullVersion());
    }
}
 
Example 7
Source File: ScriptEnvironment.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor
 *
 * @param options a Options object
 * @param out output print writer
 * @param err error print writer
 */
public ScriptEnvironment(final Options options, final PrintWriter out, final PrintWriter err) {
    this.out = out;
    this.err = err;
    this.namespace = new Namespace();
    this.options = options;

    _class_cache_size     = options.getInteger("class.cache.size");
    _compile_only         = options.getBoolean("compile.only");
    _debug_lines          = options.getBoolean("debug.lines");
    _dest_dir             = options.getString("d");
    _dump_on_error        = options.getBoolean("doe");
    _early_lvalue_error   = options.getBoolean("early.lvalue.error");
    _empty_statements     = options.getBoolean("empty.statements");
    _fullversion          = options.getBoolean("fullversion");
    if(options.getBoolean("function.statement.error")) {
        _function_statement = FunctionStatementBehavior.ERROR;
    } else if(options.getBoolean("function.statement.warning")) {
        _function_statement = FunctionStatementBehavior.WARNING;
    } else {
        _function_statement = FunctionStatementBehavior.ACCEPT;
    }
    _fx                   = options.getBoolean("fx");
    _global_per_engine    = options.getBoolean("global.per.engine");
    _lazy_compilation     = options.getBoolean("lazy.compilation");
    _loader_per_compile   = options.getBoolean("loader.per.compile");
    _no_java              = options.getBoolean("no.java");
    _no_syntax_extensions = options.getBoolean("no.syntax.extensions");
    _no_typed_arrays      = options.getBoolean("no.typed.arrays");
    _parse_only           = options.getBoolean("parse.only");
    _print_ast            = options.getBoolean("print.ast");
    _print_lower_ast      = options.getBoolean("print.lower.ast");
    _print_code           = options.getBoolean("print.code");
    _print_mem_usage      = options.getBoolean("print.mem.usage");
    _print_no_newline     = options.getBoolean("print.no.newline");
    _print_parse          = options.getBoolean("print.parse");
    _print_lower_parse    = options.getBoolean("print.lower.parse");
    _print_symbols        = options.getBoolean("print.symbols");
    _range_analysis       = options.getBoolean("range.analysis");
    _scripting            = options.getBoolean("scripting");
    _strict               = options.getBoolean("strict");
    _version              = options.getBoolean("version");
    _verify_code          = options.getBoolean("verify.code");

    final String specialize = options.getString("specialize.calls");
    if (specialize == null) {
        _specialize_calls = null;
    } else {
        _specialize_calls = new HashSet<>();
        final StringTokenizer st = new StringTokenizer(specialize, ",");
        while (st.hasMoreElements()) {
            _specialize_calls.add(st.nextToken());
        }
    }

    int callSiteFlags = 0;
    if (options.getBoolean("profile.callsites")) {
        callSiteFlags |= NashornCallSiteDescriptor.CALLSITE_PROFILE;
    }

    if (options.get("trace.callsites") instanceof KeyValueOption) {
        callSiteFlags |= NashornCallSiteDescriptor.CALLSITE_TRACE;
        final KeyValueOption kv = (KeyValueOption)options.get("trace.callsites");
        if (kv.hasValue("miss")) {
            callSiteFlags |= NashornCallSiteDescriptor.CALLSITE_TRACE_MISSES;
        }
        if (kv.hasValue("enterexit") || (callSiteFlags & NashornCallSiteDescriptor.CALLSITE_TRACE_MISSES) == 0) {
            callSiteFlags |= NashornCallSiteDescriptor.CALLSITE_TRACE_ENTEREXIT;
        }
        if (kv.hasValue("objects")) {
            callSiteFlags |= NashornCallSiteDescriptor.CALLSITE_TRACE_VALUES;
        }
        if (kv.hasValue("scope")) {
            callSiteFlags |= NashornCallSiteDescriptor.CALLSITE_TRACE_SCOPE;
        }
    }
    this._callsite_flags = callSiteFlags;

    final Option<?> timezoneOption = options.get("timezone");
    if (timezoneOption != null) {
        this._timezone = (TimeZone)timezoneOption.getValue();
    } else {
        this._timezone  = TimeZone.getDefault();
    }

    final Option<?> localeOption = options.get("locale");
    if (localeOption != null) {
        this._locale = (Locale)localeOption.getValue();
    } else {
        this._locale = Locale.getDefault();
    }
}
 
Example 8
Source File: Context.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor
 *
 * @param options options from command line or Context creator
 * @param errors  error manger
 * @param out     output writer for this Context
 * @param err     error writer for this Context
 * @param appLoader application class loader
 */
public Context(final Options options, final ErrorManager errors, final PrintWriter out, final PrintWriter err, final ClassLoader appLoader) {
    final SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(new RuntimePermission(NASHORN_CREATE_CONTEXT));
    }

    this.env       = new ScriptEnvironment(options, out, err);
    this._strict   = env._strict;
    this.appLoader = appLoader;
    if (env._loader_per_compile) {
        this.scriptLoader = null;
        this.uniqueScriptId = null;
    } else {
        this.scriptLoader = createNewLoader();
        this.uniqueScriptId = new AtomicLong();
    }
    this.errors    = errors;
    this.uniqueEvalId = new AtomicLong();

    // if user passed -classpath option, make a class loader with that and set it as
    // thread context class loader so that script can access classes from that path.
    final String classPath = options.getString("classpath");
    if (! env._compile_only && classPath != null && !classPath.isEmpty()) {
        // make sure that caller can create a class loader.
        if (sm != null) {
            sm.checkPermission(new RuntimePermission("createClassLoader"));
        }
        this.classPathLoader = NashornLoader.createClassLoader(classPath);
    } else {
        this.classPathLoader = null;
    }

    // print version info if asked.
    if (env._version) {
        getErr().println("nashorn " + Version.version());
    }

    if (env._fullversion) {
        getErr().println("nashorn full version " + Version.fullVersion());
    }
}
 
Example 9
Source File: ScriptEnvironment.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor
 *
 * @param options a Options object
 * @param out output print writer
 * @param err error print writer
 */
public ScriptEnvironment(final Options options, final PrintWriter out, final PrintWriter err) {
    this.out = out;
    this.err = err;
    this.namespace = new Namespace();
    this.options = options;

    _class_cache_size     = options.getInteger("class.cache.size");
    _compile_only         = options.getBoolean("compile.only");
    _debug_lines          = options.getBoolean("debug.lines");
    _dest_dir             = options.getString("d");
    _dump_on_error        = options.getBoolean("doe");
    _early_lvalue_error   = options.getBoolean("early.lvalue.error");
    _empty_statements     = options.getBoolean("empty.statements");
    _fullversion          = options.getBoolean("fullversion");
    if(options.getBoolean("function.statement.error")) {
        _function_statement = FunctionStatementBehavior.ERROR;
    } else if(options.getBoolean("function.statement.warning")) {
        _function_statement = FunctionStatementBehavior.WARNING;
    } else {
        _function_statement = FunctionStatementBehavior.ACCEPT;
    }
    _fx                   = options.getBoolean("fx");
    _global_per_engine    = options.getBoolean("global.per.engine");
    _lazy_compilation     = options.getBoolean("lazy.compilation");
    _loader_per_compile   = options.getBoolean("loader.per.compile");
    _no_java              = options.getBoolean("no.java");
    _no_syntax_extensions = options.getBoolean("no.syntax.extensions");
    _no_typed_arrays      = options.getBoolean("no.typed.arrays");
    _parse_only           = options.getBoolean("parse.only");
    _print_ast            = options.getBoolean("print.ast");
    _print_lower_ast      = options.getBoolean("print.lower.ast");
    _print_code           = options.getBoolean("print.code");
    _print_mem_usage      = options.getBoolean("print.mem.usage");
    _print_no_newline     = options.getBoolean("print.no.newline");
    _print_parse          = options.getBoolean("print.parse");
    _print_lower_parse    = options.getBoolean("print.lower.parse");
    _print_symbols        = options.getBoolean("print.symbols");
    _range_analysis       = options.getBoolean("range.analysis");
    _scripting            = options.getBoolean("scripting");
    _strict               = options.getBoolean("strict");
    _version              = options.getBoolean("version");
    _verify_code          = options.getBoolean("verify.code");

    final String specialize = options.getString("specialize.calls");
    if (specialize == null) {
        _specialize_calls = null;
    } else {
        _specialize_calls = new HashSet<>();
        final StringTokenizer st = new StringTokenizer(specialize, ",");
        while (st.hasMoreElements()) {
            _specialize_calls.add(st.nextToken());
        }
    }

    int callSiteFlags = 0;
    if (options.getBoolean("profile.callsites")) {
        callSiteFlags |= NashornCallSiteDescriptor.CALLSITE_PROFILE;
    }

    if (options.get("trace.callsites") instanceof KeyValueOption) {
        callSiteFlags |= NashornCallSiteDescriptor.CALLSITE_TRACE;
        final KeyValueOption kv = (KeyValueOption)options.get("trace.callsites");
        if (kv.hasValue("miss")) {
            callSiteFlags |= NashornCallSiteDescriptor.CALLSITE_TRACE_MISSES;
        }
        if (kv.hasValue("enterexit") || (callSiteFlags & NashornCallSiteDescriptor.CALLSITE_TRACE_MISSES) == 0) {
            callSiteFlags |= NashornCallSiteDescriptor.CALLSITE_TRACE_ENTEREXIT;
        }
        if (kv.hasValue("objects")) {
            callSiteFlags |= NashornCallSiteDescriptor.CALLSITE_TRACE_VALUES;
        }
        if (kv.hasValue("scope")) {
            callSiteFlags |= NashornCallSiteDescriptor.CALLSITE_TRACE_SCOPE;
        }
    }
    this._callsite_flags = callSiteFlags;

    final Option<?> timezoneOption = options.get("timezone");
    if (timezoneOption != null) {
        this._timezone = (TimeZone)timezoneOption.getValue();
    } else {
        this._timezone  = TimeZone.getDefault();
    }

    final Option<?> localeOption = options.get("locale");
    if (localeOption != null) {
        this._locale = (Locale)localeOption.getValue();
    } else {
        this._locale = Locale.getDefault();
    }
}
 
Example 10
Source File: Context.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor
 *
 * @param options options from command line or Context creator
 * @param errors  error manger
 * @param out     output writer for this Context
 * @param err     error writer for this Context
 * @param appLoader application class loader
 * @param classFilter class filter to use
 */
public Context(final Options options, final ErrorManager errors, final PrintWriter out, final PrintWriter err, final ClassLoader appLoader, final ClassFilter classFilter) {
    final SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(new RuntimePermission(NASHORN_CREATE_CONTEXT));
    }

    this.classFilter = classFilter;
    this.env       = new ScriptEnvironment(options, out, err);
    this._strict   = env._strict;
    if (env._loader_per_compile) {
        this.scriptLoader = null;
        this.uniqueScriptId = null;
    } else {
        this.scriptLoader = createNewLoader();
        this.uniqueScriptId = new AtomicLong();
    }
    this.errors    = errors;

    // if user passed -classpath option, make a URLClassLoader with that and
    // the app loader as the parent.
    final String classPath = options.getString("classpath");
    if (!env._compile_only && classPath != null && !classPath.isEmpty()) {
        // make sure that caller can create a class loader.
        if (sm != null) {
            sm.checkCreateClassLoader();
        }
        this.appLoader = NashornLoader.createClassLoader(classPath, appLoader);
    } else {
        this.appLoader = appLoader;
    }

    final int cacheSize = env._class_cache_size;
    if (cacheSize > 0) {
        classCache = new ClassCache(cacheSize);
    }

    if (env._persistent_cache) {
        codeStore = newCodeStore(this);
    }

    // print version info if asked.
    if (env._version) {
        getErr().println("nashorn " + Version.version());
    }

    if (env._fullversion) {
        getErr().println("nashorn full version " + Version.fullVersion());
    }

    if (Options.getBooleanProperty("nashorn.fields.dual")) {
        fieldMode = FieldMode.DUAL;
    } else if (Options.getBooleanProperty("nashorn.fields.objects")) {
        fieldMode = FieldMode.OBJECTS;
    } else {
        fieldMode = FieldMode.AUTO;
    }

    initLoggers();
}
 
Example 11
Source File: Context.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor
 *
 * @param options options from command line or Context creator
 * @param errors  error manger
 * @param out     output writer for this Context
 * @param err     error writer for this Context
 * @param appLoader application class loader
 */
public Context(final Options options, final ErrorManager errors, final PrintWriter out, final PrintWriter err, final ClassLoader appLoader) {
    final SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(new RuntimePermission(NASHORN_CREATE_CONTEXT));
    }

    this.env       = new ScriptEnvironment(options, out, err);
    this._strict   = env._strict;
    this.appLoader = appLoader;
    if (env._loader_per_compile) {
        this.scriptLoader = null;
        this.uniqueScriptId = null;
    } else {
        this.scriptLoader = createNewLoader();
        this.uniqueScriptId = new AtomicLong();
    }
    this.errors    = errors;

    // if user passed -classpath option, make a class loader with that and set it as
    // thread context class loader so that script can access classes from that path.
    final String classPath = options.getString("classpath");
    if (! env._compile_only && classPath != null && !classPath.isEmpty()) {
        // make sure that caller can create a class loader.
        if (sm != null) {
            sm.checkPermission(new RuntimePermission("createClassLoader"));
        }
        this.classPathLoader = NashornLoader.createClassLoader(classPath);
    } else {
        this.classPathLoader = null;
    }

    // print version info if asked.
    if (env._version) {
        getErr().println("nashorn " + Version.version());
    }

    if (env._fullversion) {
        getErr().println("nashorn full version " + Version.fullVersion());
    }
}
 
Example 12
Source File: ScriptEnvironment.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor
 *
 * @param options a Options object
 * @param out output print writer
 * @param err error print writer
 */
public ScriptEnvironment(final Options options, final PrintWriter out, final PrintWriter err) {
    this.out = out;
    this.err = err;
    this.namespace = new Namespace();
    this.options = options;

    _class_cache_size     = options.getInteger("class.cache.size");
    _compile_only         = options.getBoolean("compile.only");
    _debug_lines          = options.getBoolean("debug.lines");
    _dest_dir             = options.getString("d");
    _dump_on_error        = options.getBoolean("doe");
    _early_lvalue_error   = options.getBoolean("early.lvalue.error");
    _empty_statements     = options.getBoolean("empty.statements");
    _fullversion          = options.getBoolean("fullversion");
    if(options.getBoolean("function.statement.error")) {
        _function_statement = FunctionStatementBehavior.ERROR;
    } else if(options.getBoolean("function.statement.warning")) {
        _function_statement = FunctionStatementBehavior.WARNING;
    } else {
        _function_statement = FunctionStatementBehavior.ACCEPT;
    }
    _fx                   = options.getBoolean("fx");
    _global_per_engine    = options.getBoolean("global.per.engine");
    _lazy_compilation     = options.getBoolean("lazy.compilation");
    _loader_per_compile   = options.getBoolean("loader.per.compile");
    _no_java              = options.getBoolean("no.java");
    _no_syntax_extensions = options.getBoolean("no.syntax.extensions");
    _no_typed_arrays      = options.getBoolean("no.typed.arrays");
    _parse_only           = options.getBoolean("parse.only");
    _print_ast            = options.getBoolean("print.ast");
    _print_lower_ast      = options.getBoolean("print.lower.ast");
    _print_code           = options.getBoolean("print.code");
    _print_mem_usage      = options.getBoolean("print.mem.usage");
    _print_no_newline     = options.getBoolean("print.no.newline");
    _print_parse          = options.getBoolean("print.parse");
    _print_lower_parse    = options.getBoolean("print.lower.parse");
    _print_symbols        = options.getBoolean("print.symbols");
    _range_analysis       = options.getBoolean("range.analysis");
    _scripting            = options.getBoolean("scripting");
    _strict               = options.getBoolean("strict");
    _version              = options.getBoolean("version");
    _verify_code          = options.getBoolean("verify.code");

    final String specialize = options.getString("specialize.calls");
    if (specialize == null) {
        _specialize_calls = null;
    } else {
        _specialize_calls = new HashSet<>();
        final StringTokenizer st = new StringTokenizer(specialize, ",");
        while (st.hasMoreElements()) {
            _specialize_calls.add(st.nextToken());
        }
    }

    int callSiteFlags = 0;
    if (options.getBoolean("profile.callsites")) {
        callSiteFlags |= NashornCallSiteDescriptor.CALLSITE_PROFILE;
    }

    if (options.get("trace.callsites") instanceof KeyValueOption) {
        callSiteFlags |= NashornCallSiteDescriptor.CALLSITE_TRACE;
        final KeyValueOption kv = (KeyValueOption)options.get("trace.callsites");
        if (kv.hasValue("miss")) {
            callSiteFlags |= NashornCallSiteDescriptor.CALLSITE_TRACE_MISSES;
        }
        if (kv.hasValue("enterexit") || (callSiteFlags & NashornCallSiteDescriptor.CALLSITE_TRACE_MISSES) == 0) {
            callSiteFlags |= NashornCallSiteDescriptor.CALLSITE_TRACE_ENTEREXIT;
        }
        if (kv.hasValue("objects")) {
            callSiteFlags |= NashornCallSiteDescriptor.CALLSITE_TRACE_VALUES;
        }
        if (kv.hasValue("scope")) {
            callSiteFlags |= NashornCallSiteDescriptor.CALLSITE_TRACE_SCOPE;
        }
    }
    this._callsite_flags = callSiteFlags;

    final Option<?> timezoneOption = options.get("timezone");
    if (timezoneOption != null) {
        this._timezone = (TimeZone)timezoneOption.getValue();
    } else {
        this._timezone  = TimeZone.getDefault();
    }

    final Option<?> localeOption = options.get("locale");
    if (localeOption != null) {
        this._locale = (Locale)localeOption.getValue();
    } else {
        this._locale = Locale.getDefault();
    }
}