diff --git a/classes.js b/classes.js index d366296d..978a7bdf 100644 --- a/classes.js +++ b/classes.js @@ -73,7 +73,7 @@ Classes.prototype.getEntryPoint = function(className, methodName) { ACCESS_FLAGS.isStatic(methods[i].access_flags) && !ACCESS_FLAGS.isNative(methods[i].access_flags) && cp[methods[i].name_index].bytes === methodName) { - return new Frame(classInfo, methods[i]); + return methods[i]; } } } @@ -87,7 +87,7 @@ Classes.prototype.initClass = function(className) { if (!clinit) return; LOG.debug("call " + className + ". ..."); - clinit.run(THREADS.current.stack); + new Frame(clinit).run(THREADS.current.stack); } Classes.prototype.getClass = function(className, initialize) { @@ -124,7 +124,7 @@ Classes.prototype.getMethod = function(className, methodName, signature, staticF if (ACCESS_FLAGS.isNative(methods[i].access_flags)) { return NATIVE.getMethod(className, methodName, signature); } - return new Frame(classInfo, methods[i]); + return methods[i]; } } } diff --git a/classfile/classinfo.js b/classfile/classinfo.js index 84da52a6..a6923958 100644 --- a/classfile/classinfo.js +++ b/classfile/classinfo.js @@ -5,7 +5,7 @@ var ClassInfo = function(classBytes) { if (this instanceof ClassInfo) { - this.classImage = getClassImage(classBytes); + this.classImage = getClassImage(classBytes, this); } else { return new ClassInfo(classBytes); } @@ -51,7 +51,36 @@ ClassInfo.prototype.getClasses = function() { return classes; } -var getClassImage = function(classBytes) { +var FieldInfo = function(classInfo, access_flags, name_index, descriptor_index) { + this.classInfo = classInfo; + this.access_flags = access_flags; + this.name_index = name_index; + this.descriptor_index = descriptor_index; + this.attributes = []; +} + +var MethodInfo = function(classInfo, access_flags, name_index, signature_index) { + this.classInfo = classInfo; + this.access_flags = access_flags; + this.name_index = name_index; + this.signature_index = signature_index; + this.attributes = []; +} + +var AttributeInfo = function(attribute_name_index, attribute_length, info) { + this.attribute_name_index = attribute_name_index; + this.attribute_length = attribute_length; + this.info = info; +} + +var ExceptionInfo = function(start_pc, end_pc, handler_pc, catch_type) { + this.start_pc = start_pc; + this.end_pc = end_pc; + this.handler_pc = handler_pc; + this.catch_type = catch_type; +} + +var getClassImage = function(classBytes, classInfo) { var classImage = {}; var getAttribues = function(attribute_name_index, bytes) { @@ -67,7 +96,7 @@ var getClassImage = function(classBytes) { case TAGS.CONSTANT_Integer: case TAGS.CONSTANT_String: attribute.type = ATTRIBUTE_TYPES.ConstantValue; - attribute.constantvalue_index = reader.read16(); + attribute.info = reader.read16(); return attribute; case TAGS.CONSTANT_Utf8: @@ -86,7 +115,7 @@ var getClassImage = function(classBytes) { var end_pc = reader.read16(); var handler_pc= reader.read16(); var catch_type = reader.read16(); - attribute.exception_table.push({start_pc:start_pc,end_pc:end_pc,handler_pc:handler_pc,catch_type:catch_type }); + attribute.exception_table.push(new ExceptionInfo(start_pc, end_pc, handler_pc, catch_type)); } var attributes_count = reader.read16(); @@ -95,7 +124,7 @@ var getClassImage = function(classBytes) { var attribute_name_index = reader.read16(); var attribute_length = reader.read32(); var info = reader.readBytes(attribute_length); - attribute.attributes.push({ attribute_name_index: attribute_name_index, attribute_length: attribute_length, info: info }); + attribute.attributes.push(new AttributeInfo(attribute_name_index, attribute_length, info)); } return attribute; @@ -224,22 +253,12 @@ var getClassImage = function(classBytes) { var name_index = reader.read16(); var descriptor_index = reader.read16(); var attributes_count = reader.read16(); - var field_info = { - access_flags: access_flags, - name_index: name_index, - descriptor_index: descriptor_index, - attributes_count: attributes_count, - attributes: [] - } + var field_info = new FieldInfo(access_flags, name_index, descriptor_index); for(var j=0; j