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 { private void generateGetClass(GeneratorContext context, SourceWriter writer) throws IOException {
String thisArg = context.getParameterName(0); 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) { 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 { 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("for (var field in obj) {").softNewLine().indent();
writer.append("if (!obj.hasOwnProperty(field)) {").softNewLine().indent(); writer.append("if (!obj.hasOwnProperty(field)) {").softNewLine().indent();
writer.append("continue;").softNewLine().outdent().append("}").softNewLine(); 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 { private void generateGetLength(GeneratorContext context, SourceWriter writer) throws IOException {
String array = context.getParameterName(1); 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(); .softNewLine().indent();
String clsName = "java.lang.IllegalArgumentException"; String clsName = "java.lang.IllegalArgumentException";
MethodReference cons = new MethodReference(clsName, new MethodDescriptor("<init>", ValueType.VOID)); 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 { public void render(ClassNode cls) throws RenderingException {
try { try {
writer.appendClass(cls.getName()).ws().append("=").ws().append("function()").ws().append("{") writer.append("function ").appendClass(cls.getName()).append("()").ws().append("{")
.indent().softNewLine(); .indent().softNewLine();
for (FieldNode field : cls.getFields()) { for (FieldNode field : cls.getFields()) {
if (field.getModifiers().contains(NodeModifier.STATIC)) { 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() writer.append("this.").appendField(new FieldReference(cls.getName(), field.getName())).ws()
.append("=").ws().append(constantToString(value)).append(";").softNewLine(); .append("=").ws().append(constantToString(value)).append(";").softNewLine();
} }
writer.append("this.$class").ws().append("=").ws().appendClass(cls.getName()).append(";").softNewLine();
writer.outdent().append("}").newLine(); writer.outdent().append("}").newLine();
for (FieldNode field : cls.getFields()) { 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 ") writer.appendClass(cls.getName()).append(".prototype").ws().append("=").ws().append("new ")
.append(cls.getParentName() != null ? naming.getNameFor(cls.getParentName()) : .append(cls.getParentName() != null ? naming.getNameFor(cls.getParentName()) :
"Object").append("();").softNewLine(); "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.appendClass(cls.getName()).append(".$meta").ws().append("=").ws().append("{").ws();
writer.append("name").ws().append(":").ws().append("\"").append(cls.getName()).append("\",").ws(); writer.append("name").ws().append(":").ws().append("\"").append(cls.getName()).append("\",").ws();
writer.append("primitive").ws().append(":").ws().append("false,").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; return a > b ? 1 : a < b ? -1 : 0;
} }
$rt_isInstance = function(obj, cls) { $rt_isInstance = function(obj, cls) {
return $rt_isAssignable(obj.$class, cls); return $rt_isAssignable(obj.constructor, cls);
} }
$rt_isAssignable = function(from, to) { $rt_isAssignable = function(from, to) {
if (from === to) { if (from === to) {
@ -100,9 +100,9 @@ $rt_arraycls = function(cls) {
if (cls.$array == undefined) { if (cls.$array == undefined) {
var arraycls = function(data) { var arraycls = function(data) {
this.data = data; this.data = data;
this.$class = arraycls;
}; };
arraycls.prototype = new ($rt_objcls())(); arraycls.prototype = new ($rt_objcls())();
arraycls.prototype.constructor = arraycls;
arraycls.$meta = { item : cls, supertypes : [$rt_objcls()], primitive : false }; arraycls.$meta = { item : cls, supertypes : [$rt_objcls()], primitive : false };
cls.$array = arraycls; cls.$array = arraycls;
} }

View File

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