当前位置: 首页>>代码示例>>Java>>正文


Java ScriptEnvironment类代码示例

本文整理汇总了Java中jdk.nashorn.internal.runtime.ScriptEnvironment的典型用法代码示例。如果您正苦于以下问题:Java ScriptEnvironment类的具体用法?Java ScriptEnvironment怎么用?Java ScriptEnvironment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ScriptEnvironment类属于jdk.nashorn.internal.runtime包,在下文中一共展示了ScriptEnvironment类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: Parser

import jdk.nashorn.internal.runtime.ScriptEnvironment; //导入依赖的package包/类
/**
 * Construct a parser.
 *
 * @param env     script environment
 * @param source  source to parse
 * @param errors  error manager
 * @param strict  parser created with strict mode enabled.
 * @param lineOffset line offset to start counting lines from
 * @param log debug logger if one is needed
 */
public Parser(final ScriptEnvironment env, final Source source, final ErrorManager errors, final boolean strict, final int lineOffset, final DebugLogger log) {
    super(source, errors, strict, lineOffset);
    this.env = env;
    this.namespace = new Namespace(env.getNamespace());
    this.scripting = env._scripting;
    if (this.scripting) {
        this.lineInfoReceiver = new Lexer.LineInfoReceiver() {
            @Override
            public void lineInfo(final int receiverLine, final int receiverLinePosition) {
                // update the parser maintained line information
                Parser.this.line = receiverLine;
                Parser.this.linePosition = receiverLinePosition;
            }
        };
    } else {
        // non-scripting mode script can't have multi-line literals
        this.lineInfoReceiver = null;
    }

    this.log = log == null ? DebugLogger.DISABLED_LOGGER : log;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:32,代码来源:Parser.java

示例2: safeSourceName

import jdk.nashorn.internal.runtime.ScriptEnvironment; //导入依赖的package包/类
private static String safeSourceName(final ScriptEnvironment env, final CodeInstaller<ScriptEnvironment> installer, final Source source) {
    String baseName = new File(source.getName()).getName();

    final int index = baseName.lastIndexOf(".js");
    if (index != -1) {
        baseName = baseName.substring(0, index);
    }

    baseName = baseName.replace('.', '_').replace('-', '_');
    if (!env._loader_per_compile) {
        baseName = baseName + installer.getUniqueScriptId();
    }

    // ASM's bytecode verifier does not allow JVM allowed safe escapes using '\' as escape char.
    // While ASM accepts such escapes for method names, field names, it enforces Java identifier
    // for class names. Workaround that ASM bug here by replacing JVM 'dangerous' chars with '_'
    // rather than safe encoding using '\'.
    final String mangled = env._verify_code? replaceDangerChars(baseName) : NameCodec.encode(baseName);
    return mangled != null ? mangled : baseName;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:Compiler.java

示例3: skipFunction

import jdk.nashorn.internal.runtime.ScriptEnvironment; //导入依赖的package包/类
private boolean skipFunction(final FunctionNode functionNode) {
    final ScriptEnvironment env = compiler.getScriptEnvironment();
    final boolean lazy = env._lazy_compilation;
    final boolean onDemand = compiler.isOnDemandCompilation();

    // If this is on-demand or lazy compilation, don't compile a nested (not topmost) function.
    if((onDemand || lazy) && lc.getOutermostFunction() != functionNode) {
        return true;
    }

    // If lazy compiling with optimistic types, don't compile the program eagerly either. It will soon be
    // invalidated anyway. In presence of a class cache, this further means that an obsoleted program version
    // lingers around. Also, currently loading previously persisted optimistic types information only works if
    // we're on-demand compiling a function, so with this strategy the :program method can also have the warmup
    // benefit of using previously persisted types.
    //
    // NOTE that this means the first compiled class will effectively just have a :createProgramFunction method, and
    // the RecompilableScriptFunctionData (RSFD) object in its constants array. It won't even have the :program
    // method. This is by design. It does mean that we're wasting one compiler execution (and we could minimize this
    // by just running it up to scope depth calculation, which creates the RSFDs and then this limited codegen).
    // We could emit an initial separate compile unit with the initial version of :program in it to better utilize
    // the compilation pipeline, but that would need more invasive changes, as currently the assumption that
    // :program is emitted into the first compilation unit of the function lives in many places.
    return !onDemand && lazy && env._optimistic_types && functionNode.isProgram();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:CodeGenerator.java

示例4: run

import jdk.nashorn.internal.runtime.ScriptEnvironment; //导入依赖的package包/类
/**
 * Run method logic.
 *
 * @param in input stream for Shell
 * @param out output stream for Shell
 * @param err error stream for Shell
 * @param args arguments to Shell
 *
 * @return exit code
 *
 * @throws IOException if there's a problem setting up the streams
 */
protected final int run(final InputStream in, final OutputStream out, final OutputStream err, final String[] args) throws IOException {
    final Context context = makeContext(in, out, err, args);
    if (context == null) {
        return COMMANDLINE_ERROR;
    }

    final Global global = context.createGlobal();
    final ScriptEnvironment env = context.getEnv();
    final List<String> files = env.getFiles();
    if (files.isEmpty()) {
        return readEvalPrint(context, global);
    }

    if (env._compile_only) {
        return compileScripts(context, global, files);
    }

    if (env._fx) {
        return runFXScripts(context, global, files);
    }

    return runScripts(context, global, files);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:Shell.java

示例5: Parser

import jdk.nashorn.internal.runtime.ScriptEnvironment; //导入依赖的package包/类
/**
 * Construct a parser.
 *
 * @param env     script environment
 * @param source  source to parse
 * @param errors  error manager
 * @param strict  parser created with strict mode enabled.
 * @param lineOffset line offset to start counting lines from
 * @param log debug logger if one is needed
 */
public Parser(final ScriptEnvironment env, final Source source, final ErrorManager errors, final boolean strict, final int lineOffset, final DebugLogger log) {
    super(source, errors, strict, lineOffset);
    this.lc = new ParserContext();
    this.defaultNames = new ArrayDeque<>();
    this.env = env;
    this.namespace = new Namespace(env.getNamespace());
    this.scripting = env._scripting;
    if (this.scripting) {
        this.lineInfoReceiver = new Lexer.LineInfoReceiver() {
            @Override
            public void lineInfo(final int receiverLine, final int receiverLinePosition) {
                // update the parser maintained line information
                Parser.this.line = receiverLine;
                Parser.this.linePosition = receiverLinePosition;
            }
        };
    } else {
        // non-scripting mode script can't have multi-line literals
        this.lineInfoReceiver = null;
    }

    this.log = log == null ? DebugLogger.DISABLED_LOGGER : log;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:Parser.java

示例6: transform

import jdk.nashorn.internal.runtime.ScriptEnvironment; //导入依赖的package包/类
@Override
FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) {
    final FunctionNode newFunctionNode = transformFunction(fn, new LocalVariableTypesCalculator(compiler));
    final ScriptEnvironment senv = compiler.getScriptEnvironment();
    final PrintWriter       err  = senv.getErr();

    //TODO separate phase for the debug printouts for abstraction and clarity
    if (senv._print_lower_ast || fn.getDebugFlag(FunctionNode.DEBUG_PRINT_LOWER_AST)) {
        err.println("Lower AST for: " + quote(newFunctionNode.getName()));
        err.println(new ASTWriter(newFunctionNode));
    }

    if (senv._print_lower_parse || fn.getDebugFlag(FunctionNode.DEBUG_PRINT_LOWER_PARSE)) {
        err.println("Lower AST for: " + quote(newFunctionNode.getName()));
        err.println(new PrintVisitor(newFunctionNode));
    }

    return newFunctionNode;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:CompilationPhase.java

示例7: createParser

import jdk.nashorn.internal.runtime.ScriptEnvironment; //导入依赖的package包/类
private static Parser createParser(final ScriptEnvironment env) {
    final List<String> args = new ArrayList<>();
    if (env._const_as_var) {
        args.add("--const-as-var");
    }

    if (env._no_syntax_extensions) {
        args.add("-nse");
    }

    if (env._scripting) {
        args.add("-scripting");
    }

    if (env._strict) {
        args.add("-strict");
    }

    if (env._es6) {
        args.add("--language=es6");
    }

    return Parser.create(args.toArray(new String[0]));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:NashornCompleter.java

示例8: createParser

import jdk.nashorn.internal.runtime.ScriptEnvironment; //导入依赖的package包/类
private static Parser createParser(final ScriptEnvironment env) {
    final List<String> args = new ArrayList<>();
    if (env._const_as_var) {
        args.add("--const-as-var");
    }

    if (env._no_syntax_extensions) {
        args.add("-nse");
    }

    if (env._scripting) {
        args.add("-scripting");
    }

    if (env._strict) {
        args.add("-strict");
    }

    return Parser.create(args.toArray(new String[0]));
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:21,代码来源:NashornCompleter.java

示例9: transform

import jdk.nashorn.internal.runtime.ScriptEnvironment; //导入依赖的package包/类
@Override
FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) {
    final FunctionNode newFunctionNode = transformFunction(fn, new LocalVariableTypesCalculator(compiler));
    final ScriptEnvironment senv = compiler.getScriptEnvironment();
    final PrintWriter       err  = senv.getErr();

    //TODO separate phase for the debug printouts for abstraction and clarity
    if (senv._print_lower_ast || fn.getFlag(FunctionNode.IS_PRINT_LOWER_AST)) {
        err.println("Lower AST for: " + quote(newFunctionNode.getName()));
        err.println(new ASTWriter(newFunctionNode));
    }

    if (senv._print_lower_parse || fn.getFlag(FunctionNode.IS_PRINT_LOWER_PARSE)) {
        err.println("Lower AST for: " + quote(newFunctionNode.getName()));
        err.println(new PrintVisitor(newFunctionNode));
    }

    return newFunctionNode;
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:20,代码来源:CompilationPhase.java

示例10: Parser

import jdk.nashorn.internal.runtime.ScriptEnvironment; //导入依赖的package包/类
/**
 * Construct a parser.
 *
 * @param env     script environment
 * @param source  source to parse
 * @param errors  error manager
 * @param strict  parser created with strict mode enabled.
 */
public Parser(final ScriptEnvironment env, final Source source, final ErrorManager errors, final boolean strict) {
    super(source, errors, strict);
    this.env       = env;
    this.namespace = new Namespace(env.getNamespace());
    this.scripting = env._scripting;
    if (this.scripting) {
        this.lineInfoReceiver = new Lexer.LineInfoReceiver() {
            @Override
            public void lineInfo(final int receiverLine, final int receiverLinePosition) {
                // update the parser maintained line information
                Parser.this.line = receiverLine;
                Parser.this.linePosition = receiverLinePosition;
            }
        };
    } else {
        // non-scripting mode script can't have multi-line literals
        this.lineInfoReceiver = null;
    }
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:28,代码来源:Parser.java

示例11: toByteArray

import jdk.nashorn.internal.runtime.ScriptEnvironment; //导入依赖的package包/类
/**
 * Collects the byte codes for a generated JavaScript class.
 *
 * @param classEmitter Open class emitter.
 * @return Byte codes for the class.
 */
private byte[] toByteArray(final ClassEmitter classEmitter) {
    classEmitter.end();

    final byte[] code = classEmitter.toByteArray();
    final ScriptEnvironment env = context.getEnv();

    if (env._print_code) {
        env.getErr().println(ClassEmitter.disassemble(code));
    }

    if (env._verify_code) {
        context.verify(code);
    }

    return code;
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:23,代码来源:ObjectClassGenerator.java

示例12: run

import jdk.nashorn.internal.runtime.ScriptEnvironment; //导入依赖的package包/类
/**
 * Run method logic.
 *
 * @param in input stream for Shell
 * @param out output stream for Shell
 * @param err error stream for Shell
 * @param args arguments to Shell
 *
 * @return exit code
 *
 * @throws IOException if there's a problem setting up the streams
 */
protected final int run(final InputStream in, final OutputStream out, final OutputStream err, final String[] args) throws IOException {
    final Context context = makeContext(in, out, err, args);
    if (context == null) {
        return COMMANDLINE_ERROR;
    }

    final ScriptObject global = context.createGlobal();
    final ScriptEnvironment env = context.getEnv();
    final List<String> files = env.getFiles();
    if (files.isEmpty()) {
        return readEvalPrint(context, global);
    }

    if (env._compile_only) {
        return compileScripts(context, global, files);
    }

    if (env._fx) {
        return runFXScripts(context, global, files);
    }

    return runScripts(context, global, files);
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:36,代码来源:Shell.java

示例13: initScripting

import jdk.nashorn.internal.runtime.ScriptEnvironment; //导入依赖的package包/类
private void initScripting(final ScriptEnvironment scriptEnv) {
    Object value;
    value = ScriptFunctionImpl.makeFunction("readLine", ScriptingFunctions.READLINE);
    addOwnProperty("readLine", Attribute.NOT_ENUMERABLE, value);

    value = ScriptFunctionImpl.makeFunction("readFully", ScriptingFunctions.READFULLY);
    addOwnProperty("readFully", Attribute.NOT_ENUMERABLE, value);

    final String execName = ScriptingFunctions.EXEC_NAME;
    value = ScriptFunctionImpl.makeFunction(execName, ScriptingFunctions.EXEC);
    addOwnProperty(execName, Attribute.NOT_ENUMERABLE, value);

    // Nashorn extension: global.echo (scripting-mode-only)
    // alias for "print"
    value = get("print");
    addOwnProperty("echo", Attribute.NOT_ENUMERABLE, value);

    // Nashorn extension: global.$OPTIONS (scripting-mode-only)
    final ScriptObject options = newObject();
    copyOptions(options, scriptEnv);
    addOwnProperty("$OPTIONS", Attribute.NOT_ENUMERABLE, options);

    // Nashorn extension: global.$ENV (scripting-mode-only)
    if (System.getSecurityManager() == null) {
        // do not fill $ENV if we have a security manager around
        // Retrieve current state of ENV variables.
        final ScriptObject env = newObject();
        env.putAll(System.getenv(), scriptEnv._strict);
        addOwnProperty(ScriptingFunctions.ENV_NAME, Attribute.NOT_ENUMERABLE, env);
    } else {
        addOwnProperty(ScriptingFunctions.ENV_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
    }

    // add other special properties for exec support
    addOwnProperty(ScriptingFunctions.OUT_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
    addOwnProperty(ScriptingFunctions.ERR_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
    addOwnProperty(ScriptingFunctions.EXIT_NAME, Attribute.NOT_ENUMERABLE, UNDEFINED);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:39,代码来源:Global.java


注:本文中的jdk.nashorn.internal.runtime.ScriptEnvironment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。