Java Code Examples for jdk.nashorn.internal.ir.FunctionNode#isStrict()

The following examples show how to use jdk.nashorn.internal.ir.FunctionNode#isStrict() . 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: RecompilableScriptFunctionData.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static int getDataFlags(final FunctionNode functionNode) {
    int flags = IS_CONSTRUCTOR;
    if (functionNode.isStrict()) {
        flags |= IS_STRICT;
    }
    if (functionNode.needsCallee()) {
        flags |= NEEDS_CALLEE;
    }
    if (functionNode.usesThis() || functionNode.hasEval()) {
        flags |= USES_THIS;
    }
    if (functionNode.isVarArg()) {
        flags |= IS_VARIABLE_ARITY;
    }
    if (functionNode.getKind() == FunctionNode.Kind.GETTER || functionNode.getKind() == FunctionNode.Kind.SETTER) {
        flags |= IS_PROPERTY_ACCESSOR;
    }
    return flags;
}
 
Example 2
Source File: RecompilableScriptFunctionData.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static int getDataFlags(final FunctionNode functionNode) {
    int flags = IS_CONSTRUCTOR;
    if (functionNode.isStrict()) {
        flags |= IS_STRICT;
    }
    if (functionNode.needsCallee()) {
        flags |= NEEDS_CALLEE;
    }
    if (functionNode.usesThis() || functionNode.hasEval()) {
        flags |= USES_THIS;
    }
    if (functionNode.isVarArg()) {
        flags |= IS_VARIABLE_ARITY;
    }
    if (functionNode.getKind() == FunctionNode.Kind.GETTER || functionNode.getKind() == FunctionNode.Kind.SETTER) {
        flags |= IS_PROPERTY_ACCESSOR;
    }
    return flags;
}
 
Example 3
Source File: RecompilableScriptFunctionData.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
Compiler getCompiler(final FunctionNode functionNode, final MethodType actualCallSiteType,
        final ScriptObject runtimeScope, final Map<Integer, Type> invalidatedProgramPoints,
        final int[] continuationEntryPoints) {
    final TypeMap typeMap = typeMap(actualCallSiteType);
    final Type[] paramTypes = typeMap == null ? null : typeMap.getParameterTypes(functionNodeId);
    final Object typeInformationFile = OptimisticTypesPersistence.getLocationDescriptor(source, functionNodeId, paramTypes);
    final Context context = Context.getContextTrusted();
    return new Compiler(
            context,
            context.getEnv(),
            getInstallerForNewCode(),
            functionNode.getSource(),  // source
            context.getErrorManager(),
            isStrict() | functionNode.isStrict(), // is strict
            true,       // is on demand
            this,       // compiledFunction, i.e. this RecompilableScriptFunctionData
            typeMap,    // type map
            getEffectiveInvalidatedProgramPoints(invalidatedProgramPoints, typeInformationFile), // invalidated program points
            typeInformationFile,
            continuationEntryPoints, // continuation entry points
            runtimeScope); // runtime scope
}
 
Example 4
Source File: RecompilableScriptFunctionData.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static int getDataFlags(final FunctionNode functionNode) {
    int flags = IS_CONSTRUCTOR;
    if (functionNode.isStrict()) {
        flags |= IS_STRICT;
    }
    if (functionNode.needsCallee()) {
        flags |= NEEDS_CALLEE;
    }
    if (functionNode.usesThis() || functionNode.hasEval()) {
        flags |= USES_THIS;
    }
    if (functionNode.isVarArg()) {
        flags |= IS_VARIABLE_ARITY;
    }
    if (functionNode.getKind() == FunctionNode.Kind.GETTER || functionNode.getKind() == FunctionNode.Kind.SETTER) {
        flags |= IS_PROPERTY_ACCESSOR;
    }
    return flags;
}
 
Example 5
Source File: RecompilableScriptFunctionData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static int getDataFlags(final FunctionNode functionNode) {
    int flags = IS_CONSTRUCTOR;
    if (functionNode.isStrict()) {
        flags |= IS_STRICT;
    }
    if (functionNode.needsCallee()) {
        flags |= NEEDS_CALLEE;
    }
    if (functionNode.usesThis() || functionNode.hasEval()) {
        flags |= USES_THIS;
    }
    if (functionNode.isVarArg()) {
        flags |= IS_VARIABLE_ARITY;
    }
    if (functionNode.getKind() == FunctionNode.Kind.GETTER || functionNode.getKind() == FunctionNode.Kind.SETTER) {
        flags |= IS_PROPERTY_ACCESSOR;
    }
    return flags;
}
 
