use of com.github.anba.es6draft.ast.scope.TopLevelScope in project es6draft by anba.
the class ExpressionGenerator method isGlobalThis.
private static boolean isGlobalThis(Scope currentScope) {
for (Scope scope = currentScope; ; ) {
TopLevelScope top = scope.getTop();
TopLevelNode<?> node = top.getNode();
if (node instanceof Script) {
return ((Script) node).isGlobalThis();
}
if (node instanceof Module) {
return true;
}
assert node instanceof FunctionNode : "class=" + node.getClass();
if (((FunctionNode) node).getThisMode() != FunctionNode.ThisMode.Lexical) {
return false;
}
scope = top.getEnclosingScope();
}
}
use of com.github.anba.es6draft.ast.scope.TopLevelScope in project es6draft by anba.
the class StatementGenerator method visit.
/**
* 14.1.20 Runtime Semantics: Evaluation
*/
@Override
public Completion visit(FunctionDeclaration node, CodeVisitor mv) {
/* B.3.3 Block-Level Function Declarations Web Legacy Compatibility Semantics */
if (node.isLegacyBlockScoped()) {
Name name = node.getIdentifier().getName();
TopLevelScope top = mv.getScope().getTop();
if (mv.isFunction()) {
assert top instanceof FunctionScope;
Name varName = ((FunctionScope) top).variableScope().resolveName(name);
assert varName != null && name != varName;
/* step 1.a.ii.3.1 */
Value<DeclarativeEnvironmentRecord> fenv = getVariableEnvironmentRecord(Types.DeclarativeEnvironmentRecord, mv);
/* steps 1.a.ii.3.5-6 */
BindingOp.of(fenv, varName).setMutableBinding(fenv, varName, __ -> {
/* step 1.a.ii.3.2 */
Value<DeclarativeEnvironmentRecord> benv = getLexicalEnvironmentRecord(Types.DeclarativeEnvironmentRecord, mv);
/* steps 1.a.ii.3.3-4 */
BindingOp.of(benv, name).getBindingValue(benv, name, false, mv);
}, false, mv);
} else {
assert top instanceof ScriptScope;
Name varName = name;
int functionId = node.getLegacyBlockScopeId();
Jump isLegacyScoped = null;
if (functionId > 0) {
isLegacyScoped = new Jump();
mv.loadExecutionContext();
mv.iconst(functionId);
mv.invoke(Methods.DeclarationOperations_isLegacyBlockFunction);
mv.ifeq(isLegacyScoped);
}
// The variable environment record is either:
// 1. The global environment record for global (eval) scripts.
// 2. Or a (function) declarative environment record for eval in functions.
// 3. Or a script-context environment record for eval in JSR-223 scripting.
Value<EnvironmentRecord> genv = getVariableEnvironmentRecord(Types.EnvironmentRecord, mv);
BindingOp.of(genv, varName).setMutableBinding(genv, varName, __ -> {
Value<DeclarativeEnvironmentRecord> benv = getLexicalEnvironmentRecord(Types.DeclarativeEnvironmentRecord, mv);
BindingOp.of(benv, name).getBindingValue(benv, name, false, mv);
}, false, mv);
if (isLegacyScoped != null) {
mv.mark(isLegacyScoped);
}
}
}
/* step 1 */
return Completion.Normal;
}
use of com.github.anba.es6draft.ast.scope.TopLevelScope in project es6draft by anba.
the class ExpressionGenerator method isEnclosedByLexicalDeclaration.
private boolean isEnclosedByLexicalDeclaration(Scope currentScope) {
final boolean catchVar = codegen.isEnabled(CompatibilityOption.CatchVarStatement);
TopLevelScope top = currentScope.getTop();
for (Scope scope : currentScope) {
if (scope instanceof BlockScope) {
if (catchVar) {
ScopedNode node = scope.getNode();
if (node instanceof CatchClause && ((CatchClause) node).getCatchParameter() instanceof BindingIdentifier) {
continue;
}
}
if (!((BlockScope) scope).lexicallyDeclaredNames().isEmpty()) {
return true;
}
} else if (scope == top) {
break;
}
}
if (!top.lexicallyDeclaredNames().isEmpty()) {
TopLevelNode<?> topNode = top.getNode();
if (topNode instanceof Script) {
return ((Script) topNode).isEvalScript();
}
return true;
}
return codegen.isEnabled(Parser.Option.EnclosedByLexicalDeclaration);
}
Aggregations