Skip to content

Commit 6d59df2

Browse files
author
NatureFreshMeat
committed
Updated ConstantPool Parser
1 parent 6161693 commit 6d59df2

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

‎src/main/java/ch/ri/jsjvm/utils/ClassToJson.java‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,20 @@
1010
publicclassClassToJson
1111
{
1212

13+
/**
14+
* List of classes to convert
15+
*/
16+
privatestaticfinalClass<?>[] classList =
17+
{
18+
TestClass.class,
19+
Object.class,
20+
String.class
21+
};
22+
1323
publicstaticvoidmain(String[] args) throwsException
1424
{
15-
convert( TestClass.class.getName() );
25+
for (Class<?> c: classList)
26+
convert( c.getName() );
1627
}
1728

1829
privatestaticfinalStringoutputDir = "test/classes/";
@@ -32,7 +43,6 @@ private static void convert(String className) throws IOException
3243
ByteArrayOutputStreamoutput = newByteArrayOutputStream(4096);
3344

3445
byte[] buffer = newbyte[4096];
35-
intoffset = 0;
3646

3747
while(true)
3848
{
@@ -41,8 +51,7 @@ private static void convert(String className) throws IOException
4151
if (count <= 0)
4252
break;
4353

44-
output.write(buffer, offset, count);
45-
offset += count;
54+
output.write(buffer, 0, count);
4655
}
4756

4857
byte[] bytes = output.toByteArray();

‎src/main/javascript/10_ConstantPoolParser.js‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ var ConstantPoolParser = function(classReader)
1616
*/
1717
this.constants=newArray();
1818

19-
this.classReferences=newArray();
20-
varunresolvedClassReferences=newArray();
19+
this.classes=newArray();
20+
varunresolvedclasses=newArray();
2121

22-
this.methodReferences=newArray();
23-
varunresolvedMethodReferences=newArray();
22+
this.methods=newArray();
23+
varunresolvedmethods=newArray();
2424

2525
while(this.constants.length<constant_pool_size-1)
2626
{
@@ -92,7 +92,7 @@ var ConstantPoolParser = function(classReader)
9292
*/
9393
varref=classReader.getU2(pos);
9494
Logger.debug("Class reference: "+ref);
95-
unresolvedClassReferences.push(constantNum);
95+
unresolvedclasses.push(constantNum);
9696
this.constants.push(ref);
9797
pos+=2;
9898
}
@@ -125,7 +125,7 @@ var ConstantPoolParser = function(classReader)
125125
entry.classRef=classRef;
126126
entry.descriptor=descriptor;
127127

128-
unresolvedMethodReferences.push(constantNum);
128+
unresolvedmethods.push(constantNum);
129129
this.constants.push(entry);
130130
pos+=2;
131131
}
@@ -153,29 +153,29 @@ var ConstantPoolParser = function(classReader)
153153
/**
154154
* Resolve class references
155155
*/
156-
for(vari=0;i<unresolvedClassReferences.length;i++)
156+
for(vari=0;i<unresolvedclasses.length;i++)
157157
{
158-
varconstantRef=unresolvedClassReferences[i];
158+
varconstantRef=unresolvedclasses[i];
159159
varref=this.constants[constantRef]
160160
varresolved=this.constants[ref-1];
161161

162-
this.classReferences[constantRef]=resolved;
162+
this.classes[constantRef]=resolved;
163163

164164
Logger.debug("Resolved class ref: "+constantRef+" = "+resolved);
165165
}
166166

167167
/**
168168
* Resolve method references
169169
*/
170-
for(vari=0;i<unresolvedMethodReferences.length;i++)
170+
for(vari=0;i<unresolvedmethods.length;i++)
171171
{
172-
varconstantRef=unresolvedMethodReferences[i];
172+
varconstantRef=unresolvedmethods[i];
173173
varentry=this.constants[constantRef];
174174

175175
entry.classRef=this.constants[entry.classRef];
176176
entry.descriptor=this.constants[entry.descriptor];
177177

178-
this.methodReferences[constantRef]=entry;
178+
this.methods[constantRef]=entry;
179179

180180
Logger.debug("Resolved method ref: "+constantRef+" = "+entry.classRef+" - "+entry.descriptor);
181181
}

0 commit comments

Comments
(0)