Example 6
Source File: RecompilableScriptFunctionData.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static int getDataFlags(final FunctionNode functionNode) {
    int flags = IS_CONSTRUCTOR;
    if (functionNode.isStrict()) {
        flags |= IS_STRICT;
    }
    if (functionNode.needsCallee()) {
        flags |= NEEDS_CALLEE;
    }
    if (functionNode.usesThis() || functionNode.hasEval()) {
        flags |= USES_THIS;
    }
    if (functionNode.isVarArg()) {
        flags |= IS_VARIABLE_ARITY;
    }
    if (functionNode.getKind() == FunctionNode.Kind.GETTER || functionNode.getKind() == FunctionNode.Kind.SETTER) {
        flags |= IS_PROPERTY_ACCESSOR;
    }
    if (functionNode.isMethod() || functionNode.isClassConstructor()) {
        flags |= IS_ES6_METHOD;
    }
    return flags;
}
 
Example 7
Source File: RecompilableScriptFunctionData.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static int getDataFlags(final FunctionNode functionNode) {
    int flags = IS_CONSTRUCTOR;
    if (functionNode.isStrict()) {
        flags |= IS_STRICT;
    }
    if (functionNode.needsCallee()) {
        flags |= NEEDS_CALLEE;
    }
    if (functionNode.usesThis() || functionNode.hasEval()) {
        flags |= USES_THIS;
    }
    if (functionNode.isVarArg()) {
        flags |= IS_VARIABLE_ARITY;
    }
    if (functionNode.getKind() == FunctionNode.Kind.GETTER || functionNode.getKind() == FunctionNode.Kind.SETTER) {
        flags |= IS_PROPERTY_ACCESSOR;
    }
    return flags;
}
 
Example 8
Source File: RecompilableScriptFunctionData.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor - public as scripts use it
 *
 * @param functionNode       functionNode that represents this function code
 * @param installer          installer for code regeneration versions of this function
 * @param allocatorClassName name of our allocator class, will be looked up dynamically if used as a constructor
 * @param allocatorMap       allocator map to seed instances with, when constructing
 */
public RecompilableScriptFunctionData(final FunctionNode functionNode, final CodeInstaller<ScriptEnvironment> installer, final String allocatorClassName, final PropertyMap allocatorMap) {
    super(functionNode.isAnonymous() ?
            "" :
            functionNode.getIdent().getName(),
          functionNode.getParameters().size(),
          functionNode.isStrict(),
          false,
          true);

    this.functionNode       = functionNode;
    this.source             = functionNode.getSource();
    this.token              = tokenFor(functionNode);
    this.installer          = installer;
    this.allocatorClassName = allocatorClassName;
    this.allocatorMap       = allocatorMap;
}
 
Example 9
Source File: RecompilableScriptFunctionData.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
private static int getDataFlags(final FunctionNode functionNode) {
    int flags = IS_CONSTRUCTOR;
    if (functionNode.isStrict()) {
        flags |= IS_STRICT;
    }
    if (functionNode.needsCallee()) {
        flags |= NEEDS_CALLEE;
    }
    if (functionNode.usesThis() || functionNode.hasEval()) {
        flags |= USES_THIS;
    }
    if (functionNode.isVarArg()) {
        flags |= IS_VARIABLE_ARITY;
    }
    if (functionNode.getKind() == FunctionNode.Kind.GETTER || functionNode.getKind() == FunctionNode.Kind.SETTER) {
        flags |= IS_PROPERTY_ACCESSOR;
    }
    return flags;
}
 
Example 10
Source File: RecompilableScriptFunctionData.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor - public as scripts use it
 *
 * @param functionNode       functionNode that represents this function code
 * @param installer          installer for code regeneration versions of this function
 * @param allocatorClassName name of our allocator class, will be looked up dynamically if used as a constructor
 * @param allocatorMap       allocator map to seed instances with, when constructing
 */
public RecompilableScriptFunctionData(final FunctionNode functionNode, final CodeInstaller<ScriptEnvironment> installer, final String allocatorClassName, final PropertyMap allocatorMap) {
    super(functionName(functionNode),
          functionNode.getParameters().size(),
          functionNode.isStrict(),
          false,
          true);

    this.functionNode       = functionNode;
    this.source             = functionNode.getSource();
    this.token              = tokenFor(functionNode);
    this.installer          = installer;
    this.allocatorClassName = allocatorClassName;
    this.allocatorMap       = allocatorMap;
}
 
Example 11
Source File: Compiler.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void initCompiler(final FunctionNode functionNode) {
    this.strict        = strict || functionNode.isStrict();
    final StringBuilder sb = new StringBuilder();
    sb.append(functionNode.uniqueName(DEFAULT_SCRIPT_NAME.symbolName() + lazyTag(functionNode))).
            append('$').
            append(safeSourceName(functionNode.getSource()));
    this.source = functionNode.getSource();
    this.scriptName = sb.toString();
}
 
Example 12
Source File: Compiler.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
private void initCompiler(final FunctionNode functionNode) {
    this.strict        = strict || functionNode.isStrict();
    final StringBuilder sb = new StringBuilder();
    sb.append(functionNode.uniqueName(DEFAULT_SCRIPT_NAME.symbolName() + lazyTag(functionNode))).
            append('$').
            append(safeSourceName(functionNode.getSource()));
    this.source = functionNode.getSource();
    this.scriptName = sb.toString();
}
 
