Remove .$class property and use built-in .constructor instead

This commit is contained in:
konsoletyper 2014-01-31 10:49:01 +04:00
parent 4c70cf6828
commit bc68602dae
5 changed files with 10 additions and 9 deletions

View File

@ -73,7 +73,7 @@ public class ObjectNativeGenerator implements Generator, DependencyPlugin {
private void generateGetClass(GeneratorContext context, SourceWriter writer) throws IOException {
String thisArg = context.getParameterName(0);
writer.append("return $rt_cls(").append(thisArg).append(".$class);").softNewLine();
writer.append("return $rt_cls(").append(thisArg).append(".constructor);").softNewLine();
}
private void achieveGetClass(DependencyChecker checker, MethodReference method) {
@ -89,7 +89,7 @@ public class ObjectNativeGenerator implements Generator, DependencyPlugin {
}
private void generateClone(GeneratorContext context, SourceWriter writer) throws IOException {
writer.append("var copy = new ").append(context.getParameterName(0)).append(".$class();").softNewLine();
writer.append("var copy = new ").append(context.getParameterName(0)).append(".constructor();").softNewLine();
writer.append("for (var field in obj) {").softNewLine().indent();
writer.append("if (!obj.hasOwnProperty(field)) {").softNewLine().indent();
writer.append("continue;").softNewLine().outdent().append("}").softNewLine();

View File

@ -50,7 +50,7 @@ public class ArrayNativeGenerator implements Generator, DependencyPlugin {
private void generateGetLength(GeneratorContext context, SourceWriter writer) throws IOException {
String array = context.getParameterName(1);
writer.append("if (" + array + " === null || " + array + " .$class.$meta.item === undefined) {")
writer.append("if (" + array + " === null || " + array + ".constructor.$meta.item === undefined) {")
.softNewLine().indent();
String clsName = "java.lang.IllegalArgumentException";
MethodReference cons = new MethodReference(clsName, new MethodDescriptor("<init>", ValueType.VOID));

View File

@ -122,7 +122,7 @@ public class Renderer implements ExprVisitor, StatementVisitor {
public void render(ClassNode cls) throws RenderingException {
try {
writer.appendClass(cls.getName()).ws().append("=").ws().append("function()").ws().append("{")
writer.append("function ").appendClass(cls.getName()).append("()").ws().append("{")
.indent().softNewLine();
for (FieldNode field : cls.getFields()) {
if (field.getModifiers().contains(NodeModifier.STATIC)) {
@ -135,7 +135,6 @@ public class Renderer implements ExprVisitor, StatementVisitor {
writer.append("this.").appendField(new FieldReference(cls.getName(), field.getName())).ws()
.append("=").ws().append(constantToString(value)).append(";").softNewLine();
}
writer.append("this.$class").ws().append("=").ws().appendClass(cls.getName()).append(";").softNewLine();
writer.outdent().append("}").newLine();
for (FieldNode field : cls.getFields()) {
@ -154,6 +153,8 @@ public class Renderer implements ExprVisitor, StatementVisitor {
writer.appendClass(cls.getName()).append(".prototype").ws().append("=").ws().append("new ")
.append(cls.getParentName() != null ? naming.getNameFor(cls.getParentName()) :
"Object").append("();").softNewLine();
writer.appendClass(cls.getName()).append(".prototype.constructor").ws().append("=").ws()
.appendClass(cls.getName()).append(';').softNewLine();
writer.appendClass(cls.getName()).append(".$meta").ws().append("=").ws().append("{").ws();
writer.append("name").ws().append(":").ws().append("\"").append(cls.getName()).append("\",").ws();
writer.append("primitive").ws().append(":").ws().append("false,").ws();

View File

@ -21,7 +21,7 @@ $rt_compare = function(a, b) {
return a > b ? 1 : a < b ? -1 : 0;
}
$rt_isInstance = function(obj, cls) {
return $rt_isAssignable(obj.$class, cls);
return $rt_isAssignable(obj.constructor, cls);
}
$rt_isAssignable = function(from, to) {
if (from === to) {
@ -100,9 +100,9 @@ $rt_arraycls = function(cls) {
if (cls.$array == undefined) {
var arraycls = function(data) {
this.data = data;
this.$class = arraycls;
};
arraycls.prototype = new ($rt_objcls())();
arraycls.prototype.constructor = arraycls;
arraycls.$meta = { item : cls, supertypes : [$rt_objcls()], primitive : false };
cls.$array = arraycls;
}

View File

@ -208,8 +208,8 @@ JUnitClient.run = function() {
message.status = "ok";
} catch (e) {
message.status = "exception";
if (e.$javaException && e.$javaException.$class && e.$javaException.$class.$meta) {
message.exception = e.$javaException.$class.$meta.name;
if (e.$javaException && e.$javaException.constructor.$meta) {
message.exception = e.$javaException.constructor.$meta.name;
}
message.stack = e.stack;
}