diff --git a/constantPool.js b/constantPool.js index 1097067..4534cdd 100644 --- a/constantPool.js +++ b/constantPool.js @@ -10,49 +10,158 @@ var CONSTANT_Double = 6; var CONSTANT_NameAndType = 12; var CONSTANT_Utf8 = 1; -constUtf8 = function(){ +// constant pool members + +var constUtf8 = function(){ this.str = null; - this.read = ( dStream ) { - StringBuffer strBuf; - int len, charCnt; - byte one_byte; - char one_char; + this.id = CONSTANT_Utf8; + this.read = function ( dStream ) { + var strBuf; + var len, charCnt; + var one_byte; + var one_char; one_char = '\u0000'; - len = readU2( dStream ); - strBuf = new StringBuffer(); + len = dStream.getU2(); + strBuf = ""; charCnt = 0; while (charCnt < len) { - one_byte = (byte)readU1( dStream ); + one_byte = dStream .getU1(); charCnt++; if ((one_byte >> 7) == 1) { - short tmp; + var tmp; // its a multi-byte character - tmp = (short)(one_byte & 0x3f); // Bits 5..0 (six bits) + tmp = (one_byte & 0x3f); // Bits 5..0 (six bits) // read the next byte - one_byte = (byte)readU1( dStream ); + one_byte = dStream .getU1(); charCnt++; - tmp = (short)(tmp | ((one_byte & 0x3f) << 6)); + tmp = (tmp | ((one_byte & 0x3f) << 6)); if ((one_byte >> 6) == 0x2) { // We have 12 bits so far, get bits 15..12 - one_byte = (byte)readU1( dStream ); + one_byte = dStream .getU1(); charCnt++; - one_byte = (byte)(one_byte & 0xf); - tmp = (short)(tmp | (one_byte << 12)); + one_byte = (one_byte & 0xf); + tmp = (tmp | (one_byte << 12)); } - one_char = (char)tmp; + one_char = tmp; } else { - one_char = (char)one_byte; + one_char = one_byte; } - strBuf.append(one_char); + strBuf += String.fromCharCode(one_char); } // while - this.str = strBuf.toString(); + + this.str = strBuf.toString(); } // read + return this; }; -allocConstEntry = function(tag){ + +var constDummy = function(){ + this.read = function (stream){}; + return this; +} + +var constInt = function(){ + this.value = null; + this.id = CONSTANT_Integer; + this.read = function ( dSStream ){ + this.value = dStream.getU4(); + } +}; + +var constFloat = function(){ + this.value = null; + this.id = CONSTANT_Float; + this.read = function ( dSStream ){ + this.value = dStream.getU4(); + } +}; + +var constLong = function(){ + this.high = null; + this.low = null; + this.id = CONSTANT_Long; + this.read = function (dStream){ + this.high = dStream.getU4(); + this.low = dStream.getU4(); + } +}; + +var constDouble = function(){ + this.high = null; + this.low = null; + this.id = CONSTANT_Double; + this.read = function (dStream){ + this.high = dStream.getU4(); + this.low = dStream.getU4(); + } +}; + +var constClass = function(){ + this.name_index = null; + this.id = CONSTANT_Class; + this.read = function(dStream){ + this.name_index = dstream.getU2(); + } +}; + +var constString = function(){ + this.string_index = null; + this.id = CONSTANT_String; + this.read = function(dStream){ + this.string_index = dstream.getU2(); + } +}; + +var constString = function(){ + this.string_index = null; + this.id = CONSTANT_String; + this.read = function(dStream){ + this.string_index = dstream.getU2(); + } +}; + +var constRef = function(){ + this.class_index = null; + this.name_and_type_index = null; + this.read = function(dStream){ + this.class_index = dStream.getU2(); + this.name_and_type_index = dStream.getU2(); + }; +}; + +var constFieldRef = function(){ + var temp = new constRef(); + temp.id = CONSTANT_Fieldref; + return temp; +}; + +var constMethodRef = function(){ + var temp = new constRef(); + temp.id = CONSTANT_Methodref; + return temp; +}; + +var constInterfaceMethodRef = function(){ + var temp = new constRef(); + temp.id = CONSTANT_InterfaceMethodref; + return temp; +}; + +var constName_and_Type_info = function(){ + this.name_index = null; + this.descriptor_index = null; + this.id = CONSTANT_NameAndType; + this.read = function(dStream){ + this.name_index = dStream.getU2(); + this.descriptor_index = dStream.getU2(); + }; +} + + +var allocConstEntry = function(tag){ var obj = null; switch ( tag ) { @@ -72,19 +181,27 @@ allocConstEntry = function(tag){ obj = new constDouble(); break; case CONSTANT_Class: + obj = new constClass(); + break; case CONSTANT_String: - obj = new constClass_or_String(); + obj = new constString(); break; case CONSTANT_Fieldref: + obj = new constFieldRef(); + break; case CONSTANT_Methodref: + obj = new constMethodRef(); + break; case CONSTANT_InterfaceMethodref: - obj = new constRef(); + obj = new constInterfaceMethodRef(); break; case CONSTANT_NameAndType: obj = new constName_and_Type_info(); break; default: - System.out.println("allocConstEntry: bad tag value = " + tag); + obj = new constDummy(); + //throw "allocConstEntry: bad tag value = " + tag; break; } // switch + return obj; } \ No newline at end of file diff --git a/index.html b/index.html index 26bb739..9d586b3 100644 --- a/index.html +++ b/index.html @@ -2,6 +2,12 @@