use of com.github.anba.es6draft.runtime.EnvironmentRecord in project es6draft by anba.
the class EvalDeclarationInstantiationGenerator method declareBlockFunctions.
private <ENVREC extends EnvironmentRecord> void declareBlockFunctions(Script evalScript, HashSet<Name> declaredFunctionOrVarNames, Variable<ExecutionContext> context, Variable<LexicalEnvironment<ENVREC>> varEnv, Variable<LexicalEnvironment<DeclarativeEnvironmentRecord>> lexEnv, Variable<ENVREC> varEnvRec, Variable<Undefined> undef, InstructionVisitor mv) {
final boolean catchVar = codegen.isEnabled(CompatibilityOption.CatchVarStatement);
int idCounter = 0;
List<FunctionDeclaration> blockFunctions = evalScript.getScope().blockFunctions();
for (FunctionDeclaration f : blockFunctions) {
Name fn = f.getName();
Jump next = null;
if (isEnclosedByLexical(evalScript)) {
// Runtime check only necessary when enclosed by lexical declarations.
f.setLegacyBlockScopeId(++idCounter);
next = new Jump();
canDeclareVarBinding(varEnv, lexEnv, fn, catchVar, next, mv);
setLegacyBlockFunction(context, f, mv);
}
if (declaredFunctionOrVarNames.add(fn)) {
BindingOp<EnvironmentRecord> op = BindingOp.LOOKUP;
Jump varAlreadyDeclared = new Jump();
op.hasBinding(varEnvRec, fn, mv);
mv.ifne(varAlreadyDeclared);
{
op.createMutableBinding(varEnvRec, fn, true, mv);
op.initializeBinding(varEnvRec, fn, undef, mv);
}
mv.mark(varAlreadyDeclared);
}
if (next != null) {
mv.mark(next);
}
}
}
use of com.github.anba.es6draft.runtime.EnvironmentRecord 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, false);
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, asm -> {
Value<DeclarativeEnvironmentRecord> benv = getLexicalEnvironmentRecord(Types.DeclarativeEnvironmentRecord, mv);
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.ScriptRuntime_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, asm -> {
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.Empty;
}
use of com.github.anba.es6draft.runtime.EnvironmentRecord in project es6draft by anba.
the class ScriptRuntime method canDeclareVarBinding.
/**
* 18.2.1.2 Runtime Semantics: EvalDeclarationInstantiation( body, varEnv, lexEnv, strict)
*
* @param varEnv
* the variable environment
* @param lexEnv
* the lexical environment
* @param name
* the function name
* @param catchVar
* {@code true} if variable redeclarations are allowed in catch clauses
* @return {@code true} if the name can be declared
*/
public static boolean canDeclareVarBinding(LexicalEnvironment<?> varEnv, LexicalEnvironment<DeclarativeEnvironmentRecord> lexEnv, String name, boolean catchVar) {
for (LexicalEnvironment<?> thisEnv = lexEnv; thisEnv != varEnv; thisEnv = thisEnv.getOuter()) {
EnvironmentRecord thisEnvRec = thisEnv.getEnvRec();
if (thisEnvRec instanceof ObjectEnvironmentRecord) {
continue;
}
DeclarativeEnvironmentRecord declEnvRec = (DeclarativeEnvironmentRecord) thisEnvRec;
if (declEnvRec.hasBinding(name) && !(catchVar && declEnvRec.isCatchEnvironment())) {
return false;
}
}
return true;
}
use of com.github.anba.es6draft.runtime.EnvironmentRecord in project es6draft by anba.
the class ScriptRuntime method GetSuperConstructor.
/**
* 12.3.5 The super Keyword
* <p>
* 12.3.5.2 Runtime Semantics: GetSuperConstructor ( )
*
* @param cx
* the execution context
* @return the super reference
*/
public static Constructor GetSuperConstructor(ExecutionContext cx) {
/* step 1 */
EnvironmentRecord envRec = cx.getThisEnvironment();
/* step 2 */
assert envRec instanceof FunctionEnvironmentRecord;
FunctionEnvironmentRecord fEnvRec = (FunctionEnvironmentRecord) envRec;
/* step 3 */
FunctionObject activeFunction = fEnvRec.getFunctionObject();
/* steps 4-5 */
ScriptObject superConstructor = activeFunction.getPrototypeOf(cx);
/* step 6 */
if (!IsConstructor(superConstructor)) {
throw newTypeError(cx, Messages.Key.NotConstructor);
}
/* step 7 */
return (Constructor) superConstructor;
}
use of com.github.anba.es6draft.runtime.EnvironmentRecord in project es6draft by anba.
the class ScriptRuntime method BindThisValue.
/**
* 12.3.5 The super Keyword
*
* @param result
* the new {@code this} binding value
* @param cx
* the execution context
*/
public static void BindThisValue(ScriptObject result, ExecutionContext cx) {
EnvironmentRecord thisEnvironment = cx.getThisEnvironment();
assert thisEnvironment instanceof FunctionEnvironmentRecord;
((FunctionEnvironmentRecord) thisEnvironment).bindThisValue(cx, result);
}
Aggregations