use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject in project es6draft by anba.
the class DefaultCodeGenerator method ClassDefinitionEvaluation.
/**
* 14.5.14 Runtime Semantics: ClassDefinitionEvaluation
*
* @param def
* the class definition node
* @param className
* the class name or {@code null} if not present
* @param mv
* the code visitor
*/
protected final void ClassDefinitionEvaluation(ClassDefinition def, Name className, CodeVisitor mv) {
mv.enterVariableScope();
Variable<ArrayList<Callable>> classDecorators = null;
boolean hasClassDecorators = !def.getDecorators().isEmpty();
if (hasClassDecorators) {
classDecorators = newDecoratorVariable("classDecorators", mv);
evaluateDecorators(classDecorators, def.getDecorators(), mv);
}
mv.enterClassDefinition();
// step 1 (not applicable)
// steps 2-4
BlockScope scope = def.getScope();
assert (scope != null && scope.isPresent()) == (className != null);
Variable<DeclarativeEnvironmentRecord> classScopeEnvRec = null;
if (className != null) {
// stack: [] -> [classScope]
newDeclarativeEnvironment(scope, mv);
classScopeEnvRec = mv.newVariable("classScopeEnvRec", DeclarativeEnvironmentRecord.class);
getEnvRec(classScopeEnvRec, mv);
// stack: [classScope] -> [classScope]
Name innerName = scope.resolveName(className, false);
BindingOp<DeclarativeEnvironmentRecord> op = BindingOp.of(classScopeEnvRec, innerName);
op.createImmutableBinding(classScopeEnvRec, innerName, true, mv);
// stack: [classScope] -> []
pushLexicalEnvironment(mv);
mv.enterScope(def);
}
// steps 5-7
// stack: [] -> [<constructorParent,proto>]
Expression classHeritage = def.getHeritage();
if (classHeritage == null) {
mv.loadExecutionContext();
mv.invoke(Methods.ScriptRuntime_getDefaultClassProto);
} else if (classHeritage instanceof NullLiteral) {
mv.loadExecutionContext();
mv.invoke(Methods.ScriptRuntime_getClassProto_Null);
} else {
expressionBoxed(classHeritage, mv);
mv.loadExecutionContext();
mv.lineInfo(def);
mv.invoke(Methods.ScriptRuntime_getClassProto);
}
// stack: [<constructorParent,proto>] -> [<constructorParent,proto>]
Variable<OrdinaryObject> proto = mv.newVariable("proto", OrdinaryObject.class);
mv.dup();
mv.aload(1, Types.ScriptObject);
mv.checkcast(Types.OrdinaryObject);
mv.store(proto);
// stack: [<constructorParent,proto>] -> [constructorParent, proto]
mv.aload(0, Types.ScriptObject);
mv.load(proto);
// steps 8-9
// stack: [constructorParent, proto] -> [constructorParent, proto, <rti>]
MethodDefinition constructor = ConstructorMethod(def);
assert constructor != null;
MethodName method = codegen.compile(def);
// Runtime Semantics: Evaluation -> MethodDefinition
mv.invoke(method);
// step 10 (not applicable)
// steps 11-18
// stack: [constructorParent, proto, <rti>] -> [F]
mv.iconst(classHeritage != null);
mv.loadExecutionContext();
mv.lineInfo(def);
mv.invoke(Methods.ScriptRuntime_EvaluateConstructorMethod);
// stack: [F] -> []
Variable<OrdinaryConstructorFunction> F = mv.newVariable("F", OrdinaryConstructorFunction.class);
mv.store(F);
Variable<ArrayList<Object>> methodDecorators = null;
boolean hasMethodDecorators = HasDecorators(def);
if (hasMethodDecorators) {
methodDecorators = newDecoratorVariable("methodDecorators", mv);
}
if (!constructor.getDecorators().isEmpty()) {
addDecoratorObject(methodDecorators, proto, mv);
evaluateDecorators(methodDecorators, constructor.getDecorators(), mv);
addDecoratorKey(methodDecorators, "constructor", mv);
}
// steps 19-21
ClassPropertyEvaluation(codegen, def.getProperties(), F, proto, methodDecorators, mv);
if (hasClassDecorators) {
mv.load(F);
mv.load(classDecorators);
mv.loadExecutionContext();
mv.lineInfo(def);
mv.invoke(Methods.ScriptRuntime_EvaluateClassDecorators);
}
if (hasMethodDecorators) {
mv.load(methodDecorators);
mv.loadExecutionContext();
mv.lineInfo(def);
mv.invoke(Methods.ScriptRuntime_EvaluateClassMethodDecorators);
}
// steps 22-23 (moved)
if (className != null) {
// stack: [] -> []
Name innerName = scope.resolveName(className, false);
BindingOp<DeclarativeEnvironmentRecord> op = BindingOp.of(classScopeEnvRec, innerName);
op.initializeBinding(classScopeEnvRec, innerName, F, mv);
mv.exitScope();
popLexicalEnvironment(mv);
}
// stack: [] -> [F]
mv.load(F);
mv.exitVariableScope();
// step 24 (return F)
mv.exitClassDefinition();
}
use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject in project es6draft by anba.
the class CodeGenerator method compile.
MethodName compile(PropertyDefinitionsMethod node, boolean hasDecorators, CodeVisitor mv) {
if (!isCompiled(node)) {
MethodCode method = newMethod(node);
PropertyDefinitionsCodeVisitor body = new PropertyDefinitionsCodeVisitor(node, method, mv);
body.lineInfo(node);
body.begin();
Variable<OrdinaryObject> object = body.getObjectParameter();
Variable<ArrayList<Object>> decorators = hasDecorators ? body.getDecoratorsParameter() : null;
PropertyGenerator propgen = propertyGenerator(decorators);
for (PropertyDefinition property : node.getProperties()) {
body.load(object);
property.accept(propgen, body);
}
body._return();
body.end();
}
return methodDesc(node);
}
use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject in project es6draft by anba.
the class CodeGenerator method compile.
MethodName compile(MethodDefinitionsMethod node, boolean hasDecorators, CodeVisitor mv) {
if (!isCompiled(node)) {
MethodCode method = newMethod(node);
MethodDefinitionsCodeVisitor body = new MethodDefinitionsCodeVisitor(node, method, mv);
body.lineInfo(node);
body.begin();
Variable<OrdinaryConstructorFunction> function = body.getFunctionParameter();
Variable<OrdinaryObject> proto = body.getPrototypeParameter();
Variable<ArrayList<Object>> decorators = hasDecorators ? body.getDecoratorsParameter() : null;
ClassPropertyEvaluation(this, node.getProperties(), function, proto, decorators, body);
body._return();
body.end();
}
return methodDesc(node);
}
use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject in project es6draft by anba.
the class Interpreter method visit.
@Override
public Object visit(ObjectLiteral node, ExecutionContext cx) {
OrdinaryObject obj = ObjectCreate(cx, Intrinsics.ObjectPrototype);
for (PropertyDefinition propertyDefinition : node.getProperties()) {
assert propertyDefinition instanceof PropertyValueDefinition;
PropertyValueDefinition propValDef = (PropertyValueDefinition) propertyDefinition;
PropertyName propertyName = propValDef.getPropertyName();
Expression propertyValue = propValDef.getPropertyValue();
String propName = PropName(propertyName);
long propIndex = propName != null ? IndexedMap.toIndex(propName) : -1;
assert propName != null && !(propertyName instanceof ComputedPropertyName);
Object value = GetValue(propertyValue.accept(this, cx), cx);
if ("__proto__".equals(propName) && cx.getRealm().isEnabled(CompatibilityOption.ProtoInitializer)) {
ScriptRuntime.defineProtoProperty(obj, value, cx);
} else if (IndexedMap.isIndex(propIndex)) {
ScriptRuntime.defineProperty(obj, propIndex, value, cx);
} else {
ScriptRuntime.defineProperty(obj, propName, value, cx);
}
}
return obj;
}
use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject in project es6draft by anba.
the class Properties method createPrototype.
private static void createPrototype(Realm realm, OrdinaryObject target, Object rawValue) {
Object value = resolveValue(realm, rawValue);
assert value == null || value instanceof ScriptObject;
target.infallibleSetPrototype((ScriptObject) value);
}
Aggregations