Example 13
Source File: RecompilableScriptFunctionData.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor - public as scripts use it
 *
 * @param functionNode       functionNode that represents this function code
 * @param installer          installer for code regeneration versions of this function
 * @param allocatorClassName name of our allocator class, will be looked up dynamically if used as a constructor
 * @param allocatorMap       allocator map to seed instances with, when constructing
 */
public RecompilableScriptFunctionData(final FunctionNode functionNode, final CodeInstaller<ScriptEnvironment> installer, final String allocatorClassName, final PropertyMap allocatorMap) {
    super(functionName(functionNode),
          functionNode.getParameters().size(),
          functionNode.isStrict(),
          false,
          true);

    this.functionNode       = functionNode;
    this.source             = functionNode.getSource();
    this.token              = tokenFor(functionNode);
    this.installer          = installer;
    this.allocatorClassName = allocatorClassName;
    this.allocatorMap       = allocatorMap;
}
 
Example 14
Source File: Compiler.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void initCompiler(final FunctionNode functionNode) {
    this.strict        = strict || functionNode.isStrict();
    final StringBuilder sb = new StringBuilder();
    sb.append(functionNode.uniqueName(DEFAULT_SCRIPT_NAME.symbolName() + lazyTag(functionNode))).
            append('$').
            append(safeSourceName(functionNode.getSource()));
    this.source = functionNode.getSource();
    this.scriptName = sb.toString();
}
 
Example 15
Source File: CodeGeneratorLexicalContext.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
static boolean isFunctionDynamicScope(FunctionNode fn) {
    return fn.hasEval() && !fn.isStrict();
}
 
Example 16
Source File: CodeGeneratorLexicalContext.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
static boolean isFunctionDynamicScope(FunctionNode fn) {
    return fn.hasEval() && !fn.isStrict();
}
 
Example 17
Source File: CodeGeneratorLexicalContext.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
static boolean isFunctionDynamicScope(FunctionNode fn) {
    return fn.hasEval() && !fn.isStrict();
}
 
Example 18
Source File: Context.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
private synchronized Class<?> compile(final Source source, final ErrorManager errMan, final boolean strict) {
    // start with no errors, no warnings.
    errMan.reset();

    Class<?> script = findCachedClass(source);
    if (script != null) {
        final DebugLogger log = getLogger(Compiler.class);
        if (log.isEnabled()) {
            log.fine(new RuntimeEvent<>(Level.INFO, source), "Code cache hit for ", source, " avoiding recompile.");
        }
        return script;
    }

    StoredScript storedScript = null;
    FunctionNode functionNode = null;
    // Don't use code store if optimistic types is enabled but lazy compilation is not.
    // This would store a full script compilation with many wrong optimistic assumptions that would
    // do more harm than good on later runs with both optimistic types and lazy compilation enabled.
    final boolean useCodeStore = codeStore != null && !env._parse_only && (!env._optimistic_types || env._lazy_compilation);
    final String cacheKey = useCodeStore ? CodeStore.getCacheKey("script", null) : null;

    if (useCodeStore) {
        storedScript = codeStore.load(source, cacheKey);
    }

    if (storedScript == null) {
        if (env._dest_dir != null) {
            source.dump(env._dest_dir);
        }

        functionNode = new Parser(env, source, errMan, strict, getLogger(Parser.class)).parse();

        if (errMan.hasErrors()) {
            return null;
        }

        if (env._print_ast || functionNode.getFlag(FunctionNode.IS_PRINT_AST)) {
            getErr().println(new ASTWriter(functionNode));
        }

        if (env._print_parse || functionNode.getFlag(FunctionNode.IS_PRINT_PARSE)) {
            getErr().println(new PrintVisitor(functionNode, true, false));
        }
    }

    if (env._parse_only) {
        return null;
    }

    final URL          url    = source.getURL();
    final ScriptLoader loader = env._loader_per_compile ? createNewLoader() : scriptLoader;
    final CodeSource   cs     = new CodeSource(url, (CodeSigner[])null);
    final CodeInstaller<ScriptEnvironment> installer = new ContextCodeInstaller(this, loader, cs);

    if (storedScript == null) {
        final CompilationPhases phases = Compiler.CompilationPhases.COMPILE_ALL;

        final Compiler compiler = new Compiler(
                this,
                env,
                installer,
                source,
                errMan,
                strict | functionNode.isStrict());

        final FunctionNode compiledFunction = compiler.compile(functionNode, phases);
        if (errMan.hasErrors()) {
            return null;
        }
        script = compiledFunction.getRootClass();
        compiler.persistClassInfo(cacheKey, compiledFunction);
    } else {
        Compiler.updateCompilationId(storedScript.getCompilationId());
        script = storedScript.installScript(source, installer);
    }

    cacheClass(source, script);
    return script;